Skip to content

Commit

Permalink
WIP feature_fedpeg with bitcoind
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenroose committed Sep 24, 2018
1 parent 1920d84 commit d6660ac
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 14 deletions.
62 changes: 49 additions & 13 deletions qa/rpc-tests/feature_fedpeg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

from decimal import Decimal
import os
import json
import time

Expand All @@ -10,6 +11,7 @@
connect_nodes_bi,
rpc_auth_pair,
rpc_port,
p2p_port,
start_node,
start_nodes,
stop_node,
Expand Down Expand Up @@ -47,27 +49,57 @@ def __init__(self):
self.setup_clean_chain = True
self.num_nodes = 4

def add_options(self, parser):
parser.add_option("--parent_binpath", dest="parent_binpath", default="",
help="Use a different binary for launching nodes")
parser.add_option("--parent_bitcoin", dest="parent_bitcoin", default=False, action="store_true",
help="Parent nodes are Bitcoin")

def setup_network(self, split=False):

# Parent chain args
self.extra_args = [[
# '-printtoconsole',
'-validatepegin=0',
'-anyonecanspendaremine',
'-initialfreecoins=2100000000000000',
]] * 2

self.nodes = start_nodes(2, self.options.tmpdir, self.extra_args[:2], chain='parent')
chain = None
if self.options.parent_bitcoin:
if self.options.parent_binpath == "":
raise "Can't run with --parent_bitcoin without specifying --parent_binpath"
chain = "regtest"
self.extra_args = [[
"-regtest=1",
"-port="+str(p2p_port(n)),
"-rpcuser="+rpc_auth_pair(n)[0],
"-rpcpassword="+rpc_auth_pair(n)[1],
"-rpcport="+str(rpc_port(n)),
"-testnet=0",
"-txindex=1",
"-addresstype=legacy", # To make sure bitcoind gives back p2pkh no matter version
"-connect=localhost:"+str(p2p_port((n+1)%2)),
"-listen=1",
#"-debug"
] for n in range(2)]
else:
chain = "parent"
self.extra_args = [[
# '-printtoconsole',
'-validatepegin=0',
'-anyonecanspendaremine',
'-initialfreecoins=2100000000000000',
]] * 2

binary = None
if self.options.parent_binpath != "":
binary = [self.options.parent_binpath] * 2
self.nodes = start_nodes(2, self.options.tmpdir, self.extra_args[:2], binary=binary, chain=chain)
connect_nodes_bi(self.nodes, 0, 1)
self.parentgenesisblockhash = self.nodes[0].getblockhash(0)
print('parentgenesisblockhash', self.parentgenesisblockhash)
parent_pegged_asset = self.nodes[0].getsidechaininfo()['pegged_asset']
if not self.options.parent_bitcoin:
parent_pegged_asset = self.nodes[0].getsidechaininfo()['pegged_asset']

# Sidechain args
parent_chain_signblockscript = '51'
for n in range(2):
rpc_u, rpc_p = rpc_auth_pair(n)
self.extra_args.append([
args = [
# '-printtoconsole',
'-parentgenesisblockhash=%s' % self.parentgenesisblockhash,
'-validatepegin=1',
Expand All @@ -80,9 +112,13 @@ def setup_network(self, split=False):
'-mainchainrpcpassword=%s' % rpc_p,
'-parentpubkeyprefix=235',
'-parentscriptprefix=75',
'-con_parent_chain_signblockscript=%s' % parent_chain_signblockscript,
'-con_parent_pegged_asset=%s' % parent_pegged_asset,
])
]
if not self.options.parent_bitcoin:
args.extend([
'-con_parent_chain_signblockscript=%s' % parent_chain_signblockscript,
'-con_parent_pegged_asset=%s' % parent_pegged_asset,
])
self.extra_args.append(args)
self.nodes.append(start_node(n + 2, self.options.tmpdir, self.extra_args[n + 2], chain='sidechain'))

connect_nodes_bi(self.nodes, 2, 3)
Expand Down
4 changes: 3 additions & 1 deletion qa/rpc-tests/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=
datadir = os.path.join(dirname, "node"+str(i))
if binary is None:
binary = os.getenv("ELEMENTSD", "elementsd")
args = [ binary, '-chain='+chain, "-datadir="+datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-mocktime="+str(get_mocktime()) ]
args = [ binary, "-datadir="+datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-mocktime="+str(get_mocktime()) ]
if chain != "regtest": #TODO(stevenroose) remove if unnecessary or when bitcoind has -chain
args.append("-chain="+chain)
if extra_args is not None: args.extend(extra_args)
bitcoind_processes[i] = subprocess.Popen(args)
if os.getenv("PYTHON_DEBUG", ""):
Expand Down

0 comments on commit d6660ac

Please sign in to comment.