Skip to content

Commit e4b6b18

Browse files
committed
test: Add tests for -noconf
1 parent 483f0da commit e4b6b18

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/functional/feature_config_args.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,37 @@ def setup_nodes(self):
3939
self.nodes[0].debug_log_path.parent.mkdir()
4040
self.nodes[0].debug_log_path.touch()
4141

42+
def test_negated_config(self):
43+
self.log.info('Disabling configuration via -noconf')
44+
45+
conf_path = self.nodes[0].datadir_path / 'bitcoin.conf'
46+
with open(conf_path, encoding='utf-8') as conf:
47+
settings = [f'-{line.rstrip()}' for line in conf if len(line) > 1 and line[0] != '[']
48+
os.rename(conf_path, conf_path.with_suffix('.confbkp'))
49+
50+
self.log.debug('Verifying garbage in config can be detected')
51+
with open(conf_path, 'a', encoding='utf-8') as conf:
52+
conf.write(f'garbage\n')
53+
self.nodes[0].assert_start_raises_init_error(
54+
extra_args=['-regtest'],
55+
expected_msg='Error: Error reading configuration file: parse error on line 1: garbage',
56+
)
57+
58+
self.log.debug('Verifying that disabling of the config file means garbage inside of it does ' \
59+
'not prevent the node from starting, and message about existing config file is logged')
60+
ignored_file_message = [f'[InitConfig] Data directory "{self.nodes[0].datadir_path}" contains a "bitcoin.conf" file which is explicitly ignored using -noconf.']
61+
with self.nodes[0].assert_debug_log(timeout=60, expected_msgs=ignored_file_message):
62+
self.start_node(0, extra_args=settings + ['-noconf'])
63+
self.stop_node(0)
64+
65+
self.log.debug('Verifying no message appears when removing config file')
66+
os.remove(conf_path)
67+
with self.nodes[0].assert_debug_log(timeout=60, expected_msgs=[], unexpected_msgs=ignored_file_message):
68+
self.start_node(0, extra_args=settings + ['-noconf'])
69+
self.stop_node(0)
70+
71+
os.rename(conf_path.with_suffix('.confbkp'), conf_path)
72+
4273
def test_config_file_parser(self):
4374
self.log.info('Test config file parser')
4475

@@ -436,6 +467,7 @@ def run_test(self):
436467
self.test_networkactive()
437468
self.test_connect_with_seednode()
438469

470+
self.test_negated_config()
439471
self.test_config_file_parser()
440472
self.test_config_file_log()
441473
self.test_invalid_command_line_options()

0 commit comments

Comments
 (0)