feature_unsupported_utxo_db.py raw
1 #!/usr/bin/env python3
2 # Copyright (c) 2022-present 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 that unsupported utxo db causes an init error.
6
7 Previous releases are required by this test, see test/README.md.
8 """
9
10 import shutil
11
12 from test_framework.test_framework import BitcoinTestFramework
13 from test_framework.util import assert_equal
14
15
16 class UnsupportedUtxoDbTest(BitcoinTestFramework):
17 def set_test_params(self):
18 self.setup_clean_chain = True
19 self.num_nodes = 2
20
21 def skip_test_if_missing_module(self):
22 self.skip_if_no_previous_releases()
23
24 def setup_network(self):
25 self.add_nodes(
26 self.num_nodes,
27 versions=[
28 140300, # Last release with previous utxo db format
29 None, # For MiniWallet, without migration code
30 ],
31 )
32
33 def run_test(self):
34 self.log.info("Create previous version (v0.14.3) utxo db")
35 self.start_node(0)
36 block = self.generate(self.nodes[0], 1, sync_fun=self.no_op)[-1]
37 assert_equal(self.nodes[0].getbestblockhash(), block)
38 assert_equal(self.nodes[0].gettxoutsetinfo()["total_amount"], 50)
39 self.stop_nodes()
40
41 self.log.info("Check init error")
42 legacy_utxos_dir = self.nodes[0].chain_path / "chainstate"
43 legacy_blocks_dir = self.nodes[0].blocks_path
44 recent_utxos_dir = self.nodes[1].chain_path / "chainstate"
45 recent_blocks_dir = self.nodes[1].blocks_path
46 shutil.copytree(legacy_utxos_dir, recent_utxos_dir)
47 shutil.copytree(legacy_blocks_dir, recent_blocks_dir)
48 self.nodes[1].assert_start_raises_init_error(
49 expected_msg="Error: Unsupported chainstate database format found. "
50 "Please restart with -reindex-chainstate. "
51 "This will rebuild the chainstate database.",
52 )
53
54 self.log.info("Drop legacy utxo db")
55 self.start_node(1, extra_args=["-reindex-chainstate"])
56 assert_equal(self.nodes[1].getbestblockhash(), block)
57 assert_equal(self.nodes[1].gettxoutsetinfo()["total_amount"], 50)
58
59
60 if __name__ == "__main__":
61 UnsupportedUtxoDbTest(__file__).main()
62