Skip to content

Commit 434526a

Browse files
committed
[test] Add tests for getrawtransaction with block hash.
1 parent b167951 commit 434526a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/functional/rawtransactions.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,30 @@ def run_test(self):
5050
# This will raise an exception since there are missing inputs
5151
assert_raises_rpc_error(-25, "Missing inputs", self.nodes[2].sendrawtransaction, rawtx['hex'])
5252

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+
5377
#########################
5478
# RAW TX MULTISIG TESTS #
5579
#########################

0 commit comments

Comments
 (0)