Browse Source

Update subsidy tests to account for mining slow start

pull/145/head
Jack Grigg 8 years ago
parent
commit
91818cf28c
  1. 34
      src/test/main_tests.cpp

34
src/test/main_tests.cpp

@ -20,18 +20,23 @@ static void TestBlockSubsidyHalvings(const Consensus::Params& consensusParams)
CAmount nPreviousSubsidy = nInitialSubsidy * 2; // for height == 0
BOOST_CHECK_EQUAL(nPreviousSubsidy, nInitialSubsidy * 2);
for (int nHalvings = 0; nHalvings < maxHalvings; nHalvings++) {
int nHeight = nHalvings * consensusParams.nSubsidyHalvingInterval;
int nHeight;
if (nHalvings > 0) // Check subsidy right at halvings
nHeight = nHalvings * consensusParams.nSubsidyHalvingInterval + consensusParams.SubsidySlowStartShift();
else // Check subsidy just after end of slow start
nHeight = consensusParams.nSubsidySlowStartInterval;
CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams);
BOOST_CHECK(nSubsidy <= nInitialSubsidy);
BOOST_CHECK_EQUAL(nSubsidy, nPreviousSubsidy / 2);
nPreviousSubsidy = nSubsidy;
}
BOOST_CHECK_EQUAL(GetBlockSubsidy(maxHalvings * consensusParams.nSubsidyHalvingInterval, consensusParams), 0);
BOOST_CHECK_EQUAL(GetBlockSubsidy((maxHalvings * consensusParams.nSubsidyHalvingInterval) + consensusParams.SubsidySlowStartShift(), consensusParams), 0);
}
static void TestBlockSubsidyHalvings(int nSubsidyHalvingInterval)
static void TestBlockSubsidyHalvings(int nSubsidySlowStartInterval, int nSubsidyHalvingInterval)
{
Consensus::Params consensusParams;
consensusParams.nSubsidySlowStartInterval = nSubsidySlowStartInterval;
consensusParams.nSubsidyHalvingInterval = nSubsidyHalvingInterval;
TestBlockSubsidyHalvings(consensusParams);
}
@ -39,15 +44,32 @@ static void TestBlockSubsidyHalvings(int nSubsidyHalvingInterval)
BOOST_AUTO_TEST_CASE(block_subsidy_test)
{
TestBlockSubsidyHalvings(Params(CBaseChainParams::MAIN).GetConsensus()); // As in main
TestBlockSubsidyHalvings(150); // As in regtest
TestBlockSubsidyHalvings(1000); // Just another interval
TestBlockSubsidyHalvings(50, 150); // As in regtest
TestBlockSubsidyHalvings(500, 1000); // Just another interval
}
BOOST_AUTO_TEST_CASE(subsidy_limit_test)
{
const Consensus::Params& consensusParams = Params(CBaseChainParams::MAIN).GetConsensus();
CAmount nSum = 0;
for (int nHeight = 0; nHeight < 14000000; nHeight += 1000) {
// Mining slow start
for (int nHeight = 0; nHeight < consensusParams.nSubsidySlowStartInterval; nHeight ++) {
CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams);
BOOST_CHECK(nSubsidy <= 50 * COIN);
nSum += nSubsidy;
BOOST_CHECK(MoneyRange(nSum));
}
BOOST_CHECK_EQUAL(nSum, 12500000000000ULL);
// Remainder of first period
for (int nHeight = consensusParams.nSubsidySlowStartInterval; nHeight < consensusParams.nSubsidyHalvingInterval + consensusParams.SubsidySlowStartShift(); nHeight ++) {
CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams);
BOOST_CHECK(nSubsidy <= 50 * COIN);
nSum += nSubsidy;
BOOST_CHECK(MoneyRange(nSum));
}
BOOST_CHECK_EQUAL(nSum, 1050000000000000ULL);
// Regular mining
for (int nHeight = consensusParams.nSubsidyHalvingInterval + consensusParams.SubsidySlowStartShift(); nHeight < 14000000; nHeight += 1000) {
CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams);
BOOST_CHECK(nSubsidy <= 50 * COIN);
nSum += nSubsidy * 1000;

Loading…
Cancel
Save