Browse Source

test: Remove UNITTEST params

UNITTEST parameter are not used by any current tests, and the model
(modifyable parameters) is inconvenient when unit-testing. As
they are stored in a global structure eevery test
would have to (re)set up its own parameters.

For consistency it is also better to test with MAIN parameters.
0.13
Wladimir J. van der Laan 10 years ago
parent
commit
59bd89f116
  1. 45
      src/chainparams.cpp
  2. 22
      src/chainparams.h
  3. 3
      src/chainparamsbase.cpp
  4. 1
      src/chainparamsbase.h
  5. 4
      src/test/base58_tests.cpp
  6. 2
      src/test/test_bitcoin.cpp

45
src/chainparams.cpp

@ -281,51 +281,8 @@ public:
}; };
static CRegTestParams regTestParams; static CRegTestParams regTestParams;
/**
* Unit test
*/
class CUnitTestParams : public CMainParams, public CModifiableParams {
public:
CUnitTestParams() {
strNetworkID = "unittest";
nDefaultPort = 18445;
vFixedSeeds.clear(); //! Unit test mode doesn't have any fixed seeds.
vSeeds.clear(); //! Unit test mode doesn't have any DNS seeds.
fRequireRPCPassword = false;
fMiningRequiresPeers = false;
fDefaultCheckMemPool = true;
fAllowMinDifficultyBlocks = false;
fMineBlocksOnDemand = true;
}
const Checkpoints::CCheckpointData& Checkpoints() const
{
// UnitTest share the same checkpoints as MAIN
return data;
}
//! Published setters to allow changing values in unit test cases
virtual void setSubsidyHalvingInterval(int anSubsidyHalvingInterval) { nSubsidyHalvingInterval=anSubsidyHalvingInterval; }
virtual void setEnforceBlockUpgradeMajority(int anEnforceBlockUpgradeMajority) { nEnforceBlockUpgradeMajority=anEnforceBlockUpgradeMajority; }
virtual void setRejectBlockOutdatedMajority(int anRejectBlockOutdatedMajority) { nRejectBlockOutdatedMajority=anRejectBlockOutdatedMajority; }
virtual void setToCheckBlockUpgradeMajority(int anToCheckBlockUpgradeMajority) { nToCheckBlockUpgradeMajority=anToCheckBlockUpgradeMajority; }
virtual void setDefaultCheckMemPool(bool afDefaultCheckMemPool) { fDefaultCheckMemPool=afDefaultCheckMemPool; }
virtual void setAllowMinDifficultyBlocks(bool afAllowMinDifficultyBlocks) { fAllowMinDifficultyBlocks=afAllowMinDifficultyBlocks; }
virtual void setSkipProofOfWorkCheck(bool afSkipProofOfWorkCheck) { fSkipProofOfWorkCheck = afSkipProofOfWorkCheck; }
};
static CUnitTestParams unitTestParams;
static CChainParams *pCurrentParams = 0; static CChainParams *pCurrentParams = 0;
CModifiableParams *ModifiableParams()
{
assert(pCurrentParams);
assert(pCurrentParams==&unitTestParams);
return (CModifiableParams*)&unitTestParams;
}
const CChainParams &Params() { const CChainParams &Params() {
assert(pCurrentParams); assert(pCurrentParams);
return *pCurrentParams; return *pCurrentParams;
@ -339,8 +296,6 @@ CChainParams &Params(CBaseChainParams::Network network) {
return testNetParams; return testNetParams;
case CBaseChainParams::REGTEST: case CBaseChainParams::REGTEST:
return regTestParams; return regTestParams;
case CBaseChainParams::UNITTEST:
return unitTestParams;
default: default:
assert(false && "Unimplemented network"); assert(false && "Unimplemented network");
return mainParams; return mainParams;

22
src/chainparams.h

@ -108,25 +108,6 @@ protected:
bool fTestnetToBeDeprecatedFieldRPC; bool fTestnetToBeDeprecatedFieldRPC;
}; };
/**
* Modifiable parameters interface is used by test cases to adapt the parameters in order
* to test specific features more easily. Test cases should always restore the previous
* values after finalization.
*/
class CModifiableParams {
public:
//! Published setters to allow changing values in unit test cases
virtual void setSubsidyHalvingInterval(int anSubsidyHalvingInterval) =0;
virtual void setEnforceBlockUpgradeMajority(int anEnforceBlockUpgradeMajority)=0;
virtual void setRejectBlockOutdatedMajority(int anRejectBlockOutdatedMajority)=0;
virtual void setToCheckBlockUpgradeMajority(int anToCheckBlockUpgradeMajority)=0;
virtual void setDefaultCheckMemPool(bool aDefaultCheckMemPool)=0;
virtual void setAllowMinDifficultyBlocks(bool aAllowMinDifficultyBlocks)=0;
virtual void setSkipProofOfWorkCheck(bool aSkipProofOfWorkCheck)=0;
};
/** /**
* Return the currently selected parameters. This won't change after app startup * Return the currently selected parameters. This won't change after app startup
* outside of the unit tests. * outside of the unit tests.
@ -136,9 +117,6 @@ const CChainParams &Params();
/** Return parameters for the given network. */ /** Return parameters for the given network. */
CChainParams &Params(CBaseChainParams::Network network); CChainParams &Params(CBaseChainParams::Network network);
/** Get modifiable network parameters (UNITTEST only) */
CModifiableParams *ModifiableParams();
/** Sets the params returned by Params() to those for the given network. */ /** Sets the params returned by Params() to those for the given network. */
void SelectParams(CBaseChainParams::Network network); void SelectParams(CBaseChainParams::Network network);

3
src/chainparamsbase.cpp

@ -82,9 +82,6 @@ void SelectBaseParams(CBaseChainParams::Network network)
case CBaseChainParams::REGTEST: case CBaseChainParams::REGTEST:
pCurrentBaseParams = &regTestParams; pCurrentBaseParams = &regTestParams;
break; break;
case CBaseChainParams::UNITTEST:
pCurrentBaseParams = &unitTestParams;
break;
default: default:
assert(false && "Unimplemented network"); assert(false && "Unimplemented network");
return; return;

1
src/chainparamsbase.h

@ -19,7 +19,6 @@ public:
MAIN, MAIN,
TESTNET, TESTNET,
REGTEST, REGTEST,
UNITTEST,
MAX_NETWORK_TYPES MAX_NETWORK_TYPES
}; };

4
src/test/base58_tests.cpp

@ -127,6 +127,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_parse)
std::vector<unsigned char> result; std::vector<unsigned char> result;
CBitcoinSecret secret; CBitcoinSecret secret;
CBitcoinAddress addr; CBitcoinAddress addr;
SelectParams(CBaseChainParams::MAIN);
BOOST_FOREACH(Value& tv, tests) BOOST_FOREACH(Value& tv, tests)
{ {
@ -176,7 +177,6 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_parse)
BOOST_CHECK_MESSAGE(!secret.IsValid(), "IsValid pubkey as privkey:" + strTest); BOOST_CHECK_MESSAGE(!secret.IsValid(), "IsValid pubkey as privkey:" + strTest);
} }
} }
SelectParams(CBaseChainParams::UNITTEST);
} }
// Goal: check that generated keys match test vectors // Goal: check that generated keys match test vectors
@ -244,7 +244,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_gen)
CTxDestination nodest = CNoDestination(); CTxDestination nodest = CNoDestination();
BOOST_CHECK(!dummyAddr.Set(nodest)); BOOST_CHECK(!dummyAddr.Set(nodest));
SelectParams(CBaseChainParams::UNITTEST); SelectParams(CBaseChainParams::MAIN);
} }
// Goal: check that base58 parsing code is robust against a variety of corrupted data // Goal: check that base58 parsing code is robust against a variety of corrupted data

2
src/test/test_bitcoin.cpp

@ -29,7 +29,7 @@ extern void noui_connect();
TestingSetup::TestingSetup() TestingSetup::TestingSetup()
{ {
fPrintToDebugLog = false; // don't want to write to debug.log file fPrintToDebugLog = false; // don't want to write to debug.log file
SelectParams(CBaseChainParams::UNITTEST); SelectParams(CBaseChainParams::MAIN);
noui_connect(); noui_connect();
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
bitdb.MakeMock(); bitdb.MakeMock();

Loading…
Cancel
Save