mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
[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.
This commit is contained in:
parent
c2d04f1319
commit
802e6e128b
3 changed files with 33 additions and 0 deletions
|
@ -682,6 +682,17 @@ std::string HelpMessageOpt(const std::string &option, const std::string &message
|
|||
std::string("\n\n");
|
||||
}
|
||||
|
||||
const std::vector<std::string> TEST_OPTIONS_DOC{
|
||||
};
|
||||
|
||||
bool HasTestOption(const ArgsManager& args, const std::string& test_option)
|
||||
{
|
||||
const auto options = args.GetArgs("-test");
|
||||
return std::any_of(options.begin(), options.end(), [test_option](const auto& option) {
|
||||
return option == test_option;
|
||||
});
|
||||
}
|
||||
|
||||
fs::path GetDefaultDataDir()
|
||||
{
|
||||
// Windows: C:\Users\Username\AppData\Roaming\Bitcoin
|
||||
|
|
|
@ -447,6 +447,11 @@ bool HelpRequested(const ArgsManager& args);
|
|||
/** Add help options to the args manager */
|
||||
void SetupHelpOptions(ArgsManager& args);
|
||||
|
||||
extern const std::vector<std::string> TEST_OPTIONS_DOC;
|
||||
|
||||
/** Checks if a particular test option is present in -test command-line arg options */
|
||||
bool HasTestOption(const ArgsManager& args, const std::string& test_option);
|
||||
|
||||
/**
|
||||
* Format a string to be used as group of options in help messages
|
||||
*
|
||||
|
|
17
src/init.cpp
17
src/init.cpp
|
@ -611,6 +611,7 @@ void SetupServerArgs(ArgsManager& argsman)
|
|||
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);
|
||||
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);
|
||||
argsman.AddArg("-addrmantest", "Allows to test address relay on localhost", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||
argsman.AddArg("-test=<option>", "Pass a test-only option. Options include : " + Join(TEST_OPTIONS_DOC, ", ") + ".", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||
argsman.AddArg("-capturemessages", "Capture all P2P messages to disk", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||
argsman.AddArg("-mocktime=<n>", "Replace actual time with " + UNIX_EPOCH_TIME + " (default: 0)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||
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)
|
|||
if (args.GetBoolArg("-peerbloomfilters", DEFAULT_PEERBLOOMFILTERS))
|
||||
nLocalServices = ServiceFlags(nLocalServices | NODE_BLOOM);
|
||||
|
||||
if (args.IsArgSet("-test")) {
|
||||
if (chainparams.GetChainType() != ChainType::REGTEST) {
|
||||
return InitError(Untranslated("-test=<option> should only be used in functional tests"));
|
||||
}
|
||||
const std::vector<std::string> options = args.GetArgs("-test");
|
||||
for (const std::string& option : options) {
|
||||
auto it = std::find_if(TEST_OPTIONS_DOC.begin(), TEST_OPTIONS_DOC.end(), [&option](const std::string& doc_option) {
|
||||
size_t pos = doc_option.find(" (");
|
||||
return (pos != std::string::npos) && (doc_option.substr(0, pos) == option);
|
||||
});
|
||||
if (it == TEST_OPTIONS_DOC.end()) {
|
||||
InitWarning(strprintf(_("Unrecognised option \"%s\" provided in -test=<option>."), option));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Also report errors from parsing before daemonization
|
||||
{
|
||||
kernel::Notifications notifications{};
|
||||
|
|
Loading…
Add table
Reference in a new issue