LCOV - code coverage report
Current view: top level - src/test - validation_tests.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 49 49 100.0 %
Date: 2020-09-26 01:30:44 Functions: 27 27 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2014-2019 The Bitcoin 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 <net.h>
       7             : #include <validation.h>
       8             : 
       9             : #include <test/util/setup_common.h>
      10             : 
      11             : #include <boost/signals2/signal.hpp>
      12             : #include <boost/test/unit_test.hpp>
      13             : 
      14          89 : BOOST_FIXTURE_TEST_SUITE(validation_tests, TestingSetup)
      15             : 
      16           3 : static void TestBlockSubsidyHalvings(const Consensus::Params& consensusParams)
      17             : {
      18             :     int maxHalvings = 64;
      19             :     CAmount nInitialSubsidy = 50 * COIN;
      20             : 
      21           3 :     CAmount nPreviousSubsidy = nInitialSubsidy * 2; // for height == 0
      22           3 :     BOOST_CHECK_EQUAL(nPreviousSubsidy, nInitialSubsidy * 2);
      23         195 :     for (int nHalvings = 0; nHalvings < maxHalvings; nHalvings++) {
      24         192 :         int nHeight = nHalvings * consensusParams.nSubsidyHalvingInterval;
      25         192 :         CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams);
      26         192 :         BOOST_CHECK(nSubsidy <= nInitialSubsidy);
      27         192 :         BOOST_CHECK_EQUAL(nSubsidy, nPreviousSubsidy / 2);
      28         192 :         nPreviousSubsidy = nSubsidy;
      29         192 :     }
      30           3 :     BOOST_CHECK_EQUAL(GetBlockSubsidy(maxHalvings * consensusParams.nSubsidyHalvingInterval, consensusParams), 0);
      31           3 : }
      32             : 
      33           2 : static void TestBlockSubsidyHalvings(int nSubsidyHalvingInterval)
      34             : {
      35           2 :     Consensus::Params consensusParams;
      36           2 :     consensusParams.nSubsidyHalvingInterval = nSubsidyHalvingInterval;
      37           2 :     TestBlockSubsidyHalvings(consensusParams);
      38           2 : }
      39             : 
      40          95 : BOOST_AUTO_TEST_CASE(block_subsidy_test)
      41             : {
      42           1 :     const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
      43           1 :     TestBlockSubsidyHalvings(chainParams->GetConsensus()); // As in main
      44           1 :     TestBlockSubsidyHalvings(150); // As in regtest
      45           1 :     TestBlockSubsidyHalvings(1000); // Just another interval
      46           1 : }
      47             : 
      48          95 : BOOST_AUTO_TEST_CASE(subsidy_limit_test)
      49             : {
      50           1 :     const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
      51           1 :     CAmount nSum = 0;
      52       14001 :     for (int nHeight = 0; nHeight < 14000000; nHeight += 1000) {
      53       14000 :         CAmount nSubsidy = GetBlockSubsidy(nHeight, chainParams->GetConsensus());
      54       14000 :         BOOST_CHECK(nSubsidy <= 50 * COIN);
      55       14000 :         nSum += nSubsidy * 1000;
      56       14000 :         BOOST_CHECK(MoneyRange(nSum));
      57             :     }
      58           1 :     BOOST_CHECK_EQUAL(nSum, CAmount{2099999997690000});
      59           1 : }
      60             : 
      61           2 : static bool ReturnFalse() { return false; }
      62           1 : static bool ReturnTrue() { return true; }
      63             : 
      64          95 : BOOST_AUTO_TEST_CASE(test_combiner_all)
      65             : {
      66           1 :     boost::signals2::signal<bool (), CombinerAll> Test;
      67           1 :     BOOST_CHECK(Test());
      68           1 :     Test.connect(&ReturnFalse);
      69           1 :     BOOST_CHECK(!Test());
      70           1 :     Test.connect(&ReturnTrue);
      71           1 :     BOOST_CHECK(!Test());
      72           1 :     Test.disconnect(&ReturnFalse);
      73           1 :     BOOST_CHECK(Test());
      74           1 :     Test.disconnect(&ReturnTrue);
      75           1 :     BOOST_CHECK(Test());
      76           1 : }
      77          89 : BOOST_AUTO_TEST_SUITE_END()

Generated by: LCOV version 1.15