@@ -50,11 +50,12 @@ def items(self):
50
50
class RawTransactionsTest (BitcoinTestFramework ):
51
51
def set_test_params (self ):
52
52
self .setup_clean_chain = True
53
- self .num_nodes = 3
53
+ self .num_nodes = 4
54
54
self .extra_args = [
55
55
["-txindex" ],
56
56
["-txindex" ],
57
57
["-txindex" ],
58
+ [],
58
59
]
59
60
# whitelist all peers to speed up tx relay / mempool sync
60
61
for args in self .extra_args :
@@ -226,28 +227,40 @@ def run_test(self):
226
227
tx = self .nodes [2 ].sendtoaddress (self .nodes [1 ].getnewaddress (), 1 )
227
228
block1 , block2 = self .nodes [2 ].generate (2 )
228
229
self .sync_all ()
229
- # We should be able to get the raw transaction by providing the correct block
230
- gottx = self .nodes [0 ].getrawtransaction (tx , True , block1 )
231
- assert_equal (gottx ['txid' ], tx )
232
- assert_equal (gottx ['in_active_chain' ], True )
233
- # We should not have the 'in_active_chain' flag when we don't provide a block
234
- gottx = self .nodes [0 ].getrawtransaction (tx , True )
235
- assert_equal (gottx ['txid' ], tx )
236
- assert 'in_active_chain' not in gottx
237
- # We should not get the tx if we provide an unrelated block
238
- assert_raises_rpc_error (- 5 , "No such transaction found" , self .nodes [0 ].getrawtransaction , tx , True , block2 )
239
- # An invalid block hash should raise the correct errors
240
- assert_raises_rpc_error (- 1 , "JSON value is not a string as expected" , self .nodes [0 ].getrawtransaction , tx , True , True )
241
- assert_raises_rpc_error (- 8 , "parameter 3 must be of length 64 (not 6, for 'foobar')" , self .nodes [0 ].getrawtransaction , tx , True , "foobar" )
242
- assert_raises_rpc_error (- 8 , "parameter 3 must be of length 64 (not 8, for 'abcd1234')" , self .nodes [0 ].getrawtransaction , tx , True , "abcd1234" )
243
- assert_raises_rpc_error (- 8 , "parameter 3 must be hexadecimal string (not 'ZZZ0000000000000000000000000000000000000000000000000000000000000')" , self .nodes [0 ].getrawtransaction , tx , True , "ZZZ0000000000000000000000000000000000000000000000000000000000000" )
244
- assert_raises_rpc_error (- 5 , "Block hash not found" , self .nodes [0 ].getrawtransaction , tx , True , "0000000000000000000000000000000000000000000000000000000000000000" )
245
- # Undo the blocks and check in_active_chain
246
- self .nodes [0 ].invalidateblock (block1 )
247
- gottx = self .nodes [0 ].getrawtransaction (txid = tx , verbose = True , blockhash = block1 )
248
- assert_equal (gottx ['in_active_chain' ], False )
249
- self .nodes [0 ].reconsiderblock (block1 )
250
- assert_equal (self .nodes [0 ].getbestblockhash (), block2 )
230
+ for n in [0 , 3 ]:
231
+ self .log .info (f"Test getrawtransaction { 'with' if n == 0 else 'without' } -txindex, with blockhash" )
232
+ # We should be able to get the raw transaction by providing the correct block
233
+ gottx = self .nodes [n ].getrawtransaction (txid = tx , verbose = True , blockhash = block1 )
234
+ assert_equal (gottx ['txid' ], tx )
235
+ assert_equal (gottx ['in_active_chain' ], True )
236
+ if n == 0 :
237
+ self .log .info ("Test getrawtransaction with -txindex, without blockhash: 'in_active_chain' should be absent" )
238
+ gottx = self .nodes [n ].getrawtransaction (txid = tx , verbose = True )
239
+ assert_equal (gottx ['txid' ], tx )
240
+ assert 'in_active_chain' not in gottx
241
+ else :
242
+ self .log .info ("Test getrawtransaction without -txindex, without blockhash: expect the call to raise" )
243
+ err_msg = (
244
+ "No such mempool transaction. Use -txindex or provide a block hash to enable"
245
+ " blockchain transaction queries. Use gettransaction for wallet transactions."
246
+ )
247
+ assert_raises_rpc_error (- 5 , err_msg , self .nodes [n ].getrawtransaction , txid = tx , verbose = True )
248
+ # We should not get the tx if we provide an unrelated block
249
+ assert_raises_rpc_error (- 5 , "No such transaction found" , self .nodes [n ].getrawtransaction , txid = tx , blockhash = block2 )
250
+ # An invalid block hash should raise the correct errors
251
+ assert_raises_rpc_error (- 1 , "JSON value is not a string as expected" , self .nodes [n ].getrawtransaction , txid = tx , blockhash = True )
252
+ assert_raises_rpc_error (- 8 , "parameter 3 must be of length 64 (not 6, for 'foobar')" , self .nodes [n ].getrawtransaction , txid = tx , blockhash = "foobar" )
253
+ assert_raises_rpc_error (- 8 , "parameter 3 must be of length 64 (not 8, for 'abcd1234')" , self .nodes [n ].getrawtransaction , txid = tx , blockhash = "abcd1234" )
254
+ foo = "ZZZ0000000000000000000000000000000000000000000000000000000000000"
255
+ assert_raises_rpc_error (- 8 , f"parameter 3 must be hexadecimal string (not '{ foo } ')" , self .nodes [n ].getrawtransaction , txid = tx , blockhash = foo )
256
+ bar = "0000000000000000000000000000000000000000000000000000000000000000"
257
+ assert_raises_rpc_error (- 5 , "Block hash not found" , self .nodes [n ].getrawtransaction , txid = tx , blockhash = bar )
258
+ # Undo the blocks and verify that "in_active_chain" is false.
259
+ self .nodes [n ].invalidateblock (block1 )
260
+ gottx = self .nodes [n ].getrawtransaction (txid = tx , verbose = True , blockhash = block1 )
261
+ assert_equal (gottx ['in_active_chain' ], False )
262
+ self .nodes [n ].reconsiderblock (block1 )
263
+ assert_equal (self .nodes [n ].getbestblockhash (), block2 )
251
264
252
265
if not self .options .descriptors :
253
266
# The traditional multisig workflow does not work with descriptor wallets so these are legacy only.
0 commit comments