Skip to content

Commit 3e50024

Browse files
committed
Merge #11838: qa: Add getrawtransaction in_active_chain=False test
fa4c16d qa: Add getrawtransaction in_active_chain=False test (MarcoFalke) Pull request description: #10275 accidentally forgot to add a test for `in_active_chain==False`. This adds a test and also removes the special casing of `blockhash.IsNull()`, which makes no sense imo. Tree-SHA512: 6c51295820b3dcd53b0b48020ab2b8c8f5864cd5061ddab2b35d35d643eb3e60ef95ff20c06c985a2e47f7080e82f27f3e00ee61c85dce627776d5ea6febee8f
2 parents 7630a1f + fa4c16d commit 3e50024

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,12 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
155155

156156
if (!request.params[2].isNull()) {
157157
uint256 blockhash = ParseHashV(request.params[2], "parameter 3");
158-
if (!blockhash.IsNull()) {
159-
BlockMap::iterator it = mapBlockIndex.find(blockhash);
160-
if (it == mapBlockIndex.end()) {
161-
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block hash not found");
162-
}
163-
blockindex = it->second;
164-
in_active_chain = chainActive.Contains(blockindex);
158+
BlockMap::iterator it = mapBlockIndex.find(blockhash);
159+
if (it == mapBlockIndex.end()) {
160+
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block hash not found");
165161
}
162+
blockindex = it->second;
163+
in_active_chain = chainActive.Contains(blockindex);
166164
}
167165

168166
CTransactionRef tx;

test/functional/rawtransactions.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ def run_test(self):
7272
assert_raises_rpc_error(-8, "parameter 3 must be hexadecimal", self.nodes[0].getrawtransaction, tx, True, True)
7373
assert_raises_rpc_error(-8, "parameter 3 must be hexadecimal", self.nodes[0].getrawtransaction, tx, True, "foobar")
7474
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")
75+
assert_raises_rpc_error(-5, "Block hash not found", self.nodes[0].getrawtransaction, tx, True, "0000000000000000000000000000000000000000000000000000000000000000")
76+
# Undo the blocks and check in_active_chain
77+
self.nodes[0].invalidateblock(block1)
78+
gottx = self.nodes[0].getrawtransaction(txid=tx, verbose=True, blockhash=block1)
79+
assert_equal(gottx['in_active_chain'], False)
80+
self.nodes[0].reconsiderblock(block1)
81+
assert_equal(self.nodes[0].getbestblockhash(), block2)
7682

7783
#########################
7884
# RAW TX MULTISIG TESTS #
@@ -212,13 +218,13 @@ def run_test(self):
212218
assert_equal(self.nodes[0].getrawtransaction(txHash, True)["hex"], rawTxSigned['hex'])
213219

214220
# 6. invalid parameters - supply txid and string "Flase"
215-
assert_raises_rpc_error(-1,"not a boolean", self.nodes[0].getrawtransaction, txHash, "Flase")
221+
assert_raises_rpc_error(-1, "not a boolean", self.nodes[0].getrawtransaction, txHash, "Flase")
216222

217223
# 7. invalid parameters - supply txid and empty array
218-
assert_raises_rpc_error(-1,"not a boolean", self.nodes[0].getrawtransaction, txHash, [])
224+
assert_raises_rpc_error(-1, "not a boolean", self.nodes[0].getrawtransaction, txHash, [])
219225

220226
# 8. invalid parameters - supply txid and empty dict
221-
assert_raises_rpc_error(-1,"not a boolean", self.nodes[0].getrawtransaction, txHash, {})
227+
assert_raises_rpc_error(-1, "not a boolean", self.nodes[0].getrawtransaction, txHash, {})
222228

223229
inputs = [ {'txid' : "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000", 'vout' : 1, 'sequence' : 1000}]
224230
outputs = { self.nodes[0].getnewaddress() : 1 }

0 commit comments

Comments
 (0)