mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
Merge bitcoin/bitcoin#24113: test, bugfix: fix intermittent failure in getrawtransaction_tests
449dffc610
test, bugfix: fix intermittent failure in getrawtransaction_tests (Jon Atack)
Pull request description:
Easiest to review with `colorMoved = dimmed-zebra` and `colorMovedWs = allow-indentation-change`.
Resolves #23991
Top commit has no ACKs.
Tree-SHA512: a50c597857e45c52dae1b6fc5988ea077c09f2b32ffe3605f0c64bd780f5dd2635755cb26c4981233bf925c5ea9f7310163349a549239dc85657558f253ffb7b
This commit is contained in:
commit
2935bd9d67
1 changed files with 23 additions and 16 deletions
|
@ -99,10 +99,17 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
rawTx = self.nodes[1].createrawtransaction([{'txid': txid, 'vout': vout}], {self.nodes[1].getnewaddress(): 9.999})
|
rawTx = self.nodes[1].createrawtransaction([{'txid': txid, 'vout': vout}], {self.nodes[1].getnewaddress(): 9.999})
|
||||||
rawTxSigned = self.nodes[1].signrawtransactionwithwallet(rawTx)
|
rawTxSigned = self.nodes[1].signrawtransactionwithwallet(rawTx)
|
||||||
txId = self.nodes[1].sendrawtransaction(rawTxSigned['hex'])
|
txId = self.nodes[1].sendrawtransaction(rawTxSigned['hex'])
|
||||||
self.generate(self.nodes[0], 1)
|
self.generateblock(self.nodes[0], output=self.nodes[0].getnewaddress(), transactions=[rawTxSigned['hex']])
|
||||||
|
err_msg = (
|
||||||
|
"No such mempool transaction. Use -txindex or provide a block hash to enable"
|
||||||
|
" blockchain transaction queries. Use gettransaction for wallet transactions."
|
||||||
|
)
|
||||||
|
|
||||||
for n in [0, 3]:
|
for n in [0, 3]:
|
||||||
self.log.info(f"Test getrawtransaction {'with' if n == 0 else 'without'} -txindex")
|
self.log.info(f"Test getrawtransaction {'with' if n == 0 else 'without'} -txindex")
|
||||||
|
|
||||||
|
if n == 0:
|
||||||
|
# With -txindex.
|
||||||
# 1. valid parameters - only supply txid
|
# 1. valid parameters - only supply txid
|
||||||
assert_equal(self.nodes[n].getrawtransaction(txId), rawTxSigned['hex'])
|
assert_equal(self.nodes[n].getrawtransaction(txId), rawTxSigned['hex'])
|
||||||
|
|
||||||
|
@ -118,6 +125,10 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
|
|
||||||
# 5. valid parameters - supply txid and True for non-verbose
|
# 5. valid parameters - supply txid and True for non-verbose
|
||||||
assert_equal(self.nodes[n].getrawtransaction(txId, True)["hex"], rawTxSigned['hex'])
|
assert_equal(self.nodes[n].getrawtransaction(txId, True)["hex"], rawTxSigned['hex'])
|
||||||
|
else:
|
||||||
|
# Without -txindex, expect to raise.
|
||||||
|
for verbose in [None, 0, False, 1, True]:
|
||||||
|
assert_raises_rpc_error(-5, err_msg, self.nodes[n].getrawtransaction, txId, verbose)
|
||||||
|
|
||||||
# 6. invalid parameters - supply txid and invalid boolean values (strings) for verbose
|
# 6. invalid parameters - supply txid and invalid boolean values (strings) for verbose
|
||||||
for value in ["True", "False"]:
|
for value in ["True", "False"]:
|
||||||
|
@ -145,10 +156,6 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
assert 'in_active_chain' not in gottx
|
assert 'in_active_chain' not in gottx
|
||||||
else:
|
else:
|
||||||
self.log.info("Test getrawtransaction without -txindex, without blockhash: expect the call to raise")
|
self.log.info("Test getrawtransaction without -txindex, without blockhash: expect the call to raise")
|
||||||
err_msg = (
|
|
||||||
"No such mempool transaction. Use -txindex or provide a block hash to enable"
|
|
||||||
" blockchain transaction queries. Use gettransaction for wallet transactions."
|
|
||||||
)
|
|
||||||
assert_raises_rpc_error(-5, err_msg, self.nodes[n].getrawtransaction, txid=tx, verbose=True)
|
assert_raises_rpc_error(-5, err_msg, self.nodes[n].getrawtransaction, txid=tx, verbose=True)
|
||||||
# We should not get the tx if we provide an unrelated block
|
# We should not get the tx if we provide an unrelated block
|
||||||
assert_raises_rpc_error(-5, "No such transaction found", self.nodes[n].getrawtransaction, txid=tx, blockhash=block2)
|
assert_raises_rpc_error(-5, "No such transaction found", self.nodes[n].getrawtransaction, txid=tx, blockhash=block2)
|
||||||
|
|
Loading…
Reference in a new issue