Merge #9240: Remove txConflicted
[bitcoinplatinum.git] / src / test / amount_tests.cpp
blobfd6f88b36627d44dc2ddfdc20e8a60bced8760a0
1 // Copyright (c) 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 "amount.h"
6 #include "test/test_bitcoin.h"
8 #include <boost/test/unit_test.hpp>
10 BOOST_FIXTURE_TEST_SUITE(amount_tests, BasicTestingSetup)
12 BOOST_AUTO_TEST_CASE(GetFeeTest)
14 CFeeRate feeRate;
16 feeRate = CFeeRate(0);
17 // Must always return 0
18 BOOST_CHECK_EQUAL(feeRate.GetFee(0), 0);
19 BOOST_CHECK_EQUAL(feeRate.GetFee(1e5), 0);
21 feeRate = CFeeRate(1000);
22 // Must always just return the arg
23 BOOST_CHECK_EQUAL(feeRate.GetFee(0), 0);
24 BOOST_CHECK_EQUAL(feeRate.GetFee(1), 1);
25 BOOST_CHECK_EQUAL(feeRate.GetFee(121), 121);
26 BOOST_CHECK_EQUAL(feeRate.GetFee(999), 999);
27 BOOST_CHECK_EQUAL(feeRate.GetFee(1e3), 1e3);
28 BOOST_CHECK_EQUAL(feeRate.GetFee(9e3), 9e3);
30 feeRate = CFeeRate(-1000);
31 // Must always just return -1 * arg
32 BOOST_CHECK_EQUAL(feeRate.GetFee(0), 0);
33 BOOST_CHECK_EQUAL(feeRate.GetFee(1), -1);
34 BOOST_CHECK_EQUAL(feeRate.GetFee(121), -121);
35 BOOST_CHECK_EQUAL(feeRate.GetFee(999), -999);
36 BOOST_CHECK_EQUAL(feeRate.GetFee(1e3), -1e3);
37 BOOST_CHECK_EQUAL(feeRate.GetFee(9e3), -9e3);
39 feeRate = CFeeRate(123);
40 // Truncates the result, if not integer
41 BOOST_CHECK_EQUAL(feeRate.GetFee(0), 0);
42 BOOST_CHECK_EQUAL(feeRate.GetFee(8), 1); // Special case: returns 1 instead of 0
43 BOOST_CHECK_EQUAL(feeRate.GetFee(9), 1);
44 BOOST_CHECK_EQUAL(feeRate.GetFee(121), 14);
45 BOOST_CHECK_EQUAL(feeRate.GetFee(122), 15);
46 BOOST_CHECK_EQUAL(feeRate.GetFee(999), 122);
47 BOOST_CHECK_EQUAL(feeRate.GetFee(1e3), 123);
48 BOOST_CHECK_EQUAL(feeRate.GetFee(9e3), 1107);
50 feeRate = CFeeRate(-123);
51 // Truncates the result, if not integer
52 BOOST_CHECK_EQUAL(feeRate.GetFee(0), 0);
53 BOOST_CHECK_EQUAL(feeRate.GetFee(8), -1); // Special case: returns -1 instead of 0
54 BOOST_CHECK_EQUAL(feeRate.GetFee(9), -1);
56 // Check full constructor
57 // default value
58 BOOST_CHECK(CFeeRate(CAmount(-1), 1000) == CFeeRate(-1));
59 BOOST_CHECK(CFeeRate(CAmount(0), 1000) == CFeeRate(0));
60 BOOST_CHECK(CFeeRate(CAmount(1), 1000) == CFeeRate(1));
61 // lost precision (can only resolve satoshis per kB)
62 BOOST_CHECK(CFeeRate(CAmount(1), 1001) == CFeeRate(0));
63 BOOST_CHECK(CFeeRate(CAmount(2), 1001) == CFeeRate(1));
64 // some more integer checks
65 BOOST_CHECK(CFeeRate(CAmount(26), 789) == CFeeRate(32));
66 BOOST_CHECK(CFeeRate(CAmount(27), 789) == CFeeRate(34));
67 // Maximum size in bytes, should not crash
68 CFeeRate(MAX_MONEY, std::numeric_limits<size_t>::max() >> 1).GetFeePerK();
71 BOOST_AUTO_TEST_SUITE_END()