Changeset View
Changeset View
Standalone View
Standalone View
src/test/policy_block_tests.cpp
Show All 40 Lines | const auto minerFund = DecodeDestination( | ||||
"ecash:prfhcnyqnl5cgrnmlfmms675w93ld7mvvqd0y8lz07", chainparams); | "ecash:prfhcnyqnl5cgrnmlfmms675w93ld7mvvqd0y8lz07", chainparams); | ||||
return Block(minerFundAmount, GetScriptForDestination(minerFund)); | return Block(minerFundAmount, GetScriptForDestination(minerFund)); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(policy_minerfund) { | BOOST_AUTO_TEST_CASE(policy_minerfund) { | ||||
const CChainParams &chainparams = Params(); | const CChainParams &chainparams = Params(); | ||||
const Consensus::Params &consensusParams = chainparams.GetConsensus(); | const Consensus::Params &consensusParams = chainparams.GetConsensus(); | ||||
std::array<BlockHash, 12> blockhashes; | |||||
std::array<CBlockIndex, 12> blocks; | std::array<CBlockIndex, 12> blocks; | ||||
for (size_t i = 1; i < blocks.size(); ++i) { | for (size_t i = 1; i < blocks.size(); ++i) { | ||||
blockhashes[i] = BlockHash(uint256(i)); | |||||
blocks[i].phashBlock = &blockhashes[i]; | |||||
blocks[i].pprev = &blocks[i - 1]; | blocks[i].pprev = &blocks[i - 1]; | ||||
blocks[i].nHeight = consensusParams.gluonHeight + i; | blocks[i].nHeight = consensusParams.gluonHeight + i; | ||||
} | } | ||||
CBlockIndex &lastBlockIndexRef = blocks.back(); | CBlockIndex &lastBlockIndexRef = blocks.back(); | ||||
const Amount blockReward = | const Amount blockReward = | ||||
GetBlockSubsidy(lastBlockIndexRef.nHeight, consensusParams); | GetBlockSubsidy(lastBlockIndexRef.nHeight, consensusParams); | ||||
const Amount minerFund = GetMinerFundAmount(blockReward); | const Amount minerFund = GetMinerFundAmount(blockReward); | ||||
const auto wellingtonActivation = gArgs.GetIntArg( | const auto wellingtonActivation = gArgs.GetIntArg( | ||||
"-wellingtonactivationtime", consensusParams.wellingtonActivationTime); | "-wellingtonactivationtime", consensusParams.wellingtonActivationTime); | ||||
auto checkEarlyBlocks = [&]() { | auto checkEarlyBlocks = [&]() { | ||||
// Check genesis block (pprev is nullptr) and early blocks before | // Check genesis block (pprev is nullptr) and early blocks before | ||||
// Wellington rules are enforced. We skip the last block index | // Wellington rules are enforced. We skip the last block index | ||||
// because we explicitly test activation cases with it. | // because we explicitly test activation cases with it. | ||||
BOOST_CHECK(!blocks[0].pprev); | BOOST_CHECK(!blocks[0].pprev); | ||||
for (size_t i = 0; i < blocks.size() - 2; i++) { | for (size_t i = 0; i < blocks.size() - 2; i++) { | ||||
const CBlockIndex &blockIndex = blocks[i]; | const CBlockIndex &blockIndex = blocks[i]; | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
!IsWellingtonEnabled(consensusParams, blockIndex.pprev)); | !IsWellingtonEnabled(consensusParams, blockIndex.pprev)); | ||||
CBlock block = BlockWithoutMinerFund(blockReward); | CBlock block = BlockWithoutMinerFund(blockReward); | ||||
MinerFundPolicy check(consensusParams, blockIndex, block, | MinerFundPolicy check(consensusParams, blockIndex, block, | ||||
blockReward); | blockReward); | ||||
BOOST_CHECK(check()); | |||||
BlockPolicyValidationState state; | |||||
BOOST_CHECK(check(state)); | |||||
BOOST_CHECK(state.IsValid()); | |||||
} | } | ||||
}; | }; | ||||
auto checkMinerFundPolicy = [&](CBlock block, bool expected) { | auto checkMinerFundPolicy = [&](CBlock block, bool expected) { | ||||
BlockPolicyValidationState state; | |||||
BOOST_CHECK_EQUAL(MinerFundPolicy(consensusParams, lastBlockIndexRef, | BOOST_CHECK_EQUAL(MinerFundPolicy(consensusParams, lastBlockIndexRef, | ||||
block, blockReward)(), | block, blockReward)(state), | ||||
expected); | expected); | ||||
BOOST_CHECK_EQUAL(state.IsValid(), expected); | |||||
if (!expected) { | |||||
BOOST_CHECK_EQUAL(state.GetRejectReason(), "policy-bad-miner-fund"); | |||||
} | |||||
}; | }; | ||||
const std::vector<Amount> minerFundsTooSmall = {1 * SATOSHI, minerFund / 2, | const std::vector<Amount> minerFundsTooSmall = {1 * SATOSHI, minerFund / 2, | ||||
minerFund - 1 * SATOSHI}; | minerFund - 1 * SATOSHI}; | ||||
const std::vector<Amount> minerFundsSufficient = { | const std::vector<Amount> minerFundsSufficient = { | ||||
minerFund, minerFund + 1 * SATOSHI, blockReward}; | minerFund, minerFund + 1 * SATOSHI, blockReward}; | ||||
// Miner fund policy always passes prior to Wellington rules enforcement. | // Miner fund policy always passes prior to Wellington rules enforcement. | ||||
Show All 34 Lines |