From ffe835e1863010b1fdb8d0698c1b1a565ddd3f26 Mon Sep 17 00:00:00 2001 From: Alexander Koptelov Date: Fri, 19 Aug 2022 12:25:17 +0300 Subject: [PATCH] Implement fuzzcheck targets for gossip messages Fixes: #6 --- Cargo.toml | 4 ++++ tests/read-fuzz.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tests/read-fuzz.rs diff --git a/Cargo.toml b/Cargo.toml index f95bf7d..efdcbdf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,7 @@ hex = "0.4.3" binprot = { version = "0.1.7" } binprot_derive = { version = "0.1.7" } thiserror = "1.0.32" + +[target.'cfg(fuzzing)'.dev-dependencies] +#[dev-dependencies] +fuzzcheck = "0.12.1" diff --git a/tests/read-fuzz.rs b/tests/read-fuzz.rs new file mode 100644 index 0000000..fb5c472 --- /dev/null +++ b/tests/read-fuzz.rs @@ -0,0 +1,43 @@ +#![cfg(all(test, fuzzing))] + +fn try_decode(mut buf: &[u8]) -> bool +where + T: binprot::BinProtRead, +{ + match T::binprot_read(&mut buf) { + Ok(_) => {} + Err(_) => {} + } + true +} + +fn fuzz(f: F) +where + F: Fn(&[u8]) -> bool + 'static, +{ + let result = fuzzcheck::fuzz_test(f) + .default_options() + .stop_after_first_test_failure(true) + .launch(); + assert!(!result.found_test_failure); +} + +#[test] +fn gossip_message() { + fuzz(try_decode::); +} + +#[test] +fn external_transition() { + fuzz(try_decode::); +} + +#[test] +fn snark_pool_diff() { + fuzz(try_decode::); +} + +#[test] +fn tx_pool_diff() { + fuzz(try_decode::); +}