|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright (c) 2023 The Bitcoin Core developers |
| 3 | +# Distributed under the MIT software license, see the accompanying |
| 4 | +# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 5 | +"""Test fastprune mode.""" |
| 6 | +from test_framework.test_framework import BitcoinTestFramework |
| 7 | +from test_framework.util import ( |
| 8 | + assert_equal |
| 9 | +) |
| 10 | +from test_framework.blocktools import ( |
| 11 | + create_block, |
| 12 | + create_coinbase, |
| 13 | + add_witness_commitment |
| 14 | +) |
| 15 | +from test_framework.wallet import MiniWallet |
| 16 | + |
| 17 | + |
| 18 | +class FeatureFastpruneTest(BitcoinTestFramework): |
| 19 | + def set_test_params(self): |
| 20 | + self.num_nodes = 1 |
| 21 | + self.extra_args = [["-fastprune"]] |
| 22 | + |
| 23 | + def run_test(self): |
| 24 | + self.log.info("ensure that large blocks don't crash or freeze in -fastprune") |
| 25 | + wallet = MiniWallet(self.nodes[0]) |
| 26 | + tx = wallet.create_self_transfer()['tx'] |
| 27 | + annex = [0x50] |
| 28 | + for _ in range(0x10000): |
| 29 | + annex.append(0xff) |
| 30 | + tx.wit.vtxinwit[0].scriptWitness.stack.append(bytes(annex)) |
| 31 | + tip = int(self.nodes[0].getbestblockhash(), 16) |
| 32 | + time = self.nodes[0].getblock(self.nodes[0].getbestblockhash())['time'] + 1 |
| 33 | + height = self.nodes[0].getblockcount() + 1 |
| 34 | + block = create_block(hashprev=tip, ntime=time, txlist=[tx], coinbase=create_coinbase(height=height)) |
| 35 | + add_witness_commitment(block) |
| 36 | + block.solve() |
| 37 | + self.nodes[0].submitblock(block.serialize().hex()) |
| 38 | + assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.sha256) |
| 39 | + |
| 40 | + |
| 41 | +if __name__ == '__main__': |
| 42 | + FeatureFastpruneTest().main() |
0 commit comments