qa: Avoid UTXO reuse between test functions

This commit is contained in:
Hodlinator
2026-02-26 14:07:12 +01:00
committed by David Gumberg
parent 9c5dd2926a
commit 55e3a57f22

View File

@@ -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")