aboutsummaryrefslogtreecommitdiff
path: root/src/test/fuzz/banman.cpp
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-06-23 13:28:30 +0200
committerMarcoFalke <falke.marco@gmail.com>2021-06-24 15:57:34 +0200
commitfa485d06ec10acd9a791f8d29689e1e82591fb70 (patch)
tree000875aadeed6ec2669e29369424d55fc5083b8a /src/test/fuzz/banman.cpp
parentd6e0d78c31557660274ef53cac912c468eecbe2d (diff)
fuzz: Check banman roundtrip
Diffstat (limited to 'src/test/fuzz/banman.cpp')
-rw-r--r--src/test/fuzz/banman.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/test/fuzz/banman.cpp b/src/test/fuzz/banman.cpp
index cca41e79ae..182aabc79b 100644
--- a/src/test/fuzz/banman.cpp
+++ b/src/test/fuzz/banman.cpp
@@ -32,6 +32,13 @@ void initialize_banman()
static const auto testing_setup = MakeNoLogFileContext<>();
}
+static bool operator==(const CBanEntry& lhs, const CBanEntry& rhs)
+{
+ return lhs.nVersion == rhs.nVersion &&
+ lhs.nCreateTime == rhs.nCreateTime &&
+ lhs.nBanUntil == rhs.nBanUntil;
+}
+
FUZZ_TARGET_INIT(banman, initialize_banman)
{
// The complexity is O(N^2), where N is the input size, because each call
@@ -43,19 +50,20 @@ FUZZ_TARGET_INIT(banman, initialize_banman)
fs::path banlist_file = gArgs.GetDataDirNet() / "fuzzed_banlist";
const bool start_with_corrupted_banlist{fuzzed_data_provider.ConsumeBool()};
+ bool force_read_and_write_to_err{false};
if (start_with_corrupted_banlist) {
const std::string sfx{fuzzed_data_provider.ConsumeBool() ? ".dat" : ".json"};
assert(WriteBinaryFile(banlist_file.string() + sfx,
fuzzed_data_provider.ConsumeRandomLengthString()));
} else {
- const bool force_read_and_write_to_err{fuzzed_data_provider.ConsumeBool()};
+ force_read_and_write_to_err = fuzzed_data_provider.ConsumeBool();
if (force_read_and_write_to_err) {
banlist_file = fs::path{"path"} / "to" / "inaccessible" / "fuzzed_banlist";
}
}
{
- BanMan ban_man{banlist_file, nullptr, ConsumeBanTimeOffset(fuzzed_data_provider)};
+ BanMan ban_man{banlist_file, /* client_interface */ nullptr, /* default_ban_time */ ConsumeBanTimeOffset(fuzzed_data_provider)};
while (--limit_max_ops >= 0 && fuzzed_data_provider.ConsumeBool()) {
CallOneOf(
fuzzed_data_provider,
@@ -93,6 +101,16 @@ FUZZ_TARGET_INIT(banman, initialize_banman)
ban_man.Discourage(ConsumeNetAddr(fuzzed_data_provider));
});
}
+ if (!force_read_and_write_to_err) {
+ ban_man.DumpBanlist();
+ SetMockTime(ConsumeTime(fuzzed_data_provider));
+ banmap_t banmap;
+ ban_man.GetBanned(banmap);
+ BanMan ban_man_read{banlist_file, /* client_interface */ nullptr, /* default_ban_time */ 0};
+ banmap_t banmap_read;
+ ban_man_read.GetBanned(banmap_read);
+ assert(banmap == banmap_read);
+ }
}
fs::remove(banlist_file.string() + ".dat");
fs::remove(banlist_file.string() + ".json");