diff --git a/src/Makefile.test.include b/src/Makefile.test.include --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -79,7 +79,6 @@ test/lcg_tests.cpp \ test/lcg.h \ test/limitedmap_tests.cpp \ - test/main_tests.cpp \ test/mempool_tests.cpp \ test/merkle_tests.cpp \ test/merkleblock_tests.cpp \ diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -92,7 +92,6 @@ key_tests.cpp lcg_tests.cpp limitedmap_tests.cpp - main_tests.cpp mempool_tests.cpp merkle_tests.cpp merkleblock_tests.cpp diff --git a/src/test/main_tests.cpp b/src/test/main_tests.cpp deleted file mode 100644 --- a/src/test/main_tests.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) 2014-2016 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 -#include -#include - -#include - -#include -#include - -BOOST_FIXTURE_TEST_SUITE(main_tests, TestingSetup) - -static void TestBlockSubsidyHalvings(const Consensus::Params &consensusParams) { - int maxHalvings = 64; - Amount nInitialSubsidy = 50 * COIN; - - Amount nPreviousSubsidy = 2 * nInitialSubsidy; // for height == 0 - BOOST_CHECK_EQUAL(nPreviousSubsidy, 2 * nInitialSubsidy); - for (int nHalvings = 0; nHalvings < maxHalvings; nHalvings++) { - int nHeight = nHalvings * consensusParams.nSubsidyHalvingInterval; - Amount nSubsidy = GetBlockSubsidy(nHeight, consensusParams); - BOOST_CHECK(nSubsidy <= nInitialSubsidy); - BOOST_CHECK_EQUAL(nSubsidy, nPreviousSubsidy / 2); - nPreviousSubsidy = nSubsidy; - } - BOOST_CHECK_EQUAL( - GetBlockSubsidy(maxHalvings * consensusParams.nSubsidyHalvingInterval, - consensusParams), - Amount::zero()); -} - -static void TestBlockSubsidyHalvings(int nSubsidyHalvingInterval) { - Consensus::Params consensusParams; - consensusParams.nSubsidyHalvingInterval = nSubsidyHalvingInterval; - TestBlockSubsidyHalvings(consensusParams); -} - -BOOST_AUTO_TEST_CASE(block_subsidy_test) { - const auto chainParams = CreateChainParams(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(CBaseChainParams::MAIN); - Amount nSum = Amount::zero(); - for (int nHeight = 0; nHeight < 14000000; nHeight += 1000) { - Amount nSubsidy = GetBlockSubsidy(nHeight, chainParams->GetConsensus()); - BOOST_CHECK(nSubsidy <= 50 * COIN); - nSum += 1000 * nSubsidy; - BOOST_CHECK(MoneyRange(nSum)); - } - BOOST_CHECK_EQUAL(nSum, int64_t(2099999997690000LL) * SATOSHI); -} - -BOOST_AUTO_TEST_SUITE_END() diff --git a/src/test/validation_tests.cpp b/src/test/validation_tests.cpp --- a/src/test/validation_tests.cpp +++ b/src/test/validation_tests.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2011-2016 The Bitcoin Core developers -// Copyright (c) 2017 The Bitcoin developers +// Copyright (c) 2011-2019 The Bitcoin Core developers +// Copyright (c) 2017-2019 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -9,18 +9,71 @@ #include #include #include +#include #include #include #include +#include #include +#include #include #include #include #include +BOOST_FIXTURE_TEST_SUITE(validation_tests, TestingSetup) + +static void TestBlockSubsidyHalvings(const Consensus::Params &consensusParams) { + int maxHalvings = 64; + Amount nInitialSubsidy = 50 * COIN; + + // for height == 0 + Amount nPreviousSubsidy = 2 * nInitialSubsidy; + BOOST_CHECK_EQUAL(nPreviousSubsidy, 2 * nInitialSubsidy); + for (int nHalvings = 0; nHalvings < maxHalvings; nHalvings++) { + int nHeight = nHalvings * consensusParams.nSubsidyHalvingInterval; + Amount nSubsidy = GetBlockSubsidy(nHeight, consensusParams); + BOOST_CHECK(nSubsidy <= nInitialSubsidy); + BOOST_CHECK_EQUAL(nSubsidy, nPreviousSubsidy / 2); + nPreviousSubsidy = nSubsidy; + } + BOOST_CHECK_EQUAL( + GetBlockSubsidy(maxHalvings * consensusParams.nSubsidyHalvingInterval, + consensusParams), + Amount::zero()); +} + +static void TestBlockSubsidyHalvings(int nSubsidyHalvingInterval) { + Consensus::Params consensusParams; + consensusParams.nSubsidyHalvingInterval = nSubsidyHalvingInterval; + TestBlockSubsidyHalvings(consensusParams); +} + +BOOST_AUTO_TEST_CASE(block_subsidy_test) { + const auto chainParams = CreateChainParams(CBaseChainParams::MAIN); + // As in main + TestBlockSubsidyHalvings(chainParams->GetConsensus()); + // As in regtest + TestBlockSubsidyHalvings(150); + // Just another interval + TestBlockSubsidyHalvings(1000); +} + +BOOST_AUTO_TEST_CASE(subsidy_limit_test) { + const auto chainParams = CreateChainParams(CBaseChainParams::MAIN); + Amount nSum = Amount::zero(); + for (int nHeight = 0; nHeight < 14000000; nHeight += 1000) { + Amount nSubsidy = GetBlockSubsidy(nHeight, chainParams->GetConsensus()); + BOOST_CHECK(nSubsidy <= 50 * COIN); + nSum += 1000 * nSubsidy; + BOOST_CHECK(MoneyRange(nSum)); + } + BOOST_CHECK_EQUAL(nSum, int64_t(2099999997690000LL) * SATOSHI); +} + static CBlock makeLargeDummyBlock(const size_t num_tx) { CBlock block; block.vtx.reserve(num_tx); @@ -32,12 +85,12 @@ return block; } -BOOST_FIXTURE_TEST_SUITE(validation_tests, TestingSetup) - -/** Test that LoadExternalBlockFile works with the buffer size set -below the size of a large block. Currently, LoadExternalBlockFile has the -buffer size for CBufferedFile set to 2 * MAX_TX_SIZE. Test with a value -of 10 * MAX_TX_SIZE. */ +/** + * Test that LoadExternalBlockFile works with the buffer size set below the + * size of a large block. Currently, LoadExternalBlockFile has the buffer size + * for CBufferedFile set to 2 * MAX_TX_SIZE. Test with a value of + * 10 * MAX_TX_SIZE. + */ BOOST_AUTO_TEST_CASE(validation_load_external_block_file) { fs::path tmpfile_name = SetDataDir("validation_load_external_block_file") / "block.dat";