tests: Add missing locks to tests
[bitcoinplatinum.git] / src / test / main_tests.cpp
blob656aec606b6c2cc30a9211418960a3d1f186da85
1 // Copyright (c) 2014-2016 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.
5 #include "chainparams.h"
6 #include "validation.h"
7 #include "net.h"
9 #include "test/test_bitcoin.h"
11 #include <boost/signals2/signal.hpp>
12 #include <boost/test/unit_test.hpp>
14 BOOST_FIXTURE_TEST_SUITE(main_tests, TestingSetup)
16 static void TestBlockSubsidyHalvings(const Consensus::Params& consensusParams)
18 int maxHalvings = 64;
19 CAmount nInitialSubsidy = 50 * COIN;
21 CAmount nPreviousSubsidy = nInitialSubsidy * 2; // for height == 0
22 BOOST_CHECK_EQUAL(nPreviousSubsidy, nInitialSubsidy * 2);
23 for (int nHalvings = 0; nHalvings < maxHalvings; nHalvings++) {
24 int nHeight = nHalvings * consensusParams.nSubsidyHalvingInterval;
25 CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams);
26 BOOST_CHECK(nSubsidy <= nInitialSubsidy);
27 BOOST_CHECK_EQUAL(nSubsidy, nPreviousSubsidy / 2);
28 nPreviousSubsidy = nSubsidy;
30 BOOST_CHECK_EQUAL(GetBlockSubsidy(maxHalvings * consensusParams.nSubsidyHalvingInterval, consensusParams), 0);
33 static void TestBlockSubsidyHalvings(int nSubsidyHalvingInterval)
35 Consensus::Params consensusParams;
36 consensusParams.nSubsidyHalvingInterval = nSubsidyHalvingInterval;
37 TestBlockSubsidyHalvings(consensusParams);
40 BOOST_AUTO_TEST_CASE(block_subsidy_test)
42 const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
43 TestBlockSubsidyHalvings(chainParams->GetConsensus()); // As in main
44 TestBlockSubsidyHalvings(150); // As in regtest
45 TestBlockSubsidyHalvings(1000); // Just another interval
48 BOOST_AUTO_TEST_CASE(subsidy_limit_test)
50 const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
51 CAmount nSum = 0;
52 for (int nHeight = 0; nHeight < 14000000; nHeight += 1000) {
53 CAmount nSubsidy = GetBlockSubsidy(nHeight, chainParams->GetConsensus());
54 BOOST_CHECK(nSubsidy <= 50 * COIN);
55 nSum += nSubsidy * 1000;
56 BOOST_CHECK(MoneyRange(nSum));
58 BOOST_CHECK_EQUAL(nSum, 2099999997690000ULL);
61 bool ReturnFalse() { return false; }
62 bool ReturnTrue() { return true; }
64 BOOST_AUTO_TEST_CASE(test_combiner_all)
66 boost::signals2::signal<bool (), CombinerAll> Test;
67 BOOST_CHECK(Test());
68 Test.connect(&ReturnFalse);
69 BOOST_CHECK(!Test());
70 Test.connect(&ReturnTrue);
71 BOOST_CHECK(!Test());
72 Test.disconnect(&ReturnFalse);
73 BOOST_CHECK(Test());
74 Test.disconnect(&ReturnTrue);
75 BOOST_CHECK(Test());
77 BOOST_AUTO_TEST_SUITE_END()