@@ -38,31 +38,29 @@ def find_spendable_utxo(node, min_value):
38
38
39
39
raise AssertionError ("Unspent output equal or higher than %s not found" % min_value )
40
40
41
+ txs_mined = {} # txindex from txid to blockhash
42
+
41
43
class SegWitTest (BitcoinTestFramework ):
42
44
def set_test_params (self ):
43
45
self .setup_clean_chain = True
44
46
self .num_nodes = 3
45
47
# This test tests SegWit both pre and post-activation, so use the normal BIP9 activation.
46
- # TODO: remove -txindex. Currently required for getrawtransaction call.
47
48
self .extra_args = [
48
49
[
49
50
"-rpcserialversion=0" ,
50
51
"-vbparams=segwit:0:999999999999" ,
51
52
"-addresstype=legacy" ,
52
- "-txindex"
53
53
],
54
54
[
55
55
"-blockversion=4" ,
56
56
"-rpcserialversion=1" ,
57
57
"-vbparams=segwit:0:999999999999" ,
58
58
"-addresstype=legacy" ,
59
- "-txindex"
60
59
],
61
60
[
62
61
"-blockversion=536870915" ,
63
62
"-vbparams=segwit:0:999999999999" ,
64
63
"-addresstype=legacy" ,
65
- "-txindex"
66
64
],
67
65
]
68
66
@@ -157,10 +155,10 @@ def run_test(self):
157
155
158
156
self .log .info ("Verify previous witness txs skipped for mining can now be mined" )
159
157
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)
161
159
sync_blocks (self .nodes )
162
160
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" ]
164
162
assert_equal (len (segwit_tx_list ), 5 )
165
163
166
164
self .log .info ("Verify default node can't accept txs with missing witness" )
@@ -174,15 +172,16 @@ def run_test(self):
174
172
self .fail_accept (self .nodes [0 ], "mandatory-script-verify-flag" , p2sh_ids [NODE_0 ][WIT_V1 ][0 ], False , witness_script (True , self .pubkey [0 ]))
175
173
176
174
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 ()))
186
185
187
186
self .log .info ("Verify witness txs without witness data are invalid after the fork" )
188
187
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):
538
537
tx .rehash ()
539
538
signresults = self .nodes [0 ].signrawtransactionwithwallet (bytes_to_hex_str (tx .serialize_without_witness ()))['hex' ]
540
539
txid = self .nodes [0 ].sendrawtransaction (signresults , True )
541
- self .nodes [0 ].generate (1 )
540
+ txs_mined [ txid ] = self .nodes [0 ].generate (1 )[ 0 ]
542
541
sync_blocks (self .nodes )
543
542
watchcount = 0
544
543
spendcount = 0
@@ -581,7 +580,7 @@ def create_and_mine_tx_from_txids(self, txids, success=True):
581
580
tx = CTransaction ()
582
581
for i in txids :
583
582
txtmp = CTransaction ()
584
- txraw = self .nodes [0 ].getrawtransaction (i )
583
+ txraw = self .nodes [0 ].getrawtransaction (i , 0 , txs_mined [ i ] )
585
584
f = BytesIO (hex_str_to_bytes (txraw ))
586
585
txtmp .deserialize (f )
587
586
for j in range (len (txtmp .vout )):
0 commit comments