|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import os |
3 | 4 | from typing import TYPE_CHECKING |
4 | 5 |
|
| 6 | +import pytest |
5 | 7 | import test_tools as tt |
| 8 | + |
6 | 9 | from hive_local_tools.functional.python.compare_snapshot import compare_snapshots_contents |
7 | 10 |
|
8 | 11 | if TYPE_CHECKING: |
@@ -68,3 +71,64 @@ def clear_state(node: tt.InitNode): |
68 | 71 |
|
69 | 72 | node.wait_for_block_with_number(block_log_length + 7) |
70 | 73 | node.close() |
| 74 | + |
| 75 | +def test_snapshots_has_more_plugins(block_log: Path, block_log_length: int) -> None: |
| 76 | + def clear_state(node: tt.InitNode): |
| 77 | + from os.path import join as join_paths |
| 78 | + from shutil import rmtree |
| 79 | + |
| 80 | + rmtree(join_paths(str(node.directory), "blockchain", "shared_memory.bin"), ignore_errors=True) |
| 81 | + |
| 82 | + node = tt.InitNode() |
| 83 | + # extra plugin with new indexes: `block_log_info` |
| 84 | + node.config.plugin.append("block_log_info") |
| 85 | + node.run(exit_before_synchronization=True, replay_from=block_log) |
| 86 | + node.close() |
| 87 | + |
| 88 | + snap_0 = node.dump_snapshot(close=True) |
| 89 | + |
| 90 | + clear_state(node) |
| 91 | + node.config.plugin.remove("block_log_info") |
| 92 | + node.run(exit_before_synchronization=True, replay_from=block_log) |
| 93 | + node.run(load_snapshot_from=snap_0) |
| 94 | + node.wait_for_block_with_number(block_log_length + 5) |
| 95 | + node.close() |
| 96 | + |
| 97 | + # two files should be created which will show difference between state definitions in shm and current hived |
| 98 | + assert os.path.isfile(node.directory / "current_decoded_types_details.log") |
| 99 | + assert os.path.isfile(node.directory / "loaded_from_shm_decoded_types_details.log") |
| 100 | + |
| 101 | + warning_msg = "Snaphot has more plugins than current hived configuration" |
| 102 | + assert warning_msg in (node.directory / "stderr.txt").read_text() |
| 103 | + |
| 104 | +def test_snapshots_has_less_plugins(block_log: Path, block_log_length: int) -> None: |
| 105 | + def clear_state(node: tt.InitNode): |
| 106 | + from os.path import join as join_paths |
| 107 | + from shutil import rmtree |
| 108 | + |
| 109 | + rmtree(join_paths(str(node.directory), "blockchain", "shared_memory.bin"), ignore_errors=True) |
| 110 | + |
| 111 | + node = tt.InitNode() |
| 112 | + node.run(exit_before_synchronization=True, replay_from=block_log) |
| 113 | + node.close() |
| 114 | + |
| 115 | + snap_0 = node.dump_snapshot(close=True) |
| 116 | + |
| 117 | + clear_state(node) |
| 118 | + # add extra plugin to node - now snapshot has less plugins |
| 119 | + node.config.plugin.append("block_log_info") |
| 120 | + node.run(exit_before_synchronization=True, replay_from=block_log) |
| 121 | + |
| 122 | + with pytest.raises(RuntimeError): |
| 123 | + node.run(load_snapshot_from=snap_0, exit_before_synchronization=True) |
| 124 | + |
| 125 | + # two files should be created which will show difference between state definitions in shm and current hived |
| 126 | + assert os.path.isfile(node.directory / "current_decoded_types_details.log") |
| 127 | + assert os.path.isfile(node.directory / "loaded_from_shm_decoded_types_details.log") |
| 128 | + |
| 129 | + error_msg_1 = "Snapshot misses plugins" |
| 130 | + error_msg_2 = "State objects definitions from shared memory file mismatch current version of app" |
| 131 | + |
| 132 | + log = (node.directory / "stderr.txt").read_text() |
| 133 | + assert error_msg_1 in log |
| 134 | + assert error_msg_2 in log |
0 commit comments