LCOV - code coverage report
Current view: top level - src/test - subsidy_tests.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 53 53 100.0 %
Date: 2026-06-25 07:23:43 Functions: 10 10 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2014-2023 The Dash Core developers
       2             : // Distributed under the MIT software license, see the accompanying
       3             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #include <chainparams.h>
       6             : #include <validation.h>
       7             : 
       8             : #include <test/util/setup_common.h>
       9             : 
      10             : #include <boost/test/unit_test.hpp>
      11             : 
      12         146 : BOOST_FIXTURE_TEST_SUITE(subsidy_tests, TestingSetup)
      13             : 
      14         149 : BOOST_AUTO_TEST_CASE(block_subsidy_test)
      15             : {
      16           1 :     const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
      17             : 
      18             :     uint32_t nPrevBits;
      19             :     int32_t nPrevHeight;
      20             :     CAmount nSubsidy;
      21             : 
      22             :     // details for block 4249 (subsidy returned will be for block 4250)
      23           1 :     nPrevBits = 0x1c4a47c4;
      24           1 :     nPrevHeight = 4249;
      25           1 :     nSubsidy = GetBlockSubsidyInner(nPrevBits, nPrevHeight, chainParams->GetConsensus(), /*fV20Active=*/ false);
      26           1 :     BOOST_CHECK_EQUAL(nSubsidy, 50000000000ULL);
      27             : 
      28             :     // details for block 4249 (subsidy returned will be for block 4250)
      29             :     // v20 should make difference for blocks with low diff, regardless of their height
      30           1 :     nPrevBits = 0x1c4a47c4;
      31           1 :     nPrevHeight = 4249;
      32           1 :     nSubsidy = GetBlockSubsidyInner(nPrevBits, nPrevHeight, chainParams->GetConsensus(), /*fV20Active=*/ true);
      33           1 :     BOOST_CHECK_EQUAL(nSubsidy, 500000000ULL);
      34             : 
      35             :     // details for block 4501 (subsidy returned will be for block 4502)
      36           1 :     nPrevBits = 0x1c4a47c4;
      37           1 :     nPrevHeight = 4501;
      38           1 :     nSubsidy = GetBlockSubsidyInner(nPrevBits, nPrevHeight, chainParams->GetConsensus(), /*fV20Active=*/ false);
      39           1 :     BOOST_CHECK_EQUAL(nSubsidy, 5600000000ULL);
      40             : 
      41             :     // details for block 5464 (subsidy returned will be for block 5465)
      42           1 :     nPrevBits = 0x1c29ec00;
      43           1 :     nPrevHeight = 5464;
      44           1 :     nSubsidy = GetBlockSubsidyInner(nPrevBits, nPrevHeight, chainParams->GetConsensus(), /*fV20Active=*/ false);
      45           1 :     BOOST_CHECK_EQUAL(nSubsidy, 2100000000ULL);
      46             : 
      47             :     // details for block 5465 (subsidy returned will be for block 5466)
      48           1 :     nPrevBits = 0x1c29ec00;
      49           1 :     nPrevHeight = 5465;
      50           1 :     nSubsidy = GetBlockSubsidyInner(nPrevBits, nPrevHeight, chainParams->GetConsensus(), /*fV20Active=*/ false);
      51           1 :     BOOST_CHECK_EQUAL(nSubsidy, 12200000000ULL);
      52             : 
      53             :     // details for block 17588 (subsidy returned will be for block 17589)
      54           1 :     nPrevBits = 0x1c08ba34;
      55           1 :     nPrevHeight = 17588;
      56           1 :     nSubsidy = GetBlockSubsidyInner(nPrevBits, nPrevHeight, chainParams->GetConsensus(), /*fV20Active=*/ false);
      57           1 :     BOOST_CHECK_EQUAL(nSubsidy, 6100000000ULL);
      58             : 
      59             :     // details for block 99999 (subsidy returned will be for block 100000)
      60           1 :     nPrevBits = 0x1b10cf42;
      61           1 :     nPrevHeight = 99999;
      62           1 :     nSubsidy = GetBlockSubsidyInner(nPrevBits, nPrevHeight, chainParams->GetConsensus(), /*fV20Active=*/ false);
      63           1 :     BOOST_CHECK_EQUAL(nSubsidy, 500000000ULL);
      64             : 
      65             :     // details for block 210239 (subsidy returned will be for block 210240)
      66           1 :     nPrevBits = 0x1b11548e;
      67           1 :     nPrevHeight = 210239;
      68           1 :     nSubsidy = GetBlockSubsidyInner(nPrevBits, nPrevHeight, chainParams->GetConsensus(), /*fV20Active=*/ false);
      69           1 :     BOOST_CHECK_EQUAL(nSubsidy, 500000000ULL);
      70             : 
      71             :     // 1st subsidy reduction happens here
      72             : 
      73             :     // details for block 210240 (subsidy returned will be for block 210241)
      74           1 :     nPrevBits = 0x1b10d50b;
      75           1 :     nPrevHeight = 210240;
      76           1 :     nSubsidy = GetBlockSubsidyInner(nPrevBits, nPrevHeight, chainParams->GetConsensus(), /*fV20Active=*/ false);
      77           1 :     BOOST_CHECK_EQUAL(nSubsidy, 464285715ULL);
      78             : 
      79             :     // details for block 210240 (subsidy returned will be for block 210241)
      80             :     // v20 makes no difference for blocks with high enough diff while budgets aren't active yet
      81           1 :     nPrevBits = 0x1b10d50b;
      82           1 :     nPrevHeight = 210240;
      83           1 :     nSubsidy = GetBlockSubsidyInner(nPrevBits, nPrevHeight, chainParams->GetConsensus(), /*fV20Active=*/ true);
      84           1 :     BOOST_CHECK_EQUAL(nSubsidy, 464285715ULL);
      85             : 
      86             :     // details for block 420480 (subsidy returned will be for block 210241)
      87           1 :     nPrevBits = 0x1b10d50b;
      88           1 :     nPrevHeight = 420480;
      89           1 :     nSubsidy = GetBlockSubsidyInner(nPrevBits, nPrevHeight, chainParams->GetConsensus(), /*fV20Active=*/ false);
      90           1 :     BOOST_CHECK_EQUAL(nSubsidy, 388010205ULL); // 431122450 * 0.9
      91             : 
      92             :     // details for block 420480 (subsidy returned will be for block 210241)
      93             :     // budgets are active, reallocation matters now
      94           1 :     nPrevBits = 0x1b10d50b;
      95           1 :     nPrevHeight = 420480;
      96           1 :     nSubsidy = GetBlockSubsidyInner(nPrevBits, nPrevHeight, chainParams->GetConsensus(), /*fV20Active=*/ true);
      97           1 :     BOOST_CHECK_EQUAL(nSubsidy, 344897960ULL); // 431122450 * 0.8
      98           1 : }
      99             : 
     100         146 : BOOST_AUTO_TEST_SUITE_END()

Generated by: LCOV version 1.16