| 67 | } // namespace |
| 68 | |
| 69 | FUZZ_TARGET(feefrac) |
| 70 | { |
| 71 | FuzzedDataProvider provider(buffer.data(), buffer.size()); |
| 72 | |
| 73 | int64_t f1 = provider.ConsumeIntegral<int64_t>(); |
| 74 | int32_t s1 = provider.ConsumeIntegral<int32_t>(); |
| 75 | if (s1 == 0) f1 = 0; |
| 76 | FeeFrac fr1(f1, s1); |
| 77 | assert(fr1.IsEmpty() == (s1 == 0)); |
| 78 | |
| 79 | int64_t f2 = provider.ConsumeIntegral<int64_t>(); |
| 80 | int32_t s2 = provider.ConsumeIntegral<int32_t>(); |
| 81 | if (s2 == 0) f2 = 0; |
| 82 | FeeFrac fr2(f2, s2); |
| 83 | assert(fr2.IsEmpty() == (s2 == 0)); |
| 84 | |
| 85 | // Feerate comparisons |
| 86 | auto cmp_feerate = MulCompare(f1, s2, f2, s1); |
| 87 | assert((ByRatio{fr1} <=> ByRatio{fr2}) == cmp_feerate); |
| 88 | assert((ByRatio{fr1} < ByRatio{fr2}) == std::is_lt(cmp_feerate)); |
| 89 | assert((ByRatio{fr1} > ByRatio{fr2}) == std::is_gt(cmp_feerate)); |
| 90 | |
| 91 | // Compare with manual invocation of FeeFrac::Mul. |
| 92 | auto cmp_mul = FeeFrac::Mul(f1, s2) <=> FeeFrac::Mul(f2, s1); |
| 93 | assert(cmp_mul == cmp_feerate); |
| 94 | |
| 95 | // Same, but using FeeFrac::MulFallback. |
| 96 | auto cmp_fallback = FeeFrac::MulFallback(f1, s2) <=> FeeFrac::MulFallback(f2, s1); |
| 97 | assert(cmp_fallback == cmp_feerate); |
| 98 | |
| 99 | // Total order comparisons |
| 100 | auto cmp_total = std::is_eq(cmp_feerate) ? (s2 <=> s1) : cmp_feerate; |
| 101 | assert((ByRatioNegSize{fr1} <=> ByRatioNegSize{fr2}) == cmp_total); |
| 102 | assert((ByRatioNegSize{fr1} < ByRatioNegSize{fr2}) == std::is_lt(cmp_total)); |
| 103 | assert((ByRatioNegSize{fr1} > ByRatioNegSize{fr2}) == std::is_gt(cmp_total)); |
| 104 | assert((ByRatioNegSize{fr1} <= ByRatioNegSize{fr2}) == std::is_lteq(cmp_total)); |
| 105 | assert((ByRatioNegSize{fr1} >= ByRatioNegSize{fr2}) == std::is_gteq(cmp_total)); |
| 106 | assert((ByRatioNegSize{fr1} == ByRatioNegSize{fr2}) == std::is_eq(cmp_total)); |
| 107 | assert((ByRatioNegSize{fr1} != ByRatioNegSize{fr2}) == std::is_neq(cmp_total)); |
| 108 | } |
| 109 | |
| 110 | FUZZ_TARGET(feefrac_div_fallback) |
| 111 | { |
nothing calls this directly
no test coverage detected