qa: Avoid UTXO reuse between test functions
What changed, and why it matters
This is a minor fix inside Bitcoin Core's own test suite. It changes how test UTXOs are consumed so that different test functions don't accidentally reuse the same fake coin. It does not affect the live Bitcoin network, wallets, or node software.
No action needed. This is a test-only quality improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies test/functional/p2p_compactblocks.py. It increases the number of anyone-can-spend UTXOs created by make_utxos() from 10 to 12 and switches several test helpers from reading self.utxos[0] to popping the first entry. This prevents UTXO reuse between test functions and removes now-unnecessary len(self.utxos) assertions. The change is purely in functional tests.
Changed components
test/functional/p2p_compactblocks.pyInspect captured patch +7 / −9
diff --git a/test/functional/p2p_compactblocks.py b/test/functional/p2p_compactblocks.py
index 99f1e5fa..73c50664 100755
--- a/test/functional/p2p_compactblocks.py
+++ b/test/functional/p2p_compactblocks.py
@@ -167,18 +167,19 @@ class CompactBlocksTest(BitcoinTestFramework):
block.solve()
return block
- # Create 10 more anyone-can-spend utxo's for testing.
+ # Create 12 more anyone-can-spend utxo's for testing.
def make_utxos(self):
+ COUNT = 12
block = self.build_block_on_tip(self.nodes[0])
self.segwit_node.send_and_ping(msg_no_witness_block(block))
assert_equal(self.nodes[0].getbestblockhash(), block.hash_hex)
self.generate(self.wallet, COINBASE_MATURITY)
total_value = block.vtx[0].vout[0].nValue
- out_value = total_value // 10
+ out_value = total_value // COUNT
tx = CTransaction()
tx.vin.append(CTxIn(COutPoint(block.vtx[0].txid_int, 0), b''))
- for _ in range(10):
+ for _ in range(COUNT):
tx.vout.append(CTxOut(out_value, CScript([OP_TRUE])))
block2 = self.build_block_on_tip(self.nodes[0])
@@ -187,7 +188,7 @@ class CompactBlocksTest(BitcoinTestFramework):
block2.solve()
self.segwit_node.send_and_ping(msg_no_witness_block(block2))
assert_equal(self.nodes[0].getbestblockhash(), block2.hash_hex)
- self.utxos.extend([[tx.txid_int, i, out_value] for i in range(10)])
+ self.utxos.extend([[tx.txid_int, i, out_value] for i in range(COUNT)])
def announce_cmpct_block(self, node, peer, txn_count=5, solicit=False):
utxo = self.utxos.pop(0)
@@ -600,7 +601,7 @@ class CompactBlocksTest(BitcoinTestFramework):
# Multiple blocktxn responses will cause a node to get disconnected.
def test_multiple_blocktxn_response(self, test_node):
node = self.nodes[0]
- utxo = self.utxos[0]
+ utxo = self.utxos.pop(0)
block = self.build_block_with_transactions(node, utxo, 2)
@@ -781,8 +782,7 @@ class CompactBlocksTest(BitcoinTestFramework):
# but invalid transactions.
def test_invalid_tx_in_compactblock(self, test_node):
node = self.nodes[0]
- assert len(self.utxos)
- utxo = self.utxos[0]
+ utxo = self.utxos.pop(0)
block = self.build_block_with_transactions(node, utxo, 5)
block.hashMerkleRoot = block.calc_merkle_root()
@@ -849,7 +849,6 @@ class CompactBlocksTest(BitcoinTestFramework):
def test_compactblock_reconstruction_stalling_peer(self, stalling_peer, delivery_peer):
node = self.nodes[0]
- assert len(self.utxos)
self.make_peer_hb_to_candidate(node, delivery_peer)
block, cmpct_block = self.announce_cmpct_block(node, stalling_peer)
@@ -923,7 +922,6 @@ class CompactBlocksTest(BitcoinTestFramework):
can only be taken by an outbound node unless prior attempts were done by an outbound
"""
node = self.nodes[0]
- assert len(self.utxos)
for name, peer in [("delivery", delivery_peer), ("inbound", inbound_peer), ("outbound", outbound_peer)]:
self.log.info(f"Setting {name} as high bandwidth peer")
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.