From 43f6f1b4d7b5f7586575b2660af3f73be4566907 Mon Sep 17 00:00:00 2001 From: presstab Date: Wed, 2 May 2018 14:50:55 -0600 Subject: [PATCH] Add unit test for budget value. Prevent any future issues with calculated budget value by adding a unit test. --- src/Makefile.test.include | 1 + src/test/budget_tests.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/test/budget_tests.cpp diff --git a/src/Makefile.test.include b/src/Makefile.test.include index cf40f0f1abdb3..3b492868d465a 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -48,6 +48,7 @@ BITCOIN_TESTS =\ test/base32_tests.cpp \ test/base58_tests.cpp \ test/base64_tests.cpp \ + test/budget_tests.cpp \ test/checkblock_tests.cpp \ test/Checkpoints_tests.cpp \ test/coins_tests.cpp \ diff --git a/src/test/budget_tests.cpp b/src/test/budget_tests.cpp new file mode 100644 index 0000000000000..c156644e2cb75 --- /dev/null +++ b/src/test/budget_tests.cpp @@ -0,0 +1,31 @@ +// Copyright (c) 2018 The PIVX developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include +#include +#include "masternode-budget.h" + +BOOST_AUTO_TEST_SUITE(budget_tests) + +void CheckBudgetValue(int nHeight, std::string strNetwork, CAmount nExpectedValue) +{ + CBudgetManager budget; + CAmount nBudget = budget.GetTotalBudget(nHeight); + std::string strError = strprintf("Budget is not as expected for %s. Result: %s, Expected: %s", strNetwork, FormatMoney(nBudget), FormatMoney(nExpectedValue)); + BOOST_CHECK_MESSAGE(nBudget == nExpectedValue, strError); +} + +BOOST_AUTO_TEST_CASE(budget_value) +{ + SelectParams(CBaseChainParams::MAIN); + int nHeightTest = Params().Zerocoin_Block_V2_Start() + 1; + CheckBudgetValue(nHeightTest, "mainnet", 43200*COIN); + + SelectParams(CBaseChainParams::TESTNET); + nHeightTest = Params().Zerocoin_Block_V2_Start() + 1; + CheckBudgetValue(nHeightTest, "testnet", 7300*COIN); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file