From ac6f78e411b243e292718bc88c604d2152dd043b Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Wed, 16 Jun 2021 09:13:14 +0100 Subject: [PATCH] Rewrite subsidy limit tests --- src/test/dogecoin_tests.cpp | 58 +++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/src/test/dogecoin_tests.cpp b/src/test/dogecoin_tests.cpp index 2932824d3..57f496e5e 100644 --- a/src/test/dogecoin_tests.cpp +++ b/src/test/dogecoin_tests.cpp @@ -23,42 +23,62 @@ BOOST_AUTO_TEST_CASE(subsidy_test) BOOST_CHECK_EQUAL(nSubsidy, 228450 * COIN); } -BOOST_AUTO_TEST_CASE(subsidy_limit_test) +BOOST_AUTO_TEST_CASE(subsidy_limit_test_first_100k) { - int nHeight = 0; - int nStepSize= 1; const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN); const auto params = chainParams->GetConsensus(); CAmount nSum = 0; - uint256 prevHash = uint256S("0"); + arith_uint256 prevHash = UintToArith256(uint256S("0")); - for (nHeight = 0; nHeight <= 100000; nHeight++) { - CAmount nSubsidy = GetDogecoinBlockSubsidy(nHeight, params, prevHash); + for (int nHeight = 0; nHeight <= 100000; nHeight++) { + CAmount nSubsidy = GetDogecoinBlockSubsidy(nHeight, params, ArithToUint256(prevHash)); BOOST_CHECK(MoneyRange(nSubsidy)); BOOST_CHECK(nSubsidy <= 1000000 * COIN); - nSum += nSubsidy * nStepSize; + nSum += nSubsidy; + // Use nSubsidy to give us some variation in previous block hash, without requiring full block templates + prevHash += nSubsidy; } - for (; nHeight <= 145000; nHeight++) { - CAmount nSubsidy = GetDogecoinBlockSubsidy(nHeight, params, prevHash); + + const CAmount expected = 54894174438 * COIN; + BOOST_CHECK_EQUAL(expected, nSum); +} + +BOOST_AUTO_TEST_CASE(subsidy_limit_test_100k_145k) +{ + const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN); + const auto params = chainParams->GetConsensus(); + CAmount nSum = 0; + arith_uint256 prevHash = UintToArith256(uint256S("0")); + + for (int nHeight = 100000; nHeight <= 145000; nHeight++) { + CAmount nSubsidy = GetDogecoinBlockSubsidy(nHeight, params, ArithToUint256(prevHash)); BOOST_CHECK(MoneyRange(nSubsidy)); BOOST_CHECK(nSubsidy <= 500000 * COIN); - nSum += nSubsidy * nStepSize; + nSum += nSubsidy; + // Use nSubsidy to give us some variation in previous block hash, without requiring full block templates + prevHash += nSubsidy; } - for (; nHeight < 600000; nHeight++) { + + const CAmount expected = 12349960000 * COIN; + BOOST_CHECK_EQUAL(expected, nSum); +} + +// Check the simplified rewards after block 145,000 +BOOST_AUTO_TEST_CASE(subsidy_limit_test_post_145k) +{ + const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN); + const auto params = chainParams->GetConsensus(); + CAmount nSum = 0; + const uint256 prevHash = uint256S("0"); + + for (int nHeight = 145000; nHeight < 600000; nHeight++) { CAmount nSubsidy = GetDogecoinBlockSubsidy(nHeight, params, prevHash); CAmount nExpectedSubsidy = (500000 >> (nHeight / 100000)) * COIN; BOOST_CHECK(MoneyRange(nSubsidy)); BOOST_CHECK_EQUAL(nSubsidy, nExpectedSubsidy); - nSum += nSubsidy * nStepSize; + nSum += nSubsidy; } - //test sum +- ~10billion - arith_uint256 upperlimit = arith_uint256("95e14ec776380000"); //108 billion doge - BOOST_CHECK(nSum <= upperlimit); - - arith_uint256 lowerlimit = arith_uint256("7a1fe16027700000"); //88 billion doge - BOOST_CHECK(nSum >= lowerlimit); - // Test reward at 600k+ is constant CAmount nConstantSubsidy = GetDogecoinBlockSubsidy(600000, params, prevHash); BOOST_CHECK_EQUAL(nConstantSubsidy, 10000 * COIN);