Skip to content

Commit 2935bd9

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#24113: test, bugfix: fix intermittent failure in getrawtransaction_tests
449dffc 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
2 parents dd405ad + 449dffc commit 2935bd9

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

test/functional/rpc_rawtransaction.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -99,25 +99,36 @@ def getrawtransaction_tests(self):
9999
rawTx = self.nodes[1].createrawtransaction([{'txid': txid, 'vout': vout}], {self.nodes[1].getnewaddress(): 9.999})
100100
rawTxSigned = self.nodes[1].signrawtransactionwithwallet(rawTx)
101101
txId = self.nodes[1].sendrawtransaction(rawTxSigned['hex'])
102-
self.generate(self.nodes[0], 1)
102+
self.generateblock(self.nodes[0], output=self.nodes[0].getnewaddress(), transactions=[rawTxSigned['hex']])
103+
err_msg = (
104+
"No such mempool transaction. Use -txindex or provide a block hash to enable"
105+
" blockchain transaction queries. Use gettransaction for wallet transactions."
106+
)
103107

104108
for n in [0, 3]:
105109
self.log.info(f"Test getrawtransaction {'with' if n == 0 else 'without'} -txindex")
106-
# 1. valid parameters - only supply txid
107-
assert_equal(self.nodes[n].getrawtransaction(txId), rawTxSigned['hex'])
108110

109-
# 2. valid parameters - supply txid and 0 for non-verbose
110-
assert_equal(self.nodes[n].getrawtransaction(txId, 0), rawTxSigned['hex'])
111+
if n == 0:
112+
# With -txindex.
113+
# 1. valid parameters - only supply txid
114+
assert_equal(self.nodes[n].getrawtransaction(txId), rawTxSigned['hex'])
111115

112-
# 3. valid parameters - supply txid and False for non-verbose
113-
assert_equal(self.nodes[n].getrawtransaction(txId, False), rawTxSigned['hex'])
116+
# 2. valid parameters - supply txid and 0 for non-verbose
117+
assert_equal(self.nodes[n].getrawtransaction(txId, 0), rawTxSigned['hex'])
114118

115-
# 4. valid parameters - supply txid and 1 for verbose.
116-
# We only check the "hex" field of the output so we don't need to update this test every time the output format changes.
117-
assert_equal(self.nodes[n].getrawtransaction(txId, 1)["hex"], rawTxSigned['hex'])
119+
# 3. valid parameters - supply txid and False for non-verbose
120+
assert_equal(self.nodes[n].getrawtransaction(txId, False), rawTxSigned['hex'])
118121

119-
# 5. valid parameters - supply txid and True for non-verbose
120-
assert_equal(self.nodes[n].getrawtransaction(txId, True)["hex"], rawTxSigned['hex'])
122+
# 4. valid parameters - supply txid and 1 for verbose.
123+
# We only check the "hex" field of the output so we don't need to update this test every time the output format changes.
124+
assert_equal(self.nodes[n].getrawtransaction(txId, 1)["hex"], rawTxSigned['hex'])
125+
126+
# 5. valid parameters - supply txid and True for non-verbose
127+
assert_equal(self.nodes[n].getrawtransaction(txId, True)["hex"], rawTxSigned['hex'])
128+
else:
129+
# Without -txindex, expect to raise.
130+
for verbose in [None, 0, False, 1, True]:
131+
assert_raises_rpc_error(-5, err_msg, self.nodes[n].getrawtransaction, txId, verbose)
121132

122133
# 6. invalid parameters - supply txid and invalid boolean values (strings) for verbose
123134
for value in ["True", "False"]:
@@ -145,10 +156,6 @@ def getrawtransaction_tests(self):
145156
assert 'in_active_chain' not in gottx
146157
else:
147158
self.log.info("Test getrawtransaction without -txindex, without blockhash: expect the call to raise")
148-
err_msg = (
149-
"No such mempool transaction. Use -txindex or provide a block hash to enable"
150-
" blockchain transaction queries. Use gettransaction for wallet transactions."
151-
)
152159
assert_raises_rpc_error(-5, err_msg, self.nodes[n].getrawtransaction, txid=tx, verbose=True)
153160
# We should not get the tx if we provide an unrelated block
154161
assert_raises_rpc_error(-5, "No such transaction found", self.nodes[n].getrawtransaction, txid=tx, blockhash=block2)

0 commit comments

Comments
 (0)