diff options
author | Ava Chow <github@achow101.com> | 2023-12-19 19:24:54 -0500 |
---|---|---|
committer | Ava Chow <github@achow101.com> | 2023-12-19 19:36:06 -0500 |
commit | e3847f7ac4b74893d266770c456d57ed20b9bb8b (patch) | |
tree | 53f87b0a3d39916482a82c43b82410d525740da4 /src/test | |
parent | dd391944dc2d4e7dda9439647e603b41ba751b78 (diff) | |
parent | 1757452cc55a6dacc62e4258043ee4d711fd281a (diff) |
Merge bitcoin/bitcoin#29037: Add multiplication operator to CFeeRate
1757452cc55a6dacc62e4258043ee4d711fd281a test: Add tests for CFeeRate multiplication operator (Kashif Smith)
1553c8078698df1058b62e8fdadaf74160977b30 Add multiplication operator to CFeeRate (Murch)
Pull request description:
Allows us to use
`coin_selection_params.m_long_term_feerate * 3`
or
`3 * coin_selection_params.m_long_term_feerate`
instead of
`CFeeRate{coin_selection_params.m_long_term_feerate.GetFee(3000)}`
inspired by https://github.com/bitcoin/bitcoin/pull/27877#discussion_r1414455724
ACKs for top commit:
kevkevinpal:
reACK [1757452](https://github.com/bitcoin/bitcoin/pull/29037/commits/1757452cc55a6dacc62e4258043ee4d711fd281a)
achow101:
ACK 1757452cc55a6dacc62e4258043ee4d711fd281a
ajtowns:
ACK 1757452cc55a6dacc62e4258043ee4d711fd281a ; lgtm
ismaelsadeeq:
ACK 1757452cc55a6dacc62e4258043ee4d711fd281a
Tree-SHA512: a86faac1efd1b7688630cd811246533d184d56b62064a7fd9007de95dbf81fa668aa2252253d102fba67517b6a4ca2dc367c5388b8ab936215734d7d370740cf
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/amount_tests.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/test/amount_tests.cpp b/src/test/amount_tests.cpp index 3815a5bba6..e5ab1cfb90 100644 --- a/src/test/amount_tests.cpp +++ b/src/test/amount_tests.cpp @@ -85,6 +85,32 @@ BOOST_AUTO_TEST_CASE(GetFeeTest) BOOST_CHECK(CFeeRate(CAmount(27), 789) == CFeeRate(34)); // Maximum size in bytes, should not crash CFeeRate(MAX_MONEY, std::numeric_limits<uint32_t>::max()).GetFeePerK(); + + // check multiplication operator + // check multiplying by zero + feeRate = CFeeRate(1000); + BOOST_CHECK(0 * feeRate == CFeeRate(0)); + BOOST_CHECK(feeRate * 0 == CFeeRate(0)); + // check multiplying by a positive integer + BOOST_CHECK(3 * feeRate == CFeeRate(3000)); + BOOST_CHECK(feeRate * 3 == CFeeRate(3000)); + // check multiplying by a negative integer + BOOST_CHECK(-3 * feeRate == CFeeRate(-3000)); + BOOST_CHECK(feeRate * -3 == CFeeRate(-3000)); + // check commutativity + BOOST_CHECK(2 * feeRate == feeRate * 2); + // check with large numbers + int largeNumber = 1000000; + BOOST_CHECK(largeNumber * feeRate == feeRate * largeNumber); + // check boundary values + int maxInt = std::numeric_limits<int>::max(); + feeRate = CFeeRate(maxInt); + BOOST_CHECK(feeRate * 2 == CFeeRate(static_cast<int64_t>(maxInt) * 2)); + BOOST_CHECK(2 * feeRate == CFeeRate(static_cast<int64_t>(maxInt) * 2)); + // check with zero fee rate + feeRate = CFeeRate(0); + BOOST_CHECK(feeRate * 5 == CFeeRate(0)); + BOOST_CHECK(5 * feeRate == CFeeRate(0)); } BOOST_AUTO_TEST_CASE(BinaryOperatorTest) |