Skip to content

Commit 44fb2a5

Browse files
tests: Add fuzzing harness for FeeFilterRounder
1 parent 63dad67 commit 44fb2a5

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/Makefile.test.include

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ FUZZ_TARGETS = \
3434
test/fuzz/eval_script \
3535
test/fuzz/fee_rate \
3636
test/fuzz/fee_rate_deserialize \
37+
test/fuzz/fees \
3738
test/fuzz/flat_file_pos_deserialize \
3839
test/fuzz/flatfile \
3940
test/fuzz/float \
@@ -465,6 +466,12 @@ test_fuzz_fee_rate_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
465466
test_fuzz_fee_rate_deserialize_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
466467
test_fuzz_fee_rate_deserialize_SOURCES = test/fuzz/deserialize.cpp
467468

469+
test_fuzz_fees_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
470+
test_fuzz_fees_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
471+
test_fuzz_fees_LDADD = $(FUZZ_SUITE_LD_COMMON)
472+
test_fuzz_fees_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
473+
test_fuzz_fees_SOURCES = test/fuzz/fees.cpp
474+
468475
test_fuzz_flat_file_pos_deserialize_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) -DFLAT_FILE_POS_DESERIALIZE=1
469476
test_fuzz_flat_file_pos_deserialize_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
470477
test_fuzz_flat_file_pos_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)

src/test/fuzz/fees.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2020 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.
4+
5+
#include <amount.h>
6+
#include <optional.h>
7+
#include <policy/fees.h>
8+
#include <test/fuzz/FuzzedDataProvider.h>
9+
#include <test/fuzz/fuzz.h>
10+
#include <test/fuzz/util.h>
11+
12+
#include <cstdint>
13+
#include <string>
14+
#include <vector>
15+
16+
void test_one_input(const std::vector<uint8_t>& buffer)
17+
{
18+
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
19+
const CFeeRate minimal_incremental_fee{ConsumeMoney(fuzzed_data_provider)};
20+
FeeFilterRounder fee_filter_rounder{minimal_incremental_fee};
21+
while (fuzzed_data_provider.ConsumeBool()) {
22+
const CAmount current_minimum_fee = ConsumeMoney(fuzzed_data_provider);
23+
const CAmount rounded_fee = fee_filter_rounder.round(current_minimum_fee);
24+
assert(MoneyRange(rounded_fee));
25+
}
26+
}

0 commit comments

Comments
 (0)