mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 02:33:24 -03:00
test: Add tests for -noconf
This commit is contained in:
parent
483f0dacc4
commit
e4b6b1822c
1 changed files with 32 additions and 0 deletions
|
@ -39,6 +39,37 @@ class ConfArgsTest(BitcoinTestFramework):
|
||||||
self.nodes[0].debug_log_path.parent.mkdir()
|
self.nodes[0].debug_log_path.parent.mkdir()
|
||||||
self.nodes[0].debug_log_path.touch()
|
self.nodes[0].debug_log_path.touch()
|
||||||
|
|
||||||
|
def test_negated_config(self):
|
||||||
|
self.log.info('Disabling configuration via -noconf')
|
||||||
|
|
||||||
|
conf_path = self.nodes[0].datadir_path / 'bitcoin.conf'
|
||||||
|
with open(conf_path, encoding='utf-8') as conf:
|
||||||
|
settings = [f'-{line.rstrip()}' for line in conf if len(line) > 1 and line[0] != '[']
|
||||||
|
os.rename(conf_path, conf_path.with_suffix('.confbkp'))
|
||||||
|
|
||||||
|
self.log.debug('Verifying garbage in config can be detected')
|
||||||
|
with open(conf_path, 'a', encoding='utf-8') as conf:
|
||||||
|
conf.write(f'garbage\n')
|
||||||
|
self.nodes[0].assert_start_raises_init_error(
|
||||||
|
extra_args=['-regtest'],
|
||||||
|
expected_msg='Error: Error reading configuration file: parse error on line 1: garbage',
|
||||||
|
)
|
||||||
|
|
||||||
|
self.log.debug('Verifying that disabling of the config file means garbage inside of it does ' \
|
||||||
|
'not prevent the node from starting, and message about existing config file is logged')
|
||||||
|
ignored_file_message = [f'[InitConfig] Data directory "{self.nodes[0].datadir_path}" contains a "bitcoin.conf" file which is explicitly ignored using -noconf.']
|
||||||
|
with self.nodes[0].assert_debug_log(timeout=60, expected_msgs=ignored_file_message):
|
||||||
|
self.start_node(0, extra_args=settings + ['-noconf'])
|
||||||
|
self.stop_node(0)
|
||||||
|
|
||||||
|
self.log.debug('Verifying no message appears when removing config file')
|
||||||
|
os.remove(conf_path)
|
||||||
|
with self.nodes[0].assert_debug_log(timeout=60, expected_msgs=[], unexpected_msgs=ignored_file_message):
|
||||||
|
self.start_node(0, extra_args=settings + ['-noconf'])
|
||||||
|
self.stop_node(0)
|
||||||
|
|
||||||
|
os.rename(conf_path.with_suffix('.confbkp'), conf_path)
|
||||||
|
|
||||||
def test_config_file_parser(self):
|
def test_config_file_parser(self):
|
||||||
self.log.info('Test config file parser')
|
self.log.info('Test config file parser')
|
||||||
|
|
||||||
|
@ -436,6 +467,7 @@ class ConfArgsTest(BitcoinTestFramework):
|
||||||
self.test_networkactive()
|
self.test_networkactive()
|
||||||
self.test_connect_with_seednode()
|
self.test_connect_with_seednode()
|
||||||
|
|
||||||
|
self.test_negated_config()
|
||||||
self.test_config_file_parser()
|
self.test_config_file_parser()
|
||||||
self.test_config_file_log()
|
self.test_config_file_log()
|
||||||
self.test_invalid_command_line_options()
|
self.test_invalid_command_line_options()
|
||||||
|
|
Loading…
Add table
Reference in a new issue