Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_includeconf.py
Show All 21 Lines | |||||
class IncludeConfTest(BitcoinTestFramework): | class IncludeConfTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
def setup_chain(self): | def setup_chain(self): | ||||
super().setup_chain() | super().setup_chain() | ||||
# Create additional config files | # Create additional config files | ||||
# - tmpdir/node0/relative.conf | # - tmpdir/node0/relative.conf | ||||
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "w", encoding="utf8") as f: | with open( | ||||
os.path.join(self.options.tmpdir, "node0", "relative.conf"), | |||||
"w", | |||||
encoding="utf8", | |||||
) as f: | |||||
f.write("uacomment=relative\n") | f.write("uacomment=relative\n") | ||||
# - tmpdir/node0/relative2.conf | # - tmpdir/node0/relative2.conf | ||||
with open(os.path.join(self.options.tmpdir, "node0", "relative2.conf"), "w", encoding="utf8") as f: | with open( | ||||
os.path.join(self.options.tmpdir, "node0", "relative2.conf"), | |||||
"w", | |||||
encoding="utf8", | |||||
) as f: | |||||
f.write("uacomment=relative2\n") | f.write("uacomment=relative2\n") | ||||
with open(os.path.join(self.options.tmpdir, "node0", "bitcoin.conf"), "a", encoding='utf8') as f: | with open( | ||||
os.path.join(self.options.tmpdir, "node0", "bitcoin.conf"), | |||||
"a", | |||||
encoding="utf8", | |||||
) as f: | |||||
f.write("uacomment=main\nincludeconf=relative.conf\n") | f.write("uacomment=main\nincludeconf=relative.conf\n") | ||||
def run_test(self): | def run_test(self): | ||||
self.log.info( | self.log.info( | ||||
"-includeconf works from config file. subversion should end with 'main; relative)/'") | "-includeconf works from config file. subversion should end with 'main;" | ||||
" relative)/'" | |||||
) | |||||
subversion = self.nodes[0].getnetworkinfo()["subversion"] | subversion = self.nodes[0].getnetworkinfo()["subversion"] | ||||
assert subversion.endswith("main; relative)/") | assert subversion.endswith("main; relative)/") | ||||
self.log.info("-includeconf cannot be used as command-line arg") | self.log.info("-includeconf cannot be used as command-line arg") | ||||
self.stop_node(0) | self.stop_node(0) | ||||
self.nodes[0].assert_start_raises_init_error(extra_args=["-includeconf=relative2.conf"], | self.nodes[0].assert_start_raises_init_error( | ||||
expected_msg="Error: Error parsing command line arguments: -includeconf cannot be used from commandline; -includeconf=relative2.conf") | extra_args=["-includeconf=relative2.conf"], | ||||
expected_msg=( | |||||
"Error: Error parsing command line arguments: -includeconf cannot be" | |||||
" used from commandline; -includeconf=relative2.conf" | |||||
), | |||||
) | |||||
self.log.info( | self.log.info( | ||||
"-includeconf cannot be used recursively. subversion should end with 'main; relative)/'") | "-includeconf cannot be used recursively. subversion should end with 'main;" | ||||
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "a", encoding="utf8") as f: | " relative)/'" | ||||
) | |||||
with open( | |||||
os.path.join(self.options.tmpdir, "node0", "relative.conf"), | |||||
"a", | |||||
encoding="utf8", | |||||
) as f: | |||||
f.write("includeconf=relative2.conf\n") | f.write("includeconf=relative2.conf\n") | ||||
self.start_node(0) | self.start_node(0) | ||||
subversion = self.nodes[0].getnetworkinfo()["subversion"] | subversion = self.nodes[0].getnetworkinfo()["subversion"] | ||||
assert subversion.endswith("main; relative)/") | assert subversion.endswith("main; relative)/") | ||||
self.stop_node( | self.stop_node( | ||||
0, expected_stderr="warning: -includeconf cannot be used from included files; ignoring -includeconf=relative2.conf") | 0, | ||||
expected_stderr=( | |||||
"warning: -includeconf cannot be used from included files; ignoring" | |||||
" -includeconf=relative2.conf" | |||||
), | |||||
) | |||||
self.log.info("-includeconf cannot contain invalid arg") | self.log.info("-includeconf cannot contain invalid arg") | ||||
# Commented out as long as we ignore invalid arguments in configuration files | # Commented out as long as we ignore invalid arguments in configuration files | ||||
# with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "w", encoding="utf8") as f: | # with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "w", encoding="utf8") as f: | ||||
# f.write("foo=bar\n") | # f.write("foo=bar\n") | ||||
# self.nodes[0].assert_start_raises_init_error( | # self.nodes[0].assert_start_raises_init_error( | ||||
# expected_msg="Error: Error reading configuration file: Invalid configuration value foo") | # expected_msg="Error: Error reading configuration file: Invalid configuration value foo") | ||||
# See https://github.com/bitcoin/bitcoin/pull/13799 | # See https://github.com/bitcoin/bitcoin/pull/13799 | ||||
self.log.info("-includeconf cannot be invalid path") | self.log.info("-includeconf cannot be invalid path") | ||||
os.remove(os.path.join(self.options.tmpdir, "node0", "relative.conf")) | os.remove(os.path.join(self.options.tmpdir, "node0", "relative.conf")) | ||||
self.nodes[0].assert_start_raises_init_error( | self.nodes[0].assert_start_raises_init_error( | ||||
expected_msg="Error: Error reading configuration file: Failed to include configuration file relative.conf") | expected_msg=( | ||||
"Error: Error reading configuration file: Failed to include" | |||||
" configuration file relative.conf" | |||||
) | |||||
) | |||||
self.log.info( | self.log.info( | ||||
"multiple -includeconf args can be used from the base config file. subversion should end with 'main; relative; relative2)/'") | "multiple -includeconf args can be used from the base config file." | ||||
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "w", encoding="utf8") as f: | " subversion should end with 'main; relative; relative2)/'" | ||||
) | |||||
with open( | |||||
os.path.join(self.options.tmpdir, "node0", "relative.conf"), | |||||
"w", | |||||
encoding="utf8", | |||||
) as f: | |||||
# Restore initial file contents | # Restore initial file contents | ||||
f.write("uacomment=relative\n") | f.write("uacomment=relative\n") | ||||
with open(os.path.join(self.options.tmpdir, "node0", "bitcoin.conf"), "a", encoding='utf8') as f: | with open( | ||||
os.path.join(self.options.tmpdir, "node0", "bitcoin.conf"), | |||||
"a", | |||||
encoding="utf8", | |||||
) as f: | |||||
f.write("includeconf=relative2.conf\n") | f.write("includeconf=relative2.conf\n") | ||||
self.start_node(0) | self.start_node(0) | ||||
subversion = self.nodes[0].getnetworkinfo()["subversion"] | subversion = self.nodes[0].getnetworkinfo()["subversion"] | ||||
assert subversion.endswith("main; relative; relative2)/") | assert subversion.endswith("main; relative; relative2)/") | ||||
if __name__ == '__main__': | if __name__ == "__main__": | ||||
IncludeConfTest().main() | IncludeConfTest().main() |