feature_reindex_init.py raw
1 #!/usr/bin/env python3
2 # Copyright (c) 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 reindex works on init after a db load failure"""
6
7 from test_framework.test_framework import BitcoinTestFramework
8 from test_framework.util import assert_equal
9 import os
10
11
12 class ReindexInitTest(BitcoinTestFramework):
13 def set_test_params(self):
14 self.num_nodes = 1
15
16 def run_test(self):
17 node = self.nodes[0]
18 self.stop_nodes()
19
20 self.log.info("Removing the block index leads to init error")
21 self.cleanup_folder(node.blocks_path / "index")
22 node.assert_start_raises_init_error(
23 expected_msg=f"Error initializing block database.{os.linesep}"
24 "Please restart with -reindex or -reindex-chainstate to recover.",
25 )
26
27 self.log.info("Allowing the reindex should work fine")
28 self.start_node(0, extra_args=["-test=reindex_after_failure_noninteractive_yes"])
29 assert_equal(node.getblockcount(), 200)
30
31
32 if __name__ == "__main__":
33 ReindexInitTest(__file__).main()
34