|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright (c) 2019 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 bitcoind aborts if can't disconnect a block. |
| 6 | +
|
| 7 | +- Start a single node and generate 3 blocks. |
| 8 | +- Delete the undo data. |
| 9 | +- Mine a fork that requires disconnecting the tip. |
| 10 | +- Verify that bitcoind AbortNode's. |
| 11 | +""" |
| 12 | + |
| 13 | +from test_framework.test_framework import BitcoinTestFramework |
| 14 | +from test_framework.util import wait_until, get_datadir_path, connect_nodes |
| 15 | +import os |
| 16 | + |
| 17 | +class AbortNodeTest(BitcoinTestFramework): |
| 18 | + |
| 19 | + def set_test_params(self): |
| 20 | + self.setup_clean_chain = True |
| 21 | + self.num_nodes = 2 |
| 22 | + |
| 23 | + def setup_network(self): |
| 24 | + self.setup_nodes() |
| 25 | + # We'll connect the nodes later |
| 26 | + |
| 27 | + def run_test(self): |
| 28 | + self.nodes[0].generate(3) |
| 29 | + datadir = get_datadir_path(self.options.tmpdir, 0) |
| 30 | + |
| 31 | + # Deleting the undo file will result in reorg failure |
| 32 | + os.unlink(os.path.join(datadir, 'regtest', 'blocks', 'rev00000.dat')) |
| 33 | + |
| 34 | + # Connecting to a node with a more work chain will trigger a reorg |
| 35 | + # attempt. |
| 36 | + self.nodes[1].generate(3) |
| 37 | + with self.nodes[0].assert_debug_log(["Failed to disconnect block"]): |
| 38 | + connect_nodes(self.nodes[0], 1) |
| 39 | + self.nodes[1].generate(1) |
| 40 | + |
| 41 | + # Check that node0 aborted |
| 42 | + self.log.info("Waiting for crash") |
| 43 | + wait_until(lambda: self.nodes[0].is_node_stopped(), timeout=60) |
| 44 | + self.log.info("Node crashed - now verifying restart fails") |
| 45 | + self.nodes[0].assert_start_raises_init_error() |
| 46 | + |
| 47 | +if __name__ == '__main__': |
| 48 | + AbortNodeTest().main() |
0 commit comments