@@ -38,31 +38,29 @@ def find_spendable_utxo(node, min_value):
3838
3939 raise AssertionError ("Unspent output equal or higher than %s not found" % min_value )
4040
41+ txs_mined = {} # txindex from txid to blockhash
42+
4143class SegWitTest (BitcoinTestFramework ):
4244 def set_test_params (self ):
4345 self .setup_clean_chain = True
4446 self .num_nodes = 3
4547 # This test tests SegWit both pre and post-activation, so use the normal BIP9 activation.
46- # TODO: remove -txindex. Currently required for getrawtransaction call.
4748 self .extra_args = [
4849 [
4950 "-rpcserialversion=0" ,
5051 "-vbparams=segwit:0:999999999999" ,
5152 "-addresstype=legacy" ,
52- "-txindex"
5353 ],
5454 [
5555 "-blockversion=4" ,
5656 "-rpcserialversion=1" ,
5757 "-vbparams=segwit:0:999999999999" ,
5858 "-addresstype=legacy" ,
59- "-txindex"
6059 ],
6160 [
6261 "-blockversion=536870915" ,
6362 "-vbparams=segwit:0:999999999999" ,
6463 "-addresstype=legacy" ,
65- "-txindex"
6664 ],
6765 ]
6866
@@ -157,10 +155,10 @@ def run_test(self):
157155
158156 self .log .info ("Verify previous witness txs skipped for mining can now be mined" )
159157 assert_equal (len (self .nodes [2 ].getrawmempool ()), 4 )
160- block = self .nodes [2 ].generate (1 ) # block 432 (first block with new rules; 432 = 144 * 3)
158+ blockhash = self .nodes [2 ].generate (1 )[ 0 ] # block 432 (first block with new rules; 432 = 144 * 3)
161159 sync_blocks (self .nodes )
162160 assert_equal (len (self .nodes [2 ].getrawmempool ()), 0 )
163- segwit_tx_list = self .nodes [2 ].getblock (block [ 0 ] )["tx" ]
161+ segwit_tx_list = self .nodes [2 ].getblock (blockhash )["tx" ]
164162 assert_equal (len (segwit_tx_list ), 5 )
165163
166164 self .log .info ("Verify default node can't accept txs with missing witness" )
@@ -174,15 +172,16 @@ def run_test(self):
174172 self .fail_accept (self .nodes [0 ], "mandatory-script-verify-flag" , p2sh_ids [NODE_0 ][WIT_V1 ][0 ], False , witness_script (True , self .pubkey [0 ]))
175173
176174 self .log .info ("Verify block and transaction serialization rpcs return differing serializations depending on rpc serialization flag" )
177- assert (self .nodes [2 ].getblock (block [0 ], False ) != self .nodes [0 ].getblock (block [0 ], False ))
178- assert (self .nodes [1 ].getblock (block [0 ], False ) == self .nodes [2 ].getblock (block [0 ], False ))
179- for i in range (len (segwit_tx_list )):
180- tx = FromHex (CTransaction (), self .nodes [2 ].gettransaction (segwit_tx_list [i ])["hex" ])
181- assert (self .nodes [2 ].getrawtransaction (segwit_tx_list [i ]) != self .nodes [0 ].getrawtransaction (segwit_tx_list [i ]))
182- assert (self .nodes [1 ].getrawtransaction (segwit_tx_list [i ], 0 ) == self .nodes [2 ].getrawtransaction (segwit_tx_list [i ]))
183- assert (self .nodes [0 ].getrawtransaction (segwit_tx_list [i ]) != self .nodes [2 ].gettransaction (segwit_tx_list [i ])["hex" ])
184- assert (self .nodes [1 ].getrawtransaction (segwit_tx_list [i ]) == self .nodes [2 ].gettransaction (segwit_tx_list [i ])["hex" ])
185- assert (self .nodes [0 ].getrawtransaction (segwit_tx_list [i ]) == bytes_to_hex_str (tx .serialize_without_witness ()))
175+ assert (self .nodes [2 ].getblock (blockhash , False ) != self .nodes [0 ].getblock (blockhash , False ))
176+ assert (self .nodes [1 ].getblock (blockhash , False ) == self .nodes [2 ].getblock (blockhash , False ))
177+
178+ for tx_id in segwit_tx_list :
179+ tx = FromHex (CTransaction (), self .nodes [2 ].gettransaction (tx_id )["hex" ])
180+ assert (self .nodes [2 ].getrawtransaction (tx_id , False , blockhash ) != self .nodes [0 ].getrawtransaction (tx_id , False , blockhash ))
181+ assert (self .nodes [1 ].getrawtransaction (tx_id , False , blockhash ) == self .nodes [2 ].getrawtransaction (tx_id , False , blockhash ))
182+ assert (self .nodes [0 ].getrawtransaction (tx_id , False , blockhash ) != self .nodes [2 ].gettransaction (tx_id )["hex" ])
183+ assert (self .nodes [1 ].getrawtransaction (tx_id , False , blockhash ) == self .nodes [2 ].gettransaction (tx_id )["hex" ])
184+ assert (self .nodes [0 ].getrawtransaction (tx_id , False , blockhash ) == bytes_to_hex_str (tx .serialize_without_witness ()))
186185
187186 self .log .info ("Verify witness txs without witness data are invalid after the fork" )
188187 self .fail_accept (self .nodes [2 ], 'non-mandatory-script-verify-flag (Witness program hash mismatch) (code 64)' , wit_ids [NODE_2 ][WIT_V0 ][2 ], sign = False )
@@ -538,7 +537,7 @@ def mine_and_test_listunspent(self, script_list, ismine):
538537 tx .rehash ()
539538 signresults = self .nodes [0 ].signrawtransactionwithwallet (bytes_to_hex_str (tx .serialize_without_witness ()))['hex' ]
540539 txid = self .nodes [0 ].sendrawtransaction (signresults , True )
541- self .nodes [0 ].generate (1 )
540+ txs_mined [ txid ] = self .nodes [0 ].generate (1 )[ 0 ]
542541 sync_blocks (self .nodes )
543542 watchcount = 0
544543 spendcount = 0
@@ -581,7 +580,7 @@ def create_and_mine_tx_from_txids(self, txids, success=True):
581580 tx = CTransaction ()
582581 for i in txids :
583582 txtmp = CTransaction ()
584- txraw = self .nodes [0 ].getrawtransaction (i )
583+ txraw = self .nodes [0 ].getrawtransaction (i , 0 , txs_mined [ i ] )
585584 f = BytesIO (hex_str_to_bytes (txraw ))
586585 txtmp .deserialize (f )
587586 for j in range (len (txtmp .vout )):
0 commit comments