Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (c) 2014 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. #include "chainparams.h"
  5. #include "main.h"
  6. #include "test/test_bitcoin.h"
  7. #include <boost/signals2/signal.hpp>
  8. #include <boost/test/unit_test.hpp>
  9. BOOST_FIXTURE_TEST_SUITE(main_tests, TestingSetup)
  10. static void TestBlockSubsidyHalvings(const Consensus::Params& consensusParams)
  11. {
  12. int maxHalvings = 64;
  13. CAmount nInitialSubsidy = 50 * COIN;
  14. CAmount nPreviousSubsidy = nInitialSubsidy * 2; // for height == 0
  15. BOOST_CHECK_EQUAL(nPreviousSubsidy, nInitialSubsidy * 2);
  16. for (int nHalvings = 0; nHalvings < maxHalvings; nHalvings++) {
  17. int nHeight = nHalvings * consensusParams.nSubsidyHalvingInterval;
  18. CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams);
  19. BOOST_CHECK(nSubsidy <= nInitialSubsidy);
  20. BOOST_CHECK_EQUAL(nSubsidy, nPreviousSubsidy / 2);
  21. nPreviousSubsidy = nSubsidy;
  22. }
  23. BOOST_CHECK_EQUAL(GetBlockSubsidy(maxHalvings * consensusParams.nSubsidyHalvingInterval, consensusParams), 0);
  24. }
  25. static void TestBlockSubsidyHalvings(int nSubsidyHalvingInterval)
  26. {
  27. Consensus::Params consensusParams;
  28. consensusParams.nSubsidyHalvingInterval = nSubsidyHalvingInterval;
  29. TestBlockSubsidyHalvings(consensusParams);
  30. }
  31. BOOST_AUTO_TEST_CASE(block_subsidy_test)
  32. {
  33. TestBlockSubsidyHalvings(Params(CBaseChainParams::MAIN).GetConsensus()); // As in main
  34. TestBlockSubsidyHalvings(150); // As in regtest
  35. TestBlockSubsidyHalvings(1000); // Just another interval
  36. }
  37. BOOST_AUTO_TEST_CASE(subsidy_limit_test)
  38. {
  39. const Consensus::Params& consensusParams = Params(CBaseChainParams::MAIN).GetConsensus();
  40. CAmount nSum = 0;
  41. for (int nHeight = 0; nHeight < 14000000; nHeight += 1000) {
  42. CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams);
  43. BOOST_CHECK(nSubsidy <= 50 * COIN);
  44. nSum += nSubsidy * 1000;
  45. BOOST_CHECK(MoneyRange(nSum));
  46. }
  47. BOOST_CHECK_EQUAL(nSum, 2099999997690000ULL);
  48. }
  49. bool ReturnFalse() { return false; }
  50. bool ReturnTrue() { return true; }
  51. BOOST_AUTO_TEST_CASE(test_combiner_all)
  52. {
  53. boost::signals2::signal<bool (), CombinerAll> Test;
  54. BOOST_CHECK(Test());
  55. Test.connect(&ReturnFalse);
  56. BOOST_CHECK(!Test());
  57. Test.connect(&ReturnTrue);
  58. BOOST_CHECK(!Test());
  59. Test.disconnect(&ReturnFalse);
  60. BOOST_CHECK(Test());
  61. Test.disconnect(&ReturnTrue);
  62. BOOST_CHECK(Test());
  63. }
  64. BOOST_AUTO_TEST_SUITE_END()