(self)
| 38 | extra_args=[f'-settings={settings_path}']) |
| 39 | |
| 40 | def run_test(self): |
| 41 | node, = self.nodes |
| 42 | settings = node.chain_path / "settings.json" |
| 43 | conf = node.datadir_path / "bitcoin.conf" |
| 44 | |
| 45 | # Assert default settings file was created |
| 46 | self.stop_node(0) |
| 47 | default_settings = {"_warning_": f"This file is automatically generated and updated by {self.config['environment']['CLIENT_NAME']}. Please do not edit this file while the node is running, as any changes might be ignored or overwritten."} |
| 48 | with settings.open() as fp: |
| 49 | assert_equal(json.load(fp), default_settings) |
| 50 | |
| 51 | # Assert settings are parsed and logged |
| 52 | with settings.open("w") as fp: |
| 53 | json.dump({"string": "string", "num": 5, "bool": True, "null": None, "list": [6, 7]}, fp) |
| 54 | with node.assert_debug_log(expected_msgs=[ |
| 55 | 'Ignoring unknown rw_settings value bool', |
| 56 | 'Ignoring unknown rw_settings value list', |
| 57 | 'Ignoring unknown rw_settings value null', |
| 58 | 'Ignoring unknown rw_settings value num', |
| 59 | 'Ignoring unknown rw_settings value string', |
| 60 | 'Setting file arg: string = "string"', |
| 61 | 'Setting file arg: num = 5', |
| 62 | 'Setting file arg: bool = true', |
| 63 | 'Setting file arg: null = null', |
| 64 | 'Setting file arg: list = [6,7]', |
| 65 | ]): |
| 66 | self.start_node(0) |
| 67 | self.stop_node(0) |
| 68 | |
| 69 | # Assert settings are unchanged after shutdown |
| 70 | with settings.open() as fp: |
| 71 | assert_equal(json.load(fp), {**default_settings, **{"string": "string", "num": 5, "bool": True, "null": None, "list": [6, 7]}}) |
| 72 | |
| 73 | # Test invalid json |
| 74 | with settings.open("w") as fp: |
| 75 | fp.write("invalid json") |
| 76 | node.assert_start_raises_init_error(expected_msg='does not contain valid JSON. This may be caused by a crash, power loss, full disk, or storage error', match=ErrorMatch.PARTIAL_REGEX) |
| 77 | |
| 78 | # Test invalid json object |
| 79 | with settings.open("w") as fp: |
| 80 | fp.write('"string"') |
| 81 | node.assert_start_raises_init_error(expected_msg='Found non-object value "string" in settings file', match=ErrorMatch.PARTIAL_REGEX) |
| 82 | |
| 83 | # Test invalid settings file containing duplicate keys |
| 84 | with settings.open("w") as fp: |
| 85 | fp.write('{"key": 1, "key": 2}') |
| 86 | node.assert_start_raises_init_error(expected_msg='Found duplicate key key in settings file', match=ErrorMatch.PARTIAL_REGEX) |
| 87 | |
| 88 | # Test invalid settings file is ignored with command line -nosettings |
| 89 | with node.assert_debug_log(expected_msgs=['Command-line arg: settings=false']): |
| 90 | self.start_node(0, extra_args=["-nosettings"]) |
| 91 | self.stop_node(0) |
| 92 | |
| 93 | # Test invalid settings file is ignored with config file -nosettings |
| 94 | with conf.open('a') as conf: |
| 95 | conf.write('nosettings=1\n') |
| 96 | with node.assert_debug_log(expected_msgs=['Config file arg: [regtest] settings=false']): |
| 97 | self.start_node(0) |
nothing calls this directly
no test coverage detected