Skip to content

Commit 802e6e1

Browse files
committed
[init] Add new command line arg for use only in functional tests
some of the existing command line args are to be only used in functional tests. ex: addrmantest, fastprune etc.. make a separate category -test=<option> for these so that code is cleaner and user's debug-help output is straightforward.
1 parent c2d04f1 commit 802e6e1

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/common/args.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,17 @@ std::string HelpMessageOpt(const std::string &option, const std::string &message
682682
std::string("\n\n");
683683
}
684684

685+
const std::vector<std::string> TEST_OPTIONS_DOC{
686+
};
687+
688+
bool HasTestOption(const ArgsManager& args, const std::string& test_option)
689+
{
690+
const auto options = args.GetArgs("-test");
691+
return std::any_of(options.begin(), options.end(), [test_option](const auto& option) {
692+
return option == test_option;
693+
});
694+
}
695+
685696
fs::path GetDefaultDataDir()
686697
{
687698
// Windows: C:\Users\Username\AppData\Roaming\Bitcoin

src/common/args.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,11 @@ bool HelpRequested(const ArgsManager& args);
447447
/** Add help options to the args manager */
448448
void SetupHelpOptions(ArgsManager& args);
449449

450+
extern const std::vector<std::string> TEST_OPTIONS_DOC;
451+
452+
/** Checks if a particular test option is present in -test command-line arg options */
453+
bool HasTestOption(const ArgsManager& args, const std::string& test_option);
454+
450455
/**
451456
* Format a string to be used as group of options in help messages
452457
*

src/init.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ void SetupServerArgs(ArgsManager& argsman)
611611
argsman.AddArg("-limitdescendantcount=<n>", strprintf("Do not accept transactions if any ancestor would have <n> or more in-mempool descendants (default: %u)", DEFAULT_DESCENDANT_LIMIT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
612612
argsman.AddArg("-limitdescendantsize=<n>", strprintf("Do not accept transactions if any ancestor would have more than <n> kilobytes of in-mempool descendants (default: %u).", DEFAULT_DESCENDANT_SIZE_LIMIT_KVB), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
613613
argsman.AddArg("-addrmantest", "Allows to test address relay on localhost", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
614+
argsman.AddArg("-test=<option>", "Pass a test-only option. Options include : " + Join(TEST_OPTIONS_DOC, ", ") + ".", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
614615
argsman.AddArg("-capturemessages", "Capture all P2P messages to disk", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
615616
argsman.AddArg("-mocktime=<n>", "Replace actual time with " + UNIX_EPOCH_TIME + " (default: 0)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
616617
argsman.AddArg("-maxsigcachesize=<n>", strprintf("Limit sum of signature cache and script execution cache sizes to <n> MiB (default: %u)", DEFAULT_MAX_SIG_CACHE_BYTES >> 20), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
@@ -1024,6 +1025,22 @@ bool AppInitParameterInteraction(const ArgsManager& args)
10241025
if (args.GetBoolArg("-peerbloomfilters", DEFAULT_PEERBLOOMFILTERS))
10251026
nLocalServices = ServiceFlags(nLocalServices | NODE_BLOOM);
10261027

1028+
if (args.IsArgSet("-test")) {
1029+
if (chainparams.GetChainType() != ChainType::REGTEST) {
1030+
return InitError(Untranslated("-test=<option> should only be used in functional tests"));
1031+
}
1032+
const std::vector<std::string> options = args.GetArgs("-test");
1033+
for (const std::string& option : options) {
1034+
auto it = std::find_if(TEST_OPTIONS_DOC.begin(), TEST_OPTIONS_DOC.end(), [&option](const std::string& doc_option) {
1035+
size_t pos = doc_option.find(" (");
1036+
return (pos != std::string::npos) && (doc_option.substr(0, pos) == option);
1037+
});
1038+
if (it == TEST_OPTIONS_DOC.end()) {
1039+
InitWarning(strprintf(_("Unrecognised option \"%s\" provided in -test=<option>."), option));
1040+
}
1041+
}
1042+
}
1043+
10271044
// Also report errors from parsing before daemonization
10281045
{
10291046
kernel::Notifications notifications{};

0 commit comments

Comments
 (0)