Skip to content

Commit 052c54e

Browse files
committed
Testchains: Generic selection with -chain=<str> in addition of -testnet and -regtest
1 parent ae3e3bd commit 052c54e

File tree

8 files changed

+17
-14
lines changed

8 files changed

+17
-14
lines changed

src/bitcoin-cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static int AppInitRPC(int argc, char* argv[])
133133
tfm::format(std::cerr, "Error reading configuration file: %s\n", error.c_str());
134134
return EXIT_FAILURE;
135135
}
136-
// Check for -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
136+
// Check for -chain, -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
137137
try {
138138
SelectBaseParams(gArgs.GetChainName());
139139
} catch (const std::exception& e) {

src/bitcoin-tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static int AppInitRawTx(int argc, char* argv[])
8888
return EXIT_FAILURE;
8989
}
9090

91-
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
91+
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
9292
try {
9393
SelectParams(gArgs.GetChainName());
9494
} catch (const std::exception& e) {

src/bitcoind.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static bool AppInit(int argc, char* argv[])
101101
if (!gArgs.ReadConfigFiles(error, true)) {
102102
return InitError(strprintf("Error reading configuration file: %s\n", error));
103103
}
104-
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
104+
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
105105
try {
106106
SelectParams(gArgs.GetChainName());
107107
} catch (const std::exception& e) {

src/chainparamsbase.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ const std::string CBaseChainParams::REGTEST = "regtest";
1717

1818
void SetupChainParamsBaseOptions()
1919
{
20+
gArgs.AddArg("-chain=<chain>", "Use the chain <chain> (default: main). Allowed values: main, test, regtest", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
2021
gArgs.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
21-
"This is intended for regression testing tools and app development.", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
22+
"This is intended for regression testing tools and app development. Equivalent to -chain=regtest.", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
2223
gArgs.AddArg("-segwitheight=<n>", "Set the activation height of segwit. -1 to disable. (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
23-
gArgs.AddArg("-testnet", "Use the test chain", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
24+
gArgs.AddArg("-testnet", "Use the test chain. Equivalent to -chain=test.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
2425
gArgs.AddArg("-vbparams=deployment:start:end", "Use given start/end times for specified version bits deployment (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
2526
}
2627

src/qt/bitcoin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ int GuiMain(int argc, char* argv[])
511511
// - QSettings() will use the new application name after this, resulting in network-specific settings
512512
// - Needs to be done before createOptionsModel
513513

514-
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
514+
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
515515
try {
516516
node->selectParams(gArgs.GetChainName());
517517
} catch(std::exception &e) {

src/qt/guiutil.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ bool SetStartOnSystemStartup(bool fAutoStart)
588588
// Start client minimized
589589
QString strArgs = "-min";
590590
// Set -testnet /-regtest options
591-
strArgs += QString::fromStdString(strprintf(" -testnet=%d -regtest=%d", gArgs.GetBoolArg("-testnet", false), gArgs.GetBoolArg("-regtest", false)));
591+
strArgs += QString::fromStdString(strprintf(" -chain=%s", gArgs.GetChainName()));
592592

593593
// Set the path to the shortcut target
594594
psl->SetPath(pszExePath);
@@ -683,7 +683,7 @@ bool SetStartOnSystemStartup(bool fAutoStart)
683683
optionFile << "Name=Bitcoin\n";
684684
else
685685
optionFile << strprintf("Name=Bitcoin (%s)\n", chain);
686-
optionFile << "Exec=" << pszExePath << strprintf(" -min -testnet=%d -regtest=%d\n", gArgs.GetBoolArg("-testnet", false), gArgs.GetBoolArg("-regtest", false));
686+
optionFile << "Exec=" << pszExePath << strprintf(" -min -chain=%s\n", chain);
687687
optionFile << "Terminal=false\n";
688688
optionFile << "Hidden=false\n";
689689
optionFile.close();

src/test/util_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ BOOST_FIXTURE_TEST_CASE(util_ChainMerge, ChainMergeTestingSetup)
913913
// Results file is formatted like:
914914
//
915915
// <input> || <output>
916-
BOOST_CHECK_EQUAL(out_sha_hex, "b284f4b4a15dd6bf8c06213a69a004b1960388e1d9917173927db52ac220927f");
916+
BOOST_CHECK_EQUAL(out_sha_hex, "94b4ad55c8ac639a56b93e36f7e32e4c611fd7d7dd7b2be6a71707b1eadcaec7");
917917
}
918918

919919
BOOST_AUTO_TEST_CASE(util_FormatMoney)

src/util/system.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -954,16 +954,18 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
954954
std::string ArgsManager::GetChainName() const
955955
{
956956
LOCK(cs_args);
957-
bool fRegTest = ArgsManagerHelper::GetNetBoolArg(*this, "-regtest");
958-
bool fTestNet = ArgsManagerHelper::GetNetBoolArg(*this, "-testnet");
957+
const bool fRegTest = ArgsManagerHelper::GetNetBoolArg(*this, "-regtest");
958+
const bool fTestNet = ArgsManagerHelper::GetNetBoolArg(*this, "-testnet");
959+
const bool is_chain_arg_set = IsArgSet("-chain");
959960

960-
if (fTestNet && fRegTest)
961-
throw std::runtime_error("Invalid combination of -regtest and -testnet.");
961+
if ((int)is_chain_arg_set + (int)fRegTest + (int)fTestNet > 1) {
962+
throw std::runtime_error("Invalid combination of -regtest, -testnet and -chain. Can use at most one.");
963+
}
962964
if (fRegTest)
963965
return CBaseChainParams::REGTEST;
964966
if (fTestNet)
965967
return CBaseChainParams::TESTNET;
966-
return CBaseChainParams::MAIN;
968+
return GetArg("-chain", CBaseChainParams::MAIN);
967969
}
968970

969971
bool RenameOver(fs::path src, fs::path dest)

0 commit comments

Comments
 (0)