|
33 | 33 | - TODO: Not an ancestor or a descendant of the snapshot block and has more work
|
34 | 34 |
|
35 | 35 | """
|
| 36 | +from shutil import rmtree |
| 37 | + |
36 | 38 | from test_framework.test_framework import BitcoinTestFramework
|
37 | 39 | from test_framework.util import (
|
38 | 40 | assert_equal,
|
@@ -107,6 +109,22 @@ def expected_error(log_msg="", rpc_details=""):
|
107 | 109 | f.write(valid_snapshot_contents[(32 + 8 + offset + len(content)):])
|
108 | 110 | expected_error(log_msg=f"[snapshot] bad snapshot content hash: expected 61d9c2b29a2571a5fe285fe2d8554f91f93309666fc9b8223ee96338de25ff53, got {wrong_hash}")
|
109 | 111 |
|
| 112 | + def test_invalid_chainstate_scenarios(self): |
| 113 | + self.log.info("Test different scenarios of invalid snapshot chainstate in datadir") |
| 114 | + |
| 115 | + self.log.info(" - snapshot chainstate refering to a block that is not in the assumeutxo parameters") |
| 116 | + self.stop_node(0) |
| 117 | + chainstate_snapshot_path = self.nodes[0].chain_path / "chainstate_snapshot" |
| 118 | + chainstate_snapshot_path.mkdir() |
| 119 | + with open(chainstate_snapshot_path / "base_blockhash", 'wb') as f: |
| 120 | + f.write(b'z' * 32) |
| 121 | + expected_error = f"Error: A fatal internal error occurred, see debug.log for details" |
| 122 | + self.nodes[0].assert_start_raises_init_error(expected_msg=expected_error) |
| 123 | + |
| 124 | + # resurrect node again |
| 125 | + rmtree(chainstate_snapshot_path) |
| 126 | + self.start_node(0) |
| 127 | + |
110 | 128 | def run_test(self):
|
111 | 129 | """
|
112 | 130 | Bring up two (disconnected) nodes, mine some new blocks on the first,
|
@@ -166,6 +184,7 @@ def run_test(self):
|
166 | 184 | assert_equal(n0.getblockchaininfo()["blocks"], FINAL_HEIGHT)
|
167 | 185 |
|
168 | 186 | self.test_invalid_snapshot_scenarios(dump_output['path'])
|
| 187 | + self.test_invalid_chainstate_scenarios() |
169 | 188 |
|
170 | 189 | self.log.info(f"Loading snapshot into second node from {dump_output['path']}")
|
171 | 190 | loaded = n1.loadtxoutset(dump_output['path'])
|
|
0 commit comments