git / moonbite-core / src/test/validation_tests.cpp · raw
// Copyright (c) 2014-2019 The Bitcoin Core developers// Distributed under the MIT software license, see the accompanying// file COPYING or http://www.opensource.org/licenses/mit-license.php.#include <chainparams.h>#include <net.h>#include <signet.h>#include <validation.h>#include <test/util/setup_common.h>#include <boost/test/unit_test.hpp>BOOST_FIXTURE_TEST_SUITE(validation_tests, TestingSetup)static void TestBlockSubsidyHalvings(const Consensus::Params& consensusParams){ int maxHalvings = 64; CAmount nInitialSubsidy = 10 * COIN; // MoonBite (ADR-002 rev): 10 MBITE per 2-minute block 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; 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);}static void TestBlockSubsidyHalvings(int nSubsidyHalvingInterval){ Consensus::Params consensusParams; consensusParams.nSubsidyHalvingInterval = nSubsidyHalvingInterval; TestBlockSubsidyHalvings(consensusParams);}BOOST_AUTO_TEST_CASE(block_subsidy_test){ const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN); TestBlockSubsidyHalvings(chainParams->GetConsensus()); // As in main TestBlockSubsidyHalvings(150); // As in regtest TestBlockSubsidyHalvings(1000); // Just another interval}BOOST_AUTO_TEST_CASE(subsidy_limit_test){ const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN); CAmount nSum = 0; for (int nHeight = 0; nHeight < 56000000; nHeight += 1000) { CAmount nSubsidy = GetBlockSubsidy(nHeight, chainParams->GetConsensus()); BOOST_CHECK(nSubsidy <= 10 * COIN); nSum += nSubsidy * 1000; BOOST_CHECK(MoneyRange(nSum)); } // MoonBite (ADR-002 rev): 10 MBITE halving every 1,650,000 blocks sums to // 32,999,999.7855 MBITE — just under the 33,000,000 MAX_MONEY bound. BOOST_CHECK_EQUAL(nSum, CAmount{3299999978550000});}// MoonBite takes no protocol revenue. This test pins that: on every real// network the treasury slice must be exactly zero at every height, so 100% of// the subsidy reaches the miner. It also pins the guards themselves, so a// future change cannot quietly re-enable a dev tail without failing here.BOOST_AUTO_TEST_CASE(no_treasury_test){ for (const auto& net : {CBaseChainParams::MAIN, CBaseChainParams::TESTNET, CBaseChainParams::REGTEST}) { const auto chain = CreateChainParams(*m_node.args, net); const Consensus::Params& p = chain->GetConsensus(); // Parameters are zeroed, not merely unused. BOOST_CHECK_EQUAL(p.nTreasuryRateBps, 0); BOOST_CHECK(p.treasuryScript.empty()); // And the derived amount is zero everywhere it could possibly apply. for (int h : {0, 1, 100, 1649999, 1650000, 3300000, 5000000}) { BOOST_CHECK_EQUAL(GetTreasuryAmount(h, p), CAmount{0}); // The miner therefore receives the entire subsidy. BOOST_CHECK_EQUAL(GetBlockSubsidy(h, p) - GetTreasuryAmount(h, p), GetBlockSubsidy(h, p)); } }}// The guard logic still has to behave if a rate is ever supplied, so exercise// it with explicit local params rather than deleting the coverage entirely.BOOST_AUTO_TEST_CASE(treasury_guards_test){ Consensus::Params params; params.nSubsidyHalvingInterval = 1650000; params.nTreasuryRateBps = 500; params.nTreasurySunsetHeight = 3300000; // An empty script disables the slice even when a rate is set - this is what // keeps a misconfiguration from paying coins to nowhere. params.treasuryScript.clear(); BOOST_CHECK_EQUAL(GetTreasuryAmount(1, params), CAmount{0}); // With a script present the split is exact, and conserves the subsidy. params.treasuryScript = {0x00, 0x14}; const CAmount sub = GetBlockSubsidy(1, params); const CAmount tre = GetTreasuryAmount(1, params); BOOST_CHECK_EQUAL(sub, 10 * COIN); BOOST_CHECK_EQUAL(tre, sub * 500 / 10000); BOOST_CHECK_EQUAL(tre + (sub - tre), sub); // Genesis pays nothing, and the sunset is hard. BOOST_CHECK_EQUAL(GetTreasuryAmount(0, params), CAmount{0}); BOOST_CHECK_EQUAL(GetTreasuryAmount(3300000, params), CAmount{0}); BOOST_CHECK_EQUAL(GetTreasuryAmount(3300001, params), CAmount{0});}BOOST_AUTO_TEST_SUITE_END()