@@ -50,6 +50,30 @@ def run_test(self):
50
50
# This will raise an exception since there are missing inputs
51
51
assert_raises_rpc_error (- 25 , "Missing inputs" , self .nodes [2 ].sendrawtransaction , rawtx ['hex' ])
52
52
53
+ #####################################
54
+ # getrawtransaction with block hash #
55
+ #####################################
56
+
57
+ # make a tx by sending then generate 2 blocks; block1 has the tx in it
58
+ tx = self .nodes [2 ].sendtoaddress (self .nodes [1 ].getnewaddress (), 1 )
59
+ block1 , block2 = self .nodes [2 ].generate (2 )
60
+ self .sync_all ()
61
+ # We should be able to get the raw transaction by providing the correct block
62
+ gottx = self .nodes [0 ].getrawtransaction (tx , True , block1 )
63
+ assert_equal (gottx ['txid' ], tx )
64
+ assert_equal (gottx ['in_active_chain' ], True )
65
+ # We should not have the 'in_active_chain' flag when we don't provide a block
66
+ gottx = self .nodes [0 ].getrawtransaction (tx , True )
67
+ assert_equal (gottx ['txid' ], tx )
68
+ assert 'in_active_chain' not in gottx
69
+ # We should not get the tx if we provide an unrelated block
70
+ assert_raises_rpc_error (- 5 , "No such transaction found" , self .nodes [0 ].getrawtransaction , tx , True , block2 )
71
+ # An invalid block hash should raise the correct errors
72
+ assert_raises_rpc_error (- 8 , "parameter 3 must be hexadecimal" , self .nodes [0 ].getrawtransaction , tx , True , True )
73
+ assert_raises_rpc_error (- 8 , "parameter 3 must be hexadecimal" , self .nodes [0 ].getrawtransaction , tx , True , "foobar" )
74
+ assert_raises_rpc_error (- 8 , "parameter 3 must be of length 64" , self .nodes [0 ].getrawtransaction , tx , True , "abcd1234" )
75
+ assert_raises_rpc_error (- 5 , "Block hash not found" , self .nodes [0 ].getrawtransaction , tx , True , "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" )
76
+
53
77
#########################
54
78
# RAW TX MULTISIG TESTS #
55
79
#########################
0 commit comments