Skip to content

Commit 58914ab

Browse files
sipainstagibbs
andcommitted
fuzz: assert min diff between FeeFrac and CFeeRate
Co-Authored-By: Greg Sanders <gsanders87@gmail.com>
1 parent 0c6bcfd commit 58914ab

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/test/fuzz/feefrac.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <arith_uint256.h>
6+
#include <policy/feerate.h>
67
#include <util/feefrac.h>
78
#include <test/fuzz/FuzzedDataProvider.h>
89
#include <test/fuzz/fuzz.h>
@@ -217,5 +218,16 @@ FUZZ_TARGET(feefrac_mul_div)
217218
FeeFrac{mul64, div}.EvaluateFeeDown(mul32) :
218219
FeeFrac{mul64, div}.EvaluateFeeUp(mul32);
219220
assert(res == res_fee);
221+
222+
// Compare approximately with CFeeRate.
223+
if (mul64 <= std::numeric_limits<int64_t>::max() / 1000 &&
224+
mul64 >= std::numeric_limits<int64_t>::min() / 1000 &&
225+
quot_abs <= arith_uint256{std::numeric_limits<int64_t>::max() / 1000}) {
226+
CFeeRate feerate(mul64, (uint32_t)div);
227+
CAmount feerate_fee{feerate.GetFee(mul32)};
228+
auto allowed_gap = static_cast<int64_t>(mul32 / 1000 + 3 + round_down);
229+
assert(feerate_fee - res_fee >= -allowed_gap);
230+
assert(feerate_fee - res_fee <= allowed_gap);
231+
}
220232
}
221233
}

0 commit comments

Comments
 (0)