Files
bitcoin/test/functional/feature_reindex_init.py
David Gumberg 0d1301b47a test: functional: drop rmtree usage and add lint check
`shutil.rmtree` is dangerous because it recursively deletes. There are
not likely to be any issues with it's current uses, but it is possible
that some of the assumptions being made now won't always be true, e.g.
about what some of the variables being passed to `rmtree` represent.

For some remaining uses of rmtree that can't be avoided for now, use
`cleanup_dir` which asserts that the recursively deleted folder is a
child of the the `tmpdir` of the test run. Otherwise,
`tempfile.TemporaryDirectory` should be used which does it's own
deleting on being garbage collected, or old fashioned unlinking and
rmdir in the case of directories with known contents.
2026-03-24 16:06:35 -07:00

34 lines
1.1 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright (c) The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test reindex works on init after a db load failure"""
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
import os
class ReindexInitTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
def run_test(self):
node = self.nodes[0]
self.stop_nodes()
self.log.info("Removing the block index leads to init error")
self.cleanup_folder(node.blocks_path / "index")
node.assert_start_raises_init_error(
expected_msg=f"Error initializing block database.{os.linesep}"
"Please restart with -reindex or -reindex-chainstate to recover.",
)
self.log.info("Allowing the reindex should work fine")
self.start_node(0, extra_args=["-test=reindex_after_failure_noninteractive_yes"])
assert_equal(node.getblockcount(), 200)
if __name__ == "__main__":
ReindexInitTest(__file__).main()