Skip to content

Commit

Permalink
test: Add tests for directory in place of config files, -noconf
Browse files Browse the repository at this point in the history
  • Loading branch information
hodlinator committed Nov 18, 2024
1 parent 1607d8d commit c30e89f
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/functional/feature_config_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,54 @@ def set_test_params(self):
self.wallet_names = []
self.disable_autoconnect = False

def test_dir_config(self):
self.log.info('Error should be emitted if config file is a directory')
conf_path = self.nodes[0].datadir_path / 'bitcoin.conf'
os.rename(conf_path, conf_path.with_suffix('.confbkp'))
conf_path.mkdir()
self.stop_node(0)
self.nodes[0].assert_start_raises_init_error(
expected_msg=f'Error: Error reading configuration file: config file "{conf_path}" is a directory.',
)
conf_path.rmdir()
os.rename(conf_path.with_suffix('.confbkp'), conf_path)

self.log.debug('Verifying includeconf directive pointing to directory is caught')
with open(conf_path, 'a', encoding='utf-8') as conf:
conf.write(f'includeconf={self.nodes[0].datadir_path}\n')
self.nodes[0].assert_start_raises_init_error(
expected_msg=f'Error: Error reading configuration file: included config file "{conf_path}" is a directory.',
)
self.nodes[0].replace_in_config([(f'includeconf={self.nodes[0].datadir_path}', '')])

def test_negated_config(self):
self.log.info('Disabling configuration via -noconf')

self.log.debug('Verifying garbage in config can be detected')
conf_path = self.nodes[0].datadir_path / 'bitcoin.conf'
os.rename(conf_path, conf_path.with_suffix('.confbkp'))
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 error when attempting to disable config')
self.nodes[0].assert_start_raises_init_error(
extra_args=['-regtest', '-noconf'],
expected_msg=f'Error: Data directory "{self.nodes[0].datadir_path}" contains a "bitcoin.conf" file which is ignored, because -noconf has been set to disable config reading.\n- Set allowignoredconf=1 option to treat this condition as a warning, not an error.',
)

self.log.debug('Verifying no error occurs when adding -allowignoredconf')
self.start_node(0, extra_args=['-regtest', '-noconf', '-allowignoredconf', f'-rpcport={util.rpc_port(0)}'])

self.log.debug('Verifying no error occurs when removing config file')
os.remove(conf_path)
self.restart_node(0, extra_args=['-regtest', '-noconf', f'-rpcport={util.rpc_port(0)}'])
self.stop_node(0)
os.rename(conf_path.with_suffix('.confbkp'), conf_path)

def test_config_file_parser(self):
self.log.info('Test config file parser')
self.stop_node(0)
Expand Down Expand Up @@ -423,6 +471,8 @@ def run_test(self):
self.test_networkactive()
self.test_connect_with_seednode()

self.test_dir_config()
self.test_negated_config()
self.test_config_file_parser()
self.test_config_file_log()
self.test_invalid_command_line_options()
Expand Down

0 comments on commit c30e89f

Please sign in to comment.