aboutsummaryrefslogtreecommitdiff
path: root/src/test/dogecoin_tests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/dogecoin_tests.cpp')
-rw-r--r--src/test/dogecoin_tests.cpp70
1 files changed, 45 insertions, 25 deletions
diff --git a/src/test/dogecoin_tests.cpp b/src/test/dogecoin_tests.cpp
index 2932824d3..0322f2584 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);
@@ -78,7 +98,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_difficulty_limit)
pindexLast.nHeight = 239;
pindexLast.nTime = 1386475638; // Block #239
pindexLast.nBits = 0x1e0ffff0;
- BOOST_CHECK_EQUAL(CalculateDogecoinNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1e00ffff);
+ BOOST_CHECK_EQUAL(CalculateDogecoinNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1e00ffffU);
}
BOOST_AUTO_TEST_CASE(get_next_work_pre_digishield)
@@ -92,7 +112,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_pre_digishield)
pindexLast.nHeight = 9599;
pindexLast.nTime = 1386954113;
pindexLast.nBits = 0x1c1a1206;
- BOOST_CHECK_EQUAL(CalculateDogecoinNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1c15ea59);
+ BOOST_CHECK_EQUAL(CalculateDogecoinNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1c15ea59U);
}
BOOST_AUTO_TEST_CASE(get_next_work_digishield)
@@ -107,7 +127,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_digishield)
pindexLast.nHeight = 145000;
pindexLast.nTime = 1395094679;
pindexLast.nBits = 0x1b499dfd;
- BOOST_CHECK_EQUAL(CalculateDogecoinNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1b671062);
+ BOOST_CHECK_EQUAL(CalculateDogecoinNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1b671062U);
}
BOOST_AUTO_TEST_CASE(get_next_work_digishield_modulated_upper)
@@ -122,7 +142,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_digishield_modulated_upper)
pindexLast.nHeight = 145107;
pindexLast.nTime = 1395101360;
pindexLast.nBits = 0x1b3439cd;
- BOOST_CHECK_EQUAL(CalculateDogecoinNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1b4e56b3);
+ BOOST_CHECK_EQUAL(CalculateDogecoinNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1b4e56b3U);
}
BOOST_AUTO_TEST_CASE(get_next_work_digishield_modulated_lower)
@@ -137,7 +157,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_digishield_modulated_lower)
pindexLast.nHeight = 149423;
pindexLast.nTime = 1395380447;
pindexLast.nBits = 0x1b446f21;
- BOOST_CHECK_EQUAL(CalculateDogecoinNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1b335358);
+ BOOST_CHECK_EQUAL(CalculateDogecoinNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1b335358U);
}
BOOST_AUTO_TEST_CASE(get_next_work_digishield_rounding)
@@ -153,7 +173,7 @@ BOOST_AUTO_TEST_CASE(get_next_work_digishield_rounding)
pindexLast.nHeight = 145001;
pindexLast.nTime = 1395094727;
pindexLast.nBits = 0x1b671062;
- BOOST_CHECK_EQUAL(CalculateDogecoinNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1b6558a4);
+ BOOST_CHECK_EQUAL(CalculateDogecoinNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1b6558a4U);
}
BOOST_AUTO_TEST_SUITE_END()