Skip to content

Commit c2f61be

Browse files
committed
Add a ForceSetArg method for testing
1 parent 4e04814 commit c2f61be

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

src/qt/test/rpcnestedtests.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
#include <boost/filesystem.hpp>
2121

22-
extern std::map<std::string, std::string> mapArgs;
23-
2422
static UniValue rpcNestedTest_rpc(const JSONRPCRequest& request)
2523
{
2624
if (request.fHelp) {
@@ -47,7 +45,7 @@ void RPCNestedTests::rpcNestedTests()
4745
std::string path = QDir::tempPath().toStdString() + "/" + strprintf("test_bitcoin_qt_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000)));
4846
QDir dir(QString::fromStdString(path));
4947
dir.mkpath(".");
50-
mapArgs["-datadir"] = path;
48+
ForceSetArg("-datadir", path);
5149
//mempool.setSanityCheck(1.0);
5250
pblocktree = new CBlockTreeDB(1 << 20, true);
5351
pcoinsdbview = new CCoinsViewDB(1 << 23, true);

src/test/DoS_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "script/sign.h"
1313
#include "serialize.h"
1414
#include "util.h"
15+
#include "validation.h"
1516

1617
#include "test/test_bitcoin.h"
1718

@@ -32,7 +33,6 @@ struct COrphanTx {
3233
int64_t nTimeExpire;
3334
};
3435
extern std::map<uint256, COrphanTx> mapOrphanTransactions;
35-
extern std::map<std::string, std::string> mapArgs;
3636

3737
CService ip(uint32_t i)
3838
{
@@ -75,7 +75,7 @@ BOOST_AUTO_TEST_CASE(DoS_banning)
7575
BOOST_AUTO_TEST_CASE(DoS_banscore)
7676
{
7777
connman->ClearBanned();
78-
mapArgs["-banscore"] = "111"; // because 11 is my favorite number
78+
ForceSetArg("-banscore", "111"); // because 11 is my favorite number
7979
CAddress addr1(ip(0xa0b0c001), NODE_NONE);
8080
CNode dummyNode1(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr1, 3, 1, "", true);
8181
dummyNode1.SetSendVersion(PROTOCOL_VERSION);
@@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE(DoS_banscore)
9090
Misbehaving(dummyNode1.GetId(), 1);
9191
SendMessages(&dummyNode1, *connman);
9292
BOOST_CHECK(connman->IsBanned(addr1));
93-
mapArgs.erase("-banscore");
93+
ForceSetArg("-banscore", std::to_string(DEFAULT_BANSCORE_THRESHOLD));
9494
}
9595

9696
BOOST_AUTO_TEST_CASE(DoS_bantime)

src/test/test_bitcoin.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
std::unique_ptr<CConnman> g_connman;
3434
FastRandomContext insecure_rand_ctx(true);
3535

36-
extern std::map<std::string, std::string> mapArgs;
37-
3836
extern bool fPrintToConsole;
3937
extern void noui_connect();
4038

@@ -66,7 +64,7 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
6664
ClearDatadirCache();
6765
pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000)));
6866
boost::filesystem::create_directories(pathTemp);
69-
mapArgs["-datadir"] = pathTemp.string();
67+
ForceSetArg("-datadir", pathTemp.string());
7068
mempool.setSanityCheck(1.0);
7169
pblocktree = new CBlockTreeDB(1 << 20, true);
7270
pcoinsdbview = new CCoinsViewDB(1 << 23, true);

src/util.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,14 @@ bool SoftSetBoolArg(const std::string& strArg, bool fValue)
428428
return SoftSetArg(strArg, std::string("0"));
429429
}
430430

431+
void ForceSetArg(const std::string& strArg, const std::string& strValue)
432+
{
433+
LOCK(cs_args);
434+
mapArgs[strArg] = strValue;
435+
}
436+
437+
438+
431439
static const int screenWidth = 79;
432440
static const int optIndent = 2;
433441
static const int msgIndent = 7;

src/util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ bool SoftSetArg(const std::string& strArg, const std::string& strValue);
175175
*/
176176
bool SoftSetBoolArg(const std::string& strArg, bool fValue);
177177

178+
// Forces a arg setting, used only in testing
179+
void ForceSetArg(const std::string& strArg, const std::string& strValue);
180+
178181
/**
179182
* Format a string to be used as group of options in help messages
180183
*

0 commit comments

Comments
 (0)