Skip to content

Commit 98ff65a

Browse files
committed
Merge #415: qa: Support using bitcoind in fedpeg test
9545ca3 qa: Disable -printtoconsole in feature_fedpeg (Steven Roose) 1451e86 qa: Remove pegging.py in favor of feature_fedpeg.py (Steven Roose) 498877e QA: Fix feature_fedpeg.py to work with 0.17.0 (Jorge Timón) a7736f8 QA: Add test to get 'Given claim_script is not hex' error (Jorge Timón) 35364b6 rpc: reject non-hex strings for claim_script (Gregory Sanders) 07c617b qa: Support using bitcoind in fedpeg test (Steven Roose) 729969d QA: Special case for regtest, expected to be used for binaries that lack -chain (Jorge Timón)
2 parents 1920d84 + 9545ca3 commit 98ff65a

File tree

4 files changed

+77
-487
lines changed

4 files changed

+77
-487
lines changed

qa/rpc-tests/feature_fedpeg.py

Lines changed: 70 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
from decimal import Decimal
4+
import os
45
import json
56
import time
67

@@ -10,8 +11,8 @@
1011
connect_nodes_bi,
1112
rpc_auth_pair,
1213
rpc_port,
14+
p2p_port,
1315
start_node,
14-
start_nodes,
1516
stop_node,
1617
)
1718

@@ -47,42 +48,75 @@ def __init__(self):
4748
self.setup_clean_chain = True
4849
self.num_nodes = 4
4950

51+
def add_options(self, parser):
52+
parser.add_option("--parent_binpath", dest="parent_binpath", default="",
53+
help="Use a different binary for launching nodes")
54+
parser.add_option("--parent_bitcoin", dest="parent_bitcoin", default=False, action="store_true",
55+
help="Parent nodes are Bitcoin")
56+
5057
def setup_network(self, split=False):
58+
if self.options.parent_bitcoin and self.options.parent_binpath == "":
59+
raise Exception("Can't run with --parent_bitcoin without specifying --parent_binpath")
5160

61+
self.nodes = []
62+
self.extra_args = []
5263
# Parent chain args
53-
self.extra_args = [[
54-
# '-printtoconsole',
55-
'-validatepegin=0',
56-
'-anyonecanspendaremine',
57-
'-initialfreecoins=2100000000000000',
58-
]] * 2
59-
60-
self.nodes = start_nodes(2, self.options.tmpdir, self.extra_args[:2], chain='parent')
64+
for n in range(2):
65+
if self.options.parent_bitcoin:
66+
self.parent_chain = 'regtest'
67+
rpc_u, rpc_p = rpc_auth_pair(n)
68+
self.extra_args.append([
69+
"-printtoconsole=0",
70+
"-port="+str(p2p_port(n)),
71+
"-rpcuser="+rpc_u,
72+
"-rpcpassword="+rpc_p,
73+
"-rpcport="+str(rpc_port(n)),
74+
"-addresstype=legacy", # To make sure bitcoind gives back p2pkh no matter version
75+
"-deprecatedrpc=validateaddress",
76+
])
77+
else:
78+
self.parent_chain = 'parent'
79+
self.extra_args.append([
80+
"-printtoconsole=0",
81+
'-validatepegin=0',
82+
'-anyonecanspendaremine',
83+
'-initialfreecoins=2100000000000000',
84+
])
85+
self.binary = self.options.parent_binpath if self.options.parent_binpath != "" else None
86+
self.nodes.append(start_node(n, self.options.tmpdir, self.extra_args[n], binary=self.binary, chain=self.parent_chain))
87+
6188
connect_nodes_bi(self.nodes, 0, 1)
6289
self.parentgenesisblockhash = self.nodes[0].getblockhash(0)
6390
print('parentgenesisblockhash', self.parentgenesisblockhash)
64-
parent_pegged_asset = self.nodes[0].getsidechaininfo()['pegged_asset']
91+
if not self.options.parent_bitcoin:
92+
parent_pegged_asset = self.nodes[0].getsidechaininfo()['pegged_asset']
6593

6694
# Sidechain args
95+
self.fedpeg_script = "512103dff4923d778550cc13ce0d887d737553b4b58f4e8e886507fc39f5e447b2186451ae"
6796
parent_chain_signblockscript = '51'
6897
for n in range(2):
6998
rpc_u, rpc_p = rpc_auth_pair(n)
70-
self.extra_args.append([
71-
# '-printtoconsole',
99+
args = [
100+
"-printtoconsole=0",
72101
'-parentgenesisblockhash=%s' % self.parentgenesisblockhash,
73102
'-validatepegin=1',
103+
'-fedpegscript=%s' % self.fedpeg_script,
74104
'-anyonecanspendaremine=0',
75105
'-initialfreecoins=0',
76106
'-peginconfirmationdepth=10',
77107
'-mainchainrpchost=127.0.0.1',
78108
'-mainchainrpcport=%s' % rpc_port(n),
79109
'-mainchainrpcuser=%s' % rpc_u,
80110
'-mainchainrpcpassword=%s' % rpc_p,
81-
'-parentpubkeyprefix=235',
82-
'-parentscriptprefix=75',
83-
'-con_parent_chain_signblockscript=%s' % parent_chain_signblockscript,
84-
'-con_parent_pegged_asset=%s' % parent_pegged_asset,
85-
])
111+
]
112+
if not self.options.parent_bitcoin:
113+
args.extend([
114+
'-parentpubkeyprefix=235',
115+
'-parentscriptprefix=75',
116+
'-con_parent_chain_signblockscript=%s' % parent_chain_signblockscript,
117+
'-con_parent_pegged_asset=%s' % parent_pegged_asset,
118+
])
119+
self.extra_args.append(args)
86120
self.nodes.append(start_node(n + 2, self.options.tmpdir, self.extra_args[n + 2], chain='sidechain'))
87121

88122
connect_nodes_bi(self.nodes, 2, 3)
@@ -116,10 +150,10 @@ def run_test(self):
116150
sidechain.generate(101)
117151

118152
addrs = sidechain.getpeginaddress()
119-
addr = parent.validateaddress(addrs["mainchain_address"])
153+
addr = addrs["mainchain_address"]
120154
print('addrs', addrs)
121-
print('addr', addr)
122-
txid1 = parent.sendtoaddress(addrs["mainchain_address"], 24)
155+
print(parent.validateaddress(addr))
156+
txid1 = parent.sendtoaddress(addr, 24)
123157
# 10+2 confirms required to get into mempool and confirm
124158
parent.generate(1)
125159
time.sleep(2)
@@ -134,7 +168,7 @@ def run_test(self):
134168
pegtxid = sidechain.claimpegin(raw, proof)
135169
raise Exception("Peg-in should not be mature enough yet, need another block.")
136170
except JSONRPCException as e:
137-
print('ERROR:', e.error)
171+
print('RPC ERROR:', e.error['message'])
138172
assert("Peg-in Bitcoin transaction needs more confirmations to be sent." in e.error["message"])
139173

140174
# Second attempt simply doesn't hit mempool bar
@@ -143,23 +177,24 @@ def run_test(self):
143177
pegtxid = sidechain.claimpegin(raw, proof)
144178
raise Exception("Peg-in should not be mature enough yet, need another block.")
145179
except JSONRPCException as e:
180+
print('RPC ERROR:', e.error['message'])
146181
assert("Peg-in Bitcoin transaction needs more confirmations to be sent." in e.error["message"])
147182

148-
# Should fail due to non-witness
149183
try:
150-
pegtxid = sidechain.claimpegin(raw, proof, get_new_unconfidential_address(parent))
151-
raise Exception("Peg-in with non-matching claim_script should fail.")
184+
pegtxid = sidechain.createrawpegin(raw, proof, 'AEIOU')
185+
raise Exception("Peg-in with non-hex claim_script should fail.")
152186
except JSONRPCException as e:
153-
print(e.error["message"])
154-
assert("Given or recovered script is not a witness program." in e.error["message"])
187+
print('RPC ERROR:', e.error['message'])
188+
assert("Given claim_script is not hex." in e.error["message"])
155189

156-
# # Should fail due to non-matching wallet address
157-
# try:
158-
# pegtxid = sidechain.claimpegin(raw, proof, get_new_unconfidential_address(sidechain))
159-
# raise Exception("Peg-in with non-matching claim_script should fail.")
160-
# except JSONRPCException as e:
161-
# print(e.error["message"])
162-
# assert("Given claim_script does not match the given Bitcoin transaction." in e.error["message"])
190+
# Should fail due to non-matching wallet address
191+
try:
192+
scriptpubkey = sidechain.validateaddress(get_new_unconfidential_address(sidechain))["scriptPubKey"]
193+
pegtxid = sidechain.claimpegin(raw, proof, scriptpubkey)
194+
raise Exception("Peg-in with non-matching claim_script should fail.")
195+
except JSONRPCException as e:
196+
print('RPC ERROR:', e.error['message'])
197+
assert("Given claim_script does not match the given Bitcoin transaction." in e.error["message"])
163198

164199
# 12 confirms allows in mempool
165200
parent.generate(1)
@@ -269,7 +304,7 @@ def run_test(self):
269304

270305
print ("Now test failure to validate peg-ins based on intermittant bitcoind rpc failure")
271306
stop_node(self.nodes[1], 1)
272-
txid = parent.sendtoaddress(addrs["mainchain_address"], 1)
307+
txid = parent.sendtoaddress(addr, 1)
273308
parent.generate(12)
274309
proof = parent.gettxoutproof([txid])
275310
raw = parent.getrawtransaction(txid)
@@ -281,7 +316,7 @@ def run_test(self):
281316
assert(sidechain.getblockcount() != sidechain2.getblockcount())
282317

283318
print("Restarting parent2")
284-
self.nodes[1] = start_node(1, self.options.tmpdir, self.extra_args[1], chain='parent')
319+
self.nodes[1] = start_node(1, self.options.tmpdir, self.extra_args[1], binary=self.binary, chain=self.parent_chain)
285320
parent2 = self.nodes[1]
286321
connect_nodes_bi(self.nodes, 0, 1)
287322
time.sleep(5)

0 commit comments

Comments
 (0)