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.
This commit is contained in:
Greg Sanders 2024-11-21 22:00:18 +01:00 committed by TheCharlatan
parent 1f7fc73825
commit bb53ce9bda
No known key found for this signature in database
GPG key ID: 9B79B45691DB4173

View file

@ -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__':