mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 02:25:40 +01:00
test: some sanity checks for consensus logic
This commit is contained in:
parent
e47ad375bf
commit
8258c4c007
@ -135,4 +135,51 @@ BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
|
||||
}
|
||||
}
|
||||
|
||||
void sanity_check_chainparams(std::string chainName)
|
||||
{
|
||||
const auto chainParams = CreateChainParams(chainName);
|
||||
const auto consensus = chainParams->GetConsensus();
|
||||
|
||||
// hash genesis is correct
|
||||
BOOST_CHECK_EQUAL(consensus.hashGenesisBlock, chainParams->GenesisBlock().GetHash());
|
||||
|
||||
// target timespan is an even multiple of spacing
|
||||
BOOST_CHECK_EQUAL(consensus.nPowTargetTimespan % consensus.nPowTargetSpacing, 0);
|
||||
|
||||
// genesis nBits is positive, doesn't overflow and is lower than powLimit
|
||||
arith_uint256 pow_compact;
|
||||
bool neg, over;
|
||||
pow_compact.SetCompact(chainParams->GenesisBlock().nBits, &neg, &over);
|
||||
BOOST_CHECK(!neg && pow_compact != 0);
|
||||
BOOST_CHECK(!over);
|
||||
BOOST_CHECK(UintToArith256(consensus.powLimit) >= pow_compact);
|
||||
|
||||
// check max target * 4*nPowTargetTimespan doesn't overflow -- see pow.cpp:CalculateNextWorkRequired()
|
||||
if (!consensus.fPowNoRetargeting) {
|
||||
arith_uint256 targ_max("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
|
||||
targ_max /= consensus.nPowTargetTimespan*4;
|
||||
BOOST_CHECK(UintToArith256(consensus.powLimit) < targ_max);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ChainParams_MAIN_sanity)
|
||||
{
|
||||
sanity_check_chainparams(CBaseChainParams::MAIN);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ChainParams_REGTEST_sanity)
|
||||
{
|
||||
sanity_check_chainparams(CBaseChainParams::REGTEST);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ChainParams_TESTNET_sanity)
|
||||
{
|
||||
sanity_check_chainparams(CBaseChainParams::TESTNET);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(ChainParams_SIGNET_sanity)
|
||||
{
|
||||
sanity_check_chainparams(CBaseChainParams::SIGNET);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
Loading…
Reference in New Issue
Block a user