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