Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_config_args.py
Show All 19 Lines | def test_config_file_parser(self): | ||||
# Assume node is stopped | # Assume node is stopped | ||||
inc_conf_file_path = os.path.join( | inc_conf_file_path = os.path.join( | ||||
self.nodes[0].datadir, 'include.conf') | self.nodes[0].datadir, 'include.conf') | ||||
with open(os.path.join(self.nodes[0].datadir, 'bitcoin.conf'), 'a', encoding='utf-8') as conf: | with open(os.path.join(self.nodes[0].datadir, 'bitcoin.conf'), 'a', encoding='utf-8') as conf: | ||||
conf.write('includeconf={}\n'.format(inc_conf_file_path)) | conf.write('includeconf={}\n'.format(inc_conf_file_path)) | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
expected_msg='Error parsing command line arguments: Invalid parameter -dash_cli', | expected_msg='Error: Error parsing command line arguments: Invalid parameter -dash_cli', | ||||
extra_args=['-dash_cli=1'], | extra_args=['-dash_cli=1'], | ||||
) | ) | ||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: | with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: | ||||
conf.write('dash_conf=1\n') | conf.write('dash_conf=1\n') | ||||
with self.nodes[0].assert_debug_log(expected_msgs=['Ignoring unknown configuration value dash_conf']): | with self.nodes[0].assert_debug_log(expected_msgs=['Ignoring unknown configuration value dash_conf']): | ||||
self.start_node(0) | self.start_node(0) | ||||
self.stop_node(0) | self.stop_node(0) | ||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: | with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: | ||||
conf.write('-dash=1\n') | conf.write('-dash=1\n') | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
expected_msg='Error reading configuration file: parse error on line 1: -dash=1, options in configuration file must be specified without leading -') | expected_msg='Error: Error reading configuration file: parse error on line 1: -dash=1, options in configuration file must be specified without leading -') | ||||
if self.is_wallet_compiled(): | if self.is_wallet_compiled(): | ||||
with open(inc_conf_file_path, 'w', encoding='utf8') as conf: | with open(inc_conf_file_path, 'w', encoding='utf8') as conf: | ||||
conf.write("wallet=foo\n") | conf.write("wallet=foo\n") | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
expected_msg='Error: Config setting for -wallet only applied on regtest network when in [regtest] section.') | expected_msg='Error: Config setting for -wallet only applied on regtest network when in [regtest] section.') | ||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: | with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: | ||||
conf.write('regtest=0\n') # mainnet | conf.write('regtest=0\n') # mainnet | ||||
conf.write('acceptnonstdtxn=1\n') | conf.write('acceptnonstdtxn=1\n') | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
expected_msg='Error: acceptnonstdtxn is not currently supported for main chain') | expected_msg='Error: acceptnonstdtxn is not currently supported for main chain') | ||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: | with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: | ||||
conf.write('nono\n') | conf.write('nono\n') | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
expected_msg='Error reading configuration file: parse error on line 1: nono, if you intended to specify a negated option, use nono=1 instead') | expected_msg='Error: Error reading configuration file: parse error on line 1: nono, if you intended to specify a negated option, use nono=1 instead') | ||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: | with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: | ||||
conf.write('server=1\nrpcuser=someuser\nrpcpassword=some#pass') | conf.write('server=1\nrpcuser=someuser\nrpcpassword=some#pass') | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
expected_msg='Error reading configuration file: parse error on line 3, using # in rpcpassword can be ambiguous and should be avoided') | expected_msg='Error: Error reading configuration file: parse error on line 3, using # in rpcpassword can be ambiguous and should be avoided') | ||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: | with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: | ||||
conf.write('server=1\nrpcuser=someuser\nmain.rpcpassword=some#pass') | conf.write('server=1\nrpcuser=someuser\nmain.rpcpassword=some#pass') | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
expected_msg='Error reading configuration file: parse error on line 3, using # in rpcpassword can be ambiguous and should be avoided') | expected_msg='Error: Error reading configuration file: parse error on line 3, using # in rpcpassword can be ambiguous and should be avoided') | ||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: | with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: | ||||
conf.write( | conf.write( | ||||
'server=1\nrpcuser=someuser\n[main]\nrpcpassword=some#pass') | 'server=1\nrpcuser=someuser\n[main]\nrpcpassword=some#pass') | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
expected_msg='Error reading configuration file: parse error on line 4, using # in rpcpassword can be ambiguous and should be avoided') | expected_msg='Error: Error reading configuration file: parse error on line 4, using # in rpcpassword can be ambiguous and should be avoided') | ||||
inc_conf_file2_path = os.path.join( | inc_conf_file2_path = os.path.join( | ||||
self.nodes[0].datadir, 'include2.conf') | self.nodes[0].datadir, 'include2.conf') | ||||
with open(os.path.join(self.nodes[0].datadir, 'bitcoin.conf'), 'a', encoding='utf-8') as conf: | with open(os.path.join(self.nodes[0].datadir, 'bitcoin.conf'), 'a', encoding='utf-8') as conf: | ||||
conf.write('includeconf={}\n'.format(inc_conf_file2_path)) | conf.write('includeconf={}\n'.format(inc_conf_file2_path)) | ||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: | with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: | ||||
conf.write('testnot.datadir=1\n') | conf.write('testnot.datadir=1\n') | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# datadir needs to be set before [regtest] section | # datadir needs to be set before [regtest] section | ||||
conf_file_contents = open(conf_file, encoding='utf8').read() | conf_file_contents = open(conf_file, encoding='utf8').read() | ||||
with open(conf_file, 'w', encoding='utf8') as f: | with open(conf_file, 'w', encoding='utf8') as f: | ||||
f.write("datadir=" + new_data_dir + "\n") | f.write("datadir=" + new_data_dir + "\n") | ||||
f.write(conf_file_contents) | f.write(conf_file_contents) | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
['-conf=' + conf_file], 'Error reading configuration file: specified data directory "' + new_data_dir + '" does not exist.') | ['-conf=' + conf_file], 'Error: Error reading configuration file: specified data directory "' + new_data_dir + '" does not exist.') | ||||
# Create the directory and ensure the config file now works | # Create the directory and ensure the config file now works | ||||
os.mkdir(new_data_dir) | os.mkdir(new_data_dir) | ||||
self.start_node(0, ['-conf=' + conf_file, '-wallet=w1']) | self.start_node(0, ['-conf=' + conf_file, '-wallet=w1']) | ||||
self.stop_node(0) | self.stop_node(0) | ||||
assert os.path.exists(os.path.join(new_data_dir, 'regtest', 'blocks')) | |||||
if self.is_wallet_compiled(): | |||||
assert os.path.exists(os.path.join( | assert os.path.exists(os.path.join( | ||||
new_data_dir, 'regtest', 'wallets', 'w1')) | new_data_dir, 'regtest', 'wallets', 'w1')) | ||||
# Ensure command line argument overrides datadir in conf | # Ensure command line argument overrides datadir in conf | ||||
os.mkdir(new_data_dir_2) | os.mkdir(new_data_dir_2) | ||||
self.nodes[0].datadir = new_data_dir_2 | self.nodes[0].datadir = new_data_dir_2 | ||||
self.start_node(0, ['-datadir=' + new_data_dir_2, | self.start_node(0, ['-datadir=' + new_data_dir_2, | ||||
'-conf=' + conf_file, '-wallet=w2']) | '-conf=' + conf_file, '-wallet=w2']) | ||||
assert os.path.exists(os.path.join( | assert os.path.exists(os.path.join( | ||||
new_data_dir_2, 'regtest', 'wallets', 'w2')) | new_data_dir_2, 'regtest', 'wallets', 'w2')) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
ConfArgsTest().main() | ConfArgsTest().main() |