diff options
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/blockfilter_index_tests.cpp | 8 | ||||
| -rw-r--r-- | src/test/dogecoin_tests.cpp | 55 | ||||
| -rw-r--r-- | src/test/validation_block_tests.cpp | 5 | ||||
| -rw-r--r-- | src/test/validation_tests.cpp | 4 |
4 files changed, 69 insertions, 3 deletions
diff --git a/src/test/blockfilter_index_tests.cpp b/src/test/blockfilter_index_tests.cpp index 2b893d018..753c1bb5f 100644 --- a/src/test/blockfilter_index_tests.cpp +++ b/src/test/blockfilter_index_tests.cpp @@ -67,8 +67,14 @@ CBlock BuildChainTestingSetup::CreateBlock(const CBlockIndex* prev, block.hashPrevBlock = prev->GetBlockHash(); block.nTime = prev->nTime + 1; + // Dogecoin: Fix rewards at a low value we know is always acceptable, rather than use pseudo-random rewards. + CMutableTransaction txCoinbase(*block.vtx[0]); + txCoinbase.vout[0].nValue = 10000 * COIN; + // Replace mempool-selected txns with just coinbase plus passed-in txns: - block.vtx.resize(1); + block.vtx.clear(); + block.vtx.push_back(MakeTransactionRef(txCoinbase)); + for (const CMutableTransaction& tx : txns) { block.vtx.push_back(MakeTransactionRef(tx)); } diff --git a/src/test/dogecoin_tests.cpp b/src/test/dogecoin_tests.cpp index b446ff685..2932824d3 100644 --- a/src/test/dogecoin_tests.cpp +++ b/src/test/dogecoin_tests.cpp @@ -12,6 +12,61 @@ BOOST_FIXTURE_TEST_SUITE(dogecoin_tests, TestingSetup) +BOOST_AUTO_TEST_CASE(subsidy_test) +{ + const int nHeight = 36; + const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN); + const auto params = chainParams->GetConsensus(); + uint256 prevHash = uint256S("0x4eb7c3f5914a84a25ea0ae12c39d1e5390a8ea576490035b63dcd03fcc14d106"); // Block 35 + + CAmount nSubsidy = GetDogecoinBlockSubsidy(nHeight, params, prevHash); + BOOST_CHECK_EQUAL(nSubsidy, 228450 * COIN); +} + +BOOST_AUTO_TEST_CASE(subsidy_limit_test) +{ + 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"); + + for (nHeight = 0; nHeight <= 100000; nHeight++) { + CAmount nSubsidy = GetDogecoinBlockSubsidy(nHeight, params, prevHash); + BOOST_CHECK(MoneyRange(nSubsidy)); + BOOST_CHECK(nSubsidy <= 1000000 * COIN); + nSum += nSubsidy * nStepSize; + } + for (; nHeight <= 145000; nHeight++) { + CAmount nSubsidy = GetDogecoinBlockSubsidy(nHeight, params, prevHash); + BOOST_CHECK(MoneyRange(nSubsidy)); + BOOST_CHECK(nSubsidy <= 500000 * COIN); + nSum += nSubsidy * nStepSize; + } + for (; 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; + } + + //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); + + nConstantSubsidy = GetDogecoinBlockSubsidy(700000, params, prevHash); + BOOST_CHECK_EQUAL(nConstantSubsidy, 10000 * COIN); +} + BOOST_AUTO_TEST_CASE(get_next_work_difficulty_limit) { SelectParams(CBaseChainParams::MAIN); diff --git a/src/test/validation_block_tests.cpp b/src/test/validation_block_tests.cpp index ea17cb50f..a32b25899 100644 --- a/src/test/validation_block_tests.cpp +++ b/src/test/validation_block_tests.cpp @@ -85,7 +85,10 @@ std::shared_ptr<CBlock> MinerTestingSetup::Block(const uint256& prev_hash) CMutableTransaction txCoinbase(*pblock->vtx[0]); txCoinbase.vout.resize(2); txCoinbase.vout[1].scriptPubKey = pubKey; - txCoinbase.vout[1].nValue = txCoinbase.vout[0].nValue; + // Dogecoin: Override the calculated reward with a fixed value we know is going to be safe for every block. + // We need this as the blocks are not added to the chain as they're built, and as such the random subsidy + // calculation uses an incorrect previous block hash. + txCoinbase.vout[1].nValue = 10000 * COIN; txCoinbase.vout[0].nValue = 0; txCoinbase.vin[0].scriptWitness.SetNull(); pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase)); diff --git a/src/test/validation_tests.cpp b/src/test/validation_tests.cpp index c3816af0c..f32c7d1db 100644 --- a/src/test/validation_tests.cpp +++ b/src/test/validation_tests.cpp @@ -55,7 +55,9 @@ BOOST_AUTO_TEST_CASE(subsidy_limit_test) nSum += nSubsidy * 1000; BOOST_CHECK(MoneyRange(nSum)); } - BOOST_CHECK_EQUAL(nSum, CAmount{2099999997690000}); + // Dogecoin: Supply is uncapped, so the test doesn't apply in the same way. + // Instead we update this to the potential maximum at block 14000000 as nearest equivalent. + BOOST_CHECK_EQUAL(nSum, CAmount{999999998900000}); } BOOST_AUTO_TEST_CASE(signet_parse_tests) |