From ab9463efac759f807b2a7e467d79ab92f599f7be Mon Sep 17 00:00:00 2001 From: Fabian Jahr Date: Wed, 24 Sep 2025 01:50:06 +0200 Subject: [PATCH] test: Add dumptxoutset fork test --- test/functional/rpc_dumptxoutset.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/functional/rpc_dumptxoutset.py b/test/functional/rpc_dumptxoutset.py index 90f635cef13..0f68aeb988e 100755 --- a/test/functional/rpc_dumptxoutset.py +++ b/test/functional/rpc_dumptxoutset.py @@ -19,6 +19,30 @@ class DumptxoutsetTest(BitcoinTestFramework): self.setup_clean_chain = True self.num_nodes = 1 + def test_dumptxoutset_with_fork(self): + node = self.nodes[0] + tip = node.getbestblockhash() + target_height = node.getblockcount() - 10 + target_hash = node.getblockhash(target_height) + + # Create a fork of two blocks at the target height + invalid_block = node.getblockhash(target_height + 1) + node.invalidateblock(invalid_block) + # Reset mocktime to not regenerate the same blockhash + node.setmocktime(0) + self.generate(node, 2) + + # Move back on to actual main chain + node.reconsiderblock(invalid_block) + self.wait_until(lambda: node.getbestblockhash() == tip) + + # Use dumptxoutset at the forked height + out = node.dumptxoutset("txoutset_fork.dat", "rollback", {"rollback": target_height}) + + # Verify the snapshot was created at the target height and not the fork tip + assert_equal(out['base_height'], target_height) + assert_equal(out['base_hash'], target_hash) + def run_test(self): """Test a trivial usage of the dumptxoutset RPC command.""" node = self.nodes[0] @@ -60,6 +84,9 @@ class DumptxoutsetTest(BitcoinTestFramework): assert_raises_rpc_error( -8, 'Invalid snapshot type "bogus" specified. Please specify "rollback" or "latest"', node.dumptxoutset, 'utxos.dat', "bogus") + self.log.info("Testing dumptxoutset with chain fork at target height") + self.test_dumptxoutset_with_fork() + if __name__ == '__main__': DumptxoutsetTest(__file__).main()