From bb53ce9bdae2f02d7bd95cf5d8ca4ccf5136466a Mon Sep 17 00:00:00 2001 From: Greg Sanders Date: Thu, 21 Nov 2024 22:00:18 +0100 Subject: [PATCH] tests: Add functional test for submitting a previously pruned block This tests the new submitblock behaviour that is introduced in the previous commit: Submitting a previously pruned block should persist the block's data again. --- test/functional/mining_basic.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test/functional/mining_basic.py b/test/functional/mining_basic.py index decee34e99c..d926365ef36 100755 --- a/test/functional/mining_basic.py +++ b/test/functional/mining_basic.py @@ -56,7 +56,12 @@ def assert_template(node, block, expect, rehash=True): class MiningTest(BitcoinTestFramework): def set_test_params(self): - self.num_nodes = 2 + self.num_nodes = 3 + self.extra_args = [ + [], + [], + ["-fastprune", "-prune=1"] + ] self.setup_clean_chain = True self.supports_cli = False @@ -168,6 +173,21 @@ class MiningTest(BitcoinTestFramework): bad_block.solve() node.submitheader(hexdata=CBlockHeader(bad_block).serialize().hex()) + def test_pruning(self): + self.log.info("Test that submitblock stores previously pruned block") + prune_node = self.nodes[2] + self.generate(prune_node, 400, sync_fun=self.no_op) + pruned_block = prune_node.getblock(prune_node.getblockhash(2), verbosity=0) + pruned_height = prune_node.pruneblockchain(400) + assert_greater_than_or_equal(pruned_height, 2) + pruned_blockhash = prune_node.getblockhash(2) + + assert_raises_rpc_error(-1, 'Block not available (pruned data)', prune_node.getblock, pruned_blockhash) + + result = prune_node.submitblock(pruned_block) + assert_equal(result, "inconclusive") + assert_equal(prune_node.getblock(pruned_blockhash, verbosity=0), pruned_block) + def run_test(self): node = self.nodes[0] self.wallet = MiniWallet(node) @@ -386,6 +406,7 @@ class MiningTest(BitcoinTestFramework): self.test_blockmintxfee_parameter() self.test_timewarp() + self.test_pruning() if __name__ == '__main__':