fix: reorg behaviour in mempool tests to match real one

This commit is contained in:
yuvicc committed 2025-11-26 13:44:18 +05:30
1 parent 540ed333f6
commit 70d9e8f0a1
6 files changed
+143 -38

No files matched your search

+20 -4
View File
@@ -15,6 +15,7 @@ from test_framework.util import (
assert_equal,
)
from test_framework.wallet import MiniWallet
from test_framework.blocktools import create_empty_fork
# custom limits for node1
CUSTOM_CLUSTER_LIMIT = 10
@@ -33,6 +34,12 @@ class MempoolPackagesTest(BitcoinTestFramework):
],
]
def trigger_reorg(self, fork_blocks, node):
"""Trigger reorg of the fork blocks."""
for block in fork_blocks:
node.submitblock(block.serialize().hex())
assert_equal(node.getbestblockhash(), fork_blocks[-1].hash_hex)
def run_test(self):
self.wallet = MiniWallet(self.nodes[0])
self.wallet.rescan_utxos()
@@ -227,9 +234,16 @@ class MempoolPackagesTest(BitcoinTestFramework):
# Test reorg handling
# First, the basics:
fork_blocks = create_empty_fork(self.nodes[0])
mempool0 = self.nodes[0].getrawmempool(False)
self.generate(self.nodes[0], 1)
self.trigger_reorg(fork_blocks, self.nodes[0])
# Check if the txs are returned to the mempool
assert_equal(self.nodes[0].getrawmempool(), mempool0)
# Clean-up the mempool
self.generate(self.nodes[0], 1)
self.nodes[1].invalidateblock(self.nodes[0].getbestblockhash())
self.nodes[1].reconsiderblock(self.nodes[0].getbestblockhash())
# Now test the case where node1 has a transaction T in its mempool that
# depends on transactions A and B which are in a mined block, and the
@@ -244,6 +258,9 @@ class MempoolPackagesTest(BitcoinTestFramework):
# Tx1 and Tx7, and add to node1's mempool, then disconnect the
# last block.
# Prep for fork
fork_blocks = create_empty_fork(self.nodes[0])
# Create tx0 with 2 outputs
tx0 = self.wallet.send_self_transfer_multi(from_node=self.nodes[0], num_outputs=2)
@@ -261,8 +278,7 @@ class MempoolPackagesTest(BitcoinTestFramework):
self.sync_mempools()
# Now try to disconnect the tip on each node...
self.nodes[1].invalidateblock(self.nodes[1].getbestblockhash())
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
self.trigger_reorg(fork_blocks, self.nodes[0])
self.sync_blocks()
if __name__ == '__main__':