Browse Source

Add a ForceSetArg method for testing

0.14
Matt Corallo 8 years ago
parent
commit
c2f61bebb1
  1. 4
      src/qt/test/rpcnestedtests.cpp
  2. 6
      src/test/DoS_tests.cpp
  3. 4
      src/test/test_bitcoin.cpp
  4. 8
      src/util.cpp
  5. 3
      src/util.h

4
src/qt/test/rpcnestedtests.cpp

@ -19,8 +19,6 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
extern std::map<std::string, std::string> mapArgs;
static UniValue rpcNestedTest_rpc(const JSONRPCRequest& request) static UniValue rpcNestedTest_rpc(const JSONRPCRequest& request)
{ {
if (request.fHelp) { if (request.fHelp) {
@ -47,7 +45,7 @@ void RPCNestedTests::rpcNestedTests()
std::string path = QDir::tempPath().toStdString() + "/" + strprintf("test_bitcoin_qt_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000))); std::string path = QDir::tempPath().toStdString() + "/" + strprintf("test_bitcoin_qt_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000)));
QDir dir(QString::fromStdString(path)); QDir dir(QString::fromStdString(path));
dir.mkpath("."); dir.mkpath(".");
mapArgs["-datadir"] = path; ForceSetArg("-datadir", path);
//mempool.setSanityCheck(1.0); //mempool.setSanityCheck(1.0);
pblocktree = new CBlockTreeDB(1 << 20, true); pblocktree = new CBlockTreeDB(1 << 20, true);
pcoinsdbview = new CCoinsViewDB(1 << 23, true); pcoinsdbview = new CCoinsViewDB(1 << 23, true);

6
src/test/DoS_tests.cpp

@ -12,6 +12,7 @@
#include "script/sign.h" #include "script/sign.h"
#include "serialize.h" #include "serialize.h"
#include "util.h" #include "util.h"
#include "validation.h"
#include "test/test_bitcoin.h" #include "test/test_bitcoin.h"
@ -32,7 +33,6 @@ struct COrphanTx {
int64_t nTimeExpire; int64_t nTimeExpire;
}; };
extern std::map<uint256, COrphanTx> mapOrphanTransactions; extern std::map<uint256, COrphanTx> mapOrphanTransactions;
extern std::map<std::string, std::string> mapArgs;
CService ip(uint32_t i) CService ip(uint32_t i)
{ {
@ -75,7 +75,7 @@ BOOST_AUTO_TEST_CASE(DoS_banning)
BOOST_AUTO_TEST_CASE(DoS_banscore) BOOST_AUTO_TEST_CASE(DoS_banscore)
{ {
connman->ClearBanned(); connman->ClearBanned();
mapArgs["-banscore"] = "111"; // because 11 is my favorite number ForceSetArg("-banscore", "111"); // because 11 is my favorite number
CAddress addr1(ip(0xa0b0c001), NODE_NONE); CAddress addr1(ip(0xa0b0c001), NODE_NONE);
CNode dummyNode1(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr1, 3, 1, "", true); CNode dummyNode1(id++, NODE_NETWORK, 0, INVALID_SOCKET, addr1, 3, 1, "", true);
dummyNode1.SetSendVersion(PROTOCOL_VERSION); dummyNode1.SetSendVersion(PROTOCOL_VERSION);
@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE(DoS_banscore)
Misbehaving(dummyNode1.GetId(), 1); Misbehaving(dummyNode1.GetId(), 1);
SendMessages(&dummyNode1, *connman); SendMessages(&dummyNode1, *connman);
BOOST_CHECK(connman->IsBanned(addr1)); BOOST_CHECK(connman->IsBanned(addr1));
mapArgs.erase("-banscore"); ForceSetArg("-banscore", std::to_string(DEFAULT_BANSCORE_THRESHOLD));
} }
BOOST_AUTO_TEST_CASE(DoS_bantime) BOOST_AUTO_TEST_CASE(DoS_bantime)

4
src/test/test_bitcoin.cpp

@ -33,8 +33,6 @@
std::unique_ptr<CConnman> g_connman; std::unique_ptr<CConnman> g_connman;
FastRandomContext insecure_rand_ctx(true); FastRandomContext insecure_rand_ctx(true);
extern std::map<std::string, std::string> mapArgs;
extern bool fPrintToConsole; extern bool fPrintToConsole;
extern void noui_connect(); extern void noui_connect();
@ -66,7 +64,7 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
ClearDatadirCache(); ClearDatadirCache();
pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000))); pathTemp = GetTempPath() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(GetRand(100000)));
boost::filesystem::create_directories(pathTemp); boost::filesystem::create_directories(pathTemp);
mapArgs["-datadir"] = pathTemp.string(); ForceSetArg("-datadir", pathTemp.string());
mempool.setSanityCheck(1.0); mempool.setSanityCheck(1.0);
pblocktree = new CBlockTreeDB(1 << 20, true); pblocktree = new CBlockTreeDB(1 << 20, true);
pcoinsdbview = new CCoinsViewDB(1 << 23, true); pcoinsdbview = new CCoinsViewDB(1 << 23, true);

8
src/util.cpp

@ -428,6 +428,14 @@ bool SoftSetBoolArg(const std::string& strArg, bool fValue)
return SoftSetArg(strArg, std::string("0")); return SoftSetArg(strArg, std::string("0"));
} }
void ForceSetArg(const std::string& strArg, const std::string& strValue)
{
LOCK(cs_args);
mapArgs[strArg] = strValue;
}
static const int screenWidth = 79; static const int screenWidth = 79;
static const int optIndent = 2; static const int optIndent = 2;
static const int msgIndent = 7; static const int msgIndent = 7;

3
src/util.h

@ -175,6 +175,9 @@ bool SoftSetArg(const std::string& strArg, const std::string& strValue);
*/ */
bool SoftSetBoolArg(const std::string& strArg, bool fValue); bool SoftSetBoolArg(const std::string& strArg, bool fValue);
// Forces a arg setting, used only in testing
void ForceSetArg(const std::string& strArg, const std::string& strValue);
/** /**
* Format a string to be used as group of options in help messages * Format a string to be used as group of options in help messages
* *

Loading…
Cancel
Save