mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-10 10:52:31 -05:00
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
This commit is contained in:
commit
3e50024120
2 changed files with 15 additions and 11 deletions
|
@ -155,7 +155,6 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
|
||||||
|
|
||||||
if (!request.params[2].isNull()) {
|
if (!request.params[2].isNull()) {
|
||||||
uint256 blockhash = ParseHashV(request.params[2], "parameter 3");
|
uint256 blockhash = ParseHashV(request.params[2], "parameter 3");
|
||||||
if (!blockhash.IsNull()) {
|
|
||||||
BlockMap::iterator it = mapBlockIndex.find(blockhash);
|
BlockMap::iterator it = mapBlockIndex.find(blockhash);
|
||||||
if (it == mapBlockIndex.end()) {
|
if (it == mapBlockIndex.end()) {
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block hash not found");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block hash not found");
|
||||||
|
@ -163,7 +162,6 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
|
||||||
blockindex = it->second;
|
blockindex = it->second;
|
||||||
in_active_chain = chainActive.Contains(blockindex);
|
in_active_chain = chainActive.Contains(blockindex);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
CTransactionRef tx;
|
CTransactionRef tx;
|
||||||
uint256 hash_block;
|
uint256 hash_block;
|
||||||
|
|
|
@ -72,7 +72,13 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
assert_raises_rpc_error(-8, "parameter 3 must be hexadecimal", self.nodes[0].getrawtransaction, tx, True, True)
|
assert_raises_rpc_error(-8, "parameter 3 must be hexadecimal", self.nodes[0].getrawtransaction, tx, True, True)
|
||||||
assert_raises_rpc_error(-8, "parameter 3 must be hexadecimal", self.nodes[0].getrawtransaction, tx, True, "foobar")
|
assert_raises_rpc_error(-8, "parameter 3 must be hexadecimal", self.nodes[0].getrawtransaction, tx, True, "foobar")
|
||||||
assert_raises_rpc_error(-8, "parameter 3 must be of length 64", self.nodes[0].getrawtransaction, tx, True, "abcd1234")
|
assert_raises_rpc_error(-8, "parameter 3 must be of length 64", self.nodes[0].getrawtransaction, tx, True, "abcd1234")
|
||||||
assert_raises_rpc_error(-5, "Block hash not found", self.nodes[0].getrawtransaction, tx, True, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
assert_raises_rpc_error(-5, "Block hash not found", self.nodes[0].getrawtransaction, tx, True, "0000000000000000000000000000000000000000000000000000000000000000")
|
||||||
|
# Undo the blocks and check in_active_chain
|
||||||
|
self.nodes[0].invalidateblock(block1)
|
||||||
|
gottx = self.nodes[0].getrawtransaction(txid=tx, verbose=True, blockhash=block1)
|
||||||
|
assert_equal(gottx['in_active_chain'], False)
|
||||||
|
self.nodes[0].reconsiderblock(block1)
|
||||||
|
assert_equal(self.nodes[0].getbestblockhash(), block2)
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
# RAW TX MULTISIG TESTS #
|
# RAW TX MULTISIG TESTS #
|
||||||
|
@ -212,13 +218,13 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
assert_equal(self.nodes[0].getrawtransaction(txHash, True)["hex"], rawTxSigned['hex'])
|
assert_equal(self.nodes[0].getrawtransaction(txHash, True)["hex"], rawTxSigned['hex'])
|
||||||
|
|
||||||
# 6. invalid parameters - supply txid and string "Flase"
|
# 6. invalid parameters - supply txid and string "Flase"
|
||||||
assert_raises_rpc_error(-1,"not a boolean", self.nodes[0].getrawtransaction, txHash, "Flase")
|
assert_raises_rpc_error(-1, "not a boolean", self.nodes[0].getrawtransaction, txHash, "Flase")
|
||||||
|
|
||||||
# 7. invalid parameters - supply txid and empty array
|
# 7. invalid parameters - supply txid and empty array
|
||||||
assert_raises_rpc_error(-1,"not a boolean", self.nodes[0].getrawtransaction, txHash, [])
|
assert_raises_rpc_error(-1, "not a boolean", self.nodes[0].getrawtransaction, txHash, [])
|
||||||
|
|
||||||
# 8. invalid parameters - supply txid and empty dict
|
# 8. invalid parameters - supply txid and empty dict
|
||||||
assert_raises_rpc_error(-1,"not a boolean", self.nodes[0].getrawtransaction, txHash, {})
|
assert_raises_rpc_error(-1, "not a boolean", self.nodes[0].getrawtransaction, txHash, {})
|
||||||
|
|
||||||
inputs = [ {'txid' : "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000", 'vout' : 1, 'sequence' : 1000}]
|
inputs = [ {'txid' : "1d1d4e24ed99057e84c3f80fd8fbec79ed9e1acee37da269356ecea000000000", 'vout' : 1, 'sequence' : 1000}]
|
||||||
outputs = { self.nodes[0].getnewaddress() : 1 }
|
outputs = { self.nodes[0].getnewaddress() : 1 }
|
||||||
|
|
Loading…
Add table
Reference in a new issue