You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reindex.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2014-2016 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 running bitcoind with -reindex and -reindex-chainstate options.
  6. - Start a single node and generate 3 blocks.
  7. - Stop the node and restart it with -reindex. Verify that the node has reindexed up to block 3.
  8. - Stop the node and restart it with -reindex-chainstate. Verify that the node has reindexed up to block 3.
  9. """
  10. from test_framework.test_framework import BitcoinTestFramework
  11. from test_framework.util import assert_equal
  12. import time
  13. class ReindexTest(BitcoinTestFramework):
  14. def set_test_params(self):
  15. self.setup_clean_chain = True
  16. self.num_nodes = 1
  17. def reindex(self, justchainstate=False):
  18. self.nodes[0].generate(3)
  19. blockcount = self.nodes[0].getblockcount()
  20. self.stop_nodes()
  21. extra_args = [["-reindex-chainstate" if justchainstate else "-reindex", "-checkblockindex=1"]]
  22. self.start_nodes(extra_args)
  23. while self.nodes[0].getblockcount() < blockcount:
  24. time.sleep(0.1)
  25. assert_equal(self.nodes[0].getblockcount(), blockcount)
  26. self.log.info("Success")
  27. def run_test(self):
  28. self.reindex(False)
  29. self.reindex(True)
  30. self.reindex(False)
  31. self.reindex(True)
  32. if __name__ == '__main__':
  33. ReindexTest().main()