Skip to content

Commit

Permalink
Implement fuzzcheck targets for gossip messages
Browse files Browse the repository at this point in the history
Fixes: #6
  • Loading branch information
akoptelov committed Aug 19, 2022
1 parent 3503ed2 commit ffe835e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
43 changes: 43 additions & 0 deletions tests/read-fuzz.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#![cfg(all(test, fuzzing))]

fn try_decode<T>(mut buf: &[u8]) -> bool
where
T: binprot::BinProtRead,
{
match T::binprot_read(&mut buf) {
Ok(_) => {}
Err(_) => {}
}
true
}

fn fuzz<F>(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::<mina_p2p_messages::GossipNetMessage>);
}

#[test]
fn external_transition() {
fuzz(try_decode::<mina_p2p_messages::p2p::MinaBlockExternalTransitionRawVersionedStable>);
}

#[test]
fn snark_pool_diff() {
fuzz(try_decode::<mina_p2p_messages::p2p::NetworkPoolSnarkPoolDiffVersionedStable>);
}

#[test]
fn tx_pool_diff() {
fuzz(try_decode::<mina_p2p_messages::p2p::NetworkPoolTransactionPoolDiffVersionedStable>);
}

0 comments on commit ffe835e

Please sign in to comment.