|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright (c) 2023 RBB S.r.l |
| 3 | + |
| 4 | +# SPDX-License-Identifier: MIT |
| 5 | +# Licensed under the MIT License; |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# https://github.com/mintlayer/mintlayer-core/blob/master/LICENSE |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +from scalecodec.base import RuntimeConfiguration |
| 18 | +from test_framework.test_framework import BitcoinTestFramework |
| 19 | +from test_framework.util import ( |
| 20 | + assert_equal, |
| 21 | +) |
| 22 | + |
| 23 | +block_input_data_obj = RuntimeConfiguration().create_scale_object('GenerateBlockInputData') |
| 24 | + |
| 25 | + |
| 26 | +class RestartWithDifferentMagicBytes(BitcoinTestFramework): |
| 27 | + def set_test_params(self): |
| 28 | + self.setup_clean_chain = True |
| 29 | + self.num_nodes = 1 |
| 30 | + self.extra_args = [[ |
| 31 | + "--blockprod-min-peers-to-produce-blocks=0" |
| 32 | + ]] |
| 33 | + |
| 34 | + def run_test(self): |
| 35 | + # generate and process block to update chainstate db |
| 36 | + block_input_data = block_input_data_obj.encode({"PoW": {"reward_destination": "AnyoneCanSpend"}} |
| 37 | + ).to_hex()[2:] |
| 38 | + |
| 39 | + block = self.nodes[0].blockprod_generate_block(block_input_data, []) |
| 40 | + self.nodes[0].chainstate_submit_block(block) |
| 41 | + |
| 42 | + tip_height = self.nodes[0].chainstate_best_block_height() |
| 43 | + assert_equal(1, tip_height) |
| 44 | + |
| 45 | + # restart the node and check that the db hasn't changed |
| 46 | + self.restart_node(0) |
| 47 | + tip_height = self.nodes[0].chainstate_best_block_height() |
| 48 | + assert_equal(1, tip_height) |
| 49 | + |
| 50 | + # restart the node with different magic bytes and check that db was cleaned up |
| 51 | + self.restart_node(0, extra_args=["--chain-magic-bytes=ffff"]) |
| 52 | + tip_height = self.nodes[0].chainstate_best_block_height() |
| 53 | + assert_equal(0, tip_height) |
| 54 | + |
| 55 | + |
| 56 | +if __name__ == '__main__': |
| 57 | + RestartWithDifferentMagicBytes().main() |
0 commit comments