Skip to content

Commit 264efdc

Browse files
committed
Merge #13367: qa: Increase includeconf test coverage
fa4760f qa: Increase includeconf test coverage (MarcoFalke) Pull request description: This adds some missing `return false` for error conditions and adds test coverage [1] for those. Also, extend recursion warning when the chain was set in one of the includeconfs. [1] See the red lines in https://marcofalke.github.io/btc_cov/total.coverage/src/util.cpp.gcov.html for missing coverage. Tree-SHA512: d32563c9bb277879895a173e699034db5ecdb4061a1ec8890c566d61e36a09efa5eda19a029baf952ff6d568f8b9684a13a0bb90827850075470975e2088fee4
2 parents f0fd39f + fa4760f commit 264efdc

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

src/util.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,9 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
459459
if (it != m_override_args.end()) {
460460
if (it->second.size() > 0) {
461461
for (const auto& ic : it->second) {
462-
fprintf(stderr, "warning: -includeconf cannot be used from commandline; ignoring -includeconf=%s\n", ic.c_str());
462+
error += "-includeconf cannot be used from commandline; -includeconf=" + ic + "\n";
463463
}
464-
m_override_args.erase(it);
464+
return false;
465465
}
466466
}
467467
return true;
@@ -849,11 +849,12 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
849849
// if there is an -includeconf in the override args, but it is empty, that means the user
850850
// passed '-noincludeconf' on the command line, in which case we should not include anything
851851
if (m_override_args.count("-includeconf") == 0) {
852+
std::string chain_id = GetChainName();
852853
std::vector<std::string> includeconf(GetArgs("-includeconf"));
853854
{
854855
// We haven't set m_network yet (that happens in SelectParams()), so manually check
855856
// for network.includeconf args.
856-
std::vector<std::string> includeconf_net(GetArgs(std::string("-") + GetChainName() + ".includeconf"));
857+
std::vector<std::string> includeconf_net(GetArgs(std::string("-") + chain_id + ".includeconf"));
857858
includeconf.insert(includeconf.end(), includeconf_net.begin(), includeconf_net.end());
858859
}
859860

@@ -862,7 +863,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
862863
{
863864
LOCK(cs_args);
864865
m_config_args.erase("-includeconf");
865-
m_config_args.erase(std::string("-") + GetChainName() + ".includeconf");
866+
m_config_args.erase(std::string("-") + chain_id + ".includeconf");
866867
}
867868

868869
for (const std::string& to_include : includeconf) {
@@ -873,15 +874,22 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
873874
}
874875
LogPrintf("Included configuration file %s\n", to_include.c_str());
875876
} else {
876-
fprintf(stderr, "Failed to include configuration file %s\n", to_include.c_str());
877+
error = "Failed to include configuration file " + to_include;
878+
return false;
877879
}
878880
}
879881

880882
// Warn about recursive -includeconf
881883
includeconf = GetArgs("-includeconf");
882884
{
883-
std::vector<std::string> includeconf_net(GetArgs(std::string("-") + GetChainName() + ".includeconf"));
885+
std::vector<std::string> includeconf_net(GetArgs(std::string("-") + chain_id + ".includeconf"));
884886
includeconf.insert(includeconf.end(), includeconf_net.begin(), includeconf_net.end());
887+
std::string chain_id_final = GetChainName();
888+
if (chain_id_final != chain_id) {
889+
// Also warn about recursive includeconf for the chain that was specified in one of the includeconfs
890+
includeconf_net = GetArgs(std::string("-") + chain_id_final + ".includeconf");
891+
includeconf.insert(includeconf.end(), includeconf_net.begin(), includeconf_net.end());
892+
}
885893
}
886894
for (const std::string& to_include : includeconf) {
887895
fprintf(stderr, "warning: -includeconf cannot be used from included files; ignoring -includeconf=%s\n", to_include.c_str());

test/functional/feature_includeconf.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,9 @@ def run_test(self):
4141
subversion = self.nodes[0].getnetworkinfo()["subversion"]
4242
assert subversion.endswith("main; relative)/")
4343

44-
self.log.info("-includeconf cannot be used as command-line arg. subversion should still end with 'main; relative)/'")
44+
self.log.info("-includeconf cannot be used as command-line arg")
4545
self.stop_node(0)
46-
47-
self.start_node(0, extra_args=["-includeconf=relative2.conf"])
48-
49-
subversion = self.nodes[0].getnetworkinfo()["subversion"]
50-
assert subversion.endswith("main; relative)/")
51-
self.stop_node(0, expected_stderr="warning: -includeconf cannot be used from commandline; ignoring -includeconf=relative2.conf")
46+
self.nodes[0].assert_start_raises_init_error(extra_args=["-includeconf=relative2.conf"], expected_msg="Error parsing command line arguments: -includeconf cannot be used from commandline; -includeconf=relative2.conf")
5247

5348
self.log.info("-includeconf cannot be used recursively. subversion should end with 'main; relative)/'")
5449
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "a", encoding="utf8") as f:
@@ -59,8 +54,18 @@ def run_test(self):
5954
assert subversion.endswith("main; relative)/")
6055
self.stop_node(0, expected_stderr="warning: -includeconf cannot be used from included files; ignoring -includeconf=relative2.conf")
6156

57+
self.log.info("-includeconf cannot contain invalid arg")
58+
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "w", encoding="utf8") as f:
59+
f.write("foo=bar\n")
60+
self.nodes[0].assert_start_raises_init_error(expected_msg="Error reading configuration file: Invalid configuration value foo")
61+
62+
self.log.info("-includeconf cannot be invalid path")
63+
os.remove(os.path.join(self.options.tmpdir, "node0", "relative.conf"))
64+
self.nodes[0].assert_start_raises_init_error(expected_msg="Error reading configuration file: Failed to include configuration file relative.conf")
65+
6266
self.log.info("multiple -includeconf args can be used from the base config file. subversion should end with 'main; relative; relative2)/'")
6367
with open(os.path.join(self.options.tmpdir, "node0", "relative.conf"), "w", encoding="utf8") as f:
68+
# Restore initial file contents
6469
f.write("uacomment=relative\n")
6570

6671
with open(os.path.join(self.options.tmpdir, "node0", "bitcoin.conf"), "a", encoding='utf8') as f:

0 commit comments

Comments
 (0)