1010 get_datadir_path ,
1111 rpc_port ,
1212 p2p_port ,
13+ assert_raises_rpc_error ,
14+ assert_equal ,
1315)
1416from decimal import Decimal
1517
@@ -62,9 +64,10 @@ def setup_network(self, split=False):
6264 else :
6365 extra_args .extend ([
6466 "-validatepegin=0" ,
65- "-initialfreecoins=2100000000000000 " ,
67+ "-initialfreecoins=0 " ,
6668 "-anyonecanspendaremine" ,
6769 "-signblockscript=51" , # OP_TRUE
70+ '-con_blocksubsidy=5000000000' ,
6871 ])
6972
7073 self .add_nodes (1 , [extra_args ], chain = [parent_chain ], binary = parent_binary , chain_in_args = [not self .options .parent_bitcoin ])
@@ -73,7 +76,6 @@ def setup_network(self, split=False):
7376
7477 connect_nodes_bi (self .nodes , 0 , 1 )
7578 self .parentgenesisblockhash = self .nodes [0 ].getblockhash (0 )
76- print ('parentgenesisblockhash' , self .parentgenesisblockhash )
7779 if not self .options .parent_bitcoin :
7880 parent_pegged_asset = self .nodes [0 ].getsidechaininfo ()['pegged_asset' ]
7981
@@ -158,24 +160,20 @@ def run_test(self):
158160
159161 addrs = sidechain .getpeginaddress ()
160162 addr = addrs ["mainchain_address" ]
161- print ('addrs' , addrs )
162- print (parent .getaddressinfo (addr ))
163163 txid1 = parent .sendtoaddress (addr , 24 )
164164 # 10+2 confirms required to get into mempool and confirm
165165 parent .generate (1 )
166166 time .sleep (2 )
167167 proof = parent .gettxoutproof ([txid1 ])
168168
169169 raw = parent .getrawtransaction (txid1 )
170- print ('raw' , parent .getrawtransaction (txid1 , True ))
171170
172- print ("Attempting peg-in " )
171+ print ("Attempting peg-ins " )
173172 # First attempt fails the consensus check but gives useful result
174173 try :
175174 pegtxid = sidechain .claimpegin (raw , proof )
176175 raise Exception ("Peg-in should not be mature enough yet, need another block." )
177176 except JSONRPCException as e :
178- print ('RPC ERROR:' , e .error ['message' ])
179177 assert ("Peg-in Bitcoin transaction needs more confirmations to be sent." in e .error ["message" ])
180178
181179 # Second attempt simply doesn't hit mempool bar
@@ -184,14 +182,12 @@ def run_test(self):
184182 pegtxid = sidechain .claimpegin (raw , proof )
185183 raise Exception ("Peg-in should not be mature enough yet, need another block." )
186184 except JSONRPCException as e :
187- print ('RPC ERROR:' , e .error ['message' ])
188185 assert ("Peg-in Bitcoin transaction needs more confirmations to be sent." in e .error ["message" ])
189186
190187 try :
191188 pegtxid = sidechain .createrawpegin (raw , proof , 'AEIOU' )
192189 raise Exception ("Peg-in with non-hex claim_script should fail." )
193190 except JSONRPCException as e :
194- print ('RPC ERROR:' , e .error ['message' ])
195191 assert ("Given claim_script is not hex." in e .error ["message" ])
196192
197193 # Should fail due to non-matching wallet address
@@ -200,7 +196,6 @@ def run_test(self):
200196 pegtxid = sidechain .claimpegin (raw , proof , scriptpubkey )
201197 raise Exception ("Peg-in with non-matching claim_script should fail." )
202198 except JSONRPCException as e :
203- print ('RPC ERROR:' , e .error ['message' ])
204199 assert ("Given claim_script does not match the given Bitcoin transaction." in e .error ["message" ])
205200
206201 # 12 confirms allows in mempool
@@ -219,7 +214,6 @@ def run_test(self):
219214
220215 tx1 = sidechain .gettransaction (pegtxid1 )
221216
222- print ('tx1' , tx1 )
223217 if "confirmations" in tx1 and tx1 ["confirmations" ] == 6 :
224218 print ("Peg-in is confirmed: Success!" )
225219 else :
@@ -233,7 +227,6 @@ def run_test(self):
233227 vsize = decoded ["vsize" ]
234228 fee_output = decoded ["vout" ][1 ]
235229 fallbackfee_pervbyte = Decimal ("0.00001" )/ Decimal ("1000" )
236- print ("fee_output" , fee_output )
237230 assert fee_output ["scriptPubKey" ]["type" ] == "fee"
238231 assert fee_output ["value" ] >= fallbackfee_pervbyte * vsize
239232
@@ -252,7 +245,7 @@ def run_test(self):
252245 # Do multiple claims in mempool
253246 n_claims = 6
254247
255- print ("Flooding mempool with many small claims" )
248+ print ("Flooding mempool with a few claims" )
256249 pegtxs = []
257250 sidechain .generate (101 )
258251
@@ -352,7 +345,6 @@ def run_test(self):
352345
353346 print ("Restarting parent2" )
354347 self .start_node (1 )
355- #parent2 = self.nodes[1]
356348 connect_nodes_bi (self .nodes , 0 , 1 )
357349
358350 # Don't make a block, race condition when pegin-invalid block
@@ -401,10 +393,41 @@ def run_test(self):
401393 # Make sure balance went down
402394 assert (bal_2 + 1 < bal_1 )
403395
396+ # Send rest of coins using subtractfee from output arg
404397 sidechain .sendtomainchain (some_btc_addr , bal_2 , True )
405398
406399 assert (sidechain .getwalletinfo ()["balance" ]['bitcoin' ] == 0 )
407400
401+ print ('Test coinbase peg-in maturity rules' )
402+
403+ # Have bitcoin output go directly into a claim output
404+ pegin_info = sidechain .getpeginaddress ()
405+ mainchain_addr = pegin_info ["mainchain_address" ]
406+ # Watch the address so we can get tx without txindex
407+ parent .importaddress (mainchain_addr )
408+ claim_block = parent .generatetoaddress (50 , mainchain_addr )[0 ]
409+ block_coinbase = parent .getblock (claim_block , 2 )["tx" ][0 ]
410+ claim_txid = block_coinbase ["txid" ]
411+ claim_tx = block_coinbase ["hex" ]
412+ claim_proof = parent .gettxoutproof ([claim_txid ], claim_block )
413+
414+ # Can't claim something even though it has 50 confirms since it's coinbase
415+ assert_raises_rpc_error (- 8 , "Peg-in Bitcoin transaction needs more confirmations to be sent." , sidechain .claimpegin , claim_tx , claim_proof )
416+ # If done via raw API, still doesn't work
417+ coinbase_pegin = sidechain .createrawpegin (claim_tx , claim_proof )
418+ assert_equal (coinbase_pegin ["mature" ], False )
419+ signed_pegin = sidechain .signrawtransactionwithwallet (coinbase_pegin ["hex" ])["hex" ]
420+ assert_raises_rpc_error (- 26 , "bad-pegin-witness, Needs more confirmations." , sidechain .sendrawtransaction , signed_pegin )
421+
422+ # 50 more blocks to allow wallet to make it succeed by relay and consensus
423+ parent .generatetoaddress (50 , parent .getnewaddress ())
424+ # Wallet still doesn't want to for 2 more confirms
425+ assert_equal (sidechain .createrawpegin (claim_tx , claim_proof )["mature" ], False )
426+ # But we can just shoot it off
427+ claim_txid = sidechain .sendrawtransaction (signed_pegin )
428+ sidechain .generatetoaddress (1 , sidechain .getnewaddress ())
429+ assert_equal (sidechain .gettransaction (claim_txid )["confirmations" ], 1 )
430+
408431 print ('Success!' )
409432
410433 # Manually stop sidechains first, then the parent chains.
0 commit comments