mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
Merge bitcoin/bitcoin#29037: Add multiplication operator to CFeeRate
1757452cc5test: Add tests for CFeeRate multiplication operator (Kashif Smith)1553c80786Add 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](1757452cc5) achow101: ACK1757452cc5ajtowns: ACK1757452cc5; lgtm ismaelsadeeq: ACK1757452cc5Tree-SHA512: a86faac1efd1b7688630cd811246533d184d56b62064a7fd9007de95dbf81fa668aa2252253d102fba67517b6a4ca2dc367c5388b8ab936215734d7d370740cf
This commit is contained in:
@@ -71,6 +71,8 @@ public:
|
||||
friend bool operator!=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK != b.nSatoshisPerK; }
|
||||
CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
|
||||
std::string ToString(const FeeEstimateMode& fee_estimate_mode = FeeEstimateMode::BTC_KVB) const;
|
||||
friend CFeeRate operator*(const CFeeRate& f, int a) { return CFeeRate(a * f.nSatoshisPerK); }
|
||||
friend CFeeRate operator*(int a, const CFeeRate& f) { return CFeeRate(a * f.nSatoshisPerK); }
|
||||
|
||||
SERIALIZE_METHODS(CFeeRate, obj) { READWRITE(obj.nSatoshisPerK); }
|
||||
};
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user