Skip to content

Commit fcae901

Browse files
committed
consensus: add consensus property tests
1 parent 9313251 commit fcae901

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
//
5+
// Copyright (c) DUSK NETWORK. All rights reserved.
6+
7+
use std::io::Cursor;
8+
9+
use node_data::Serializable;
10+
use node_data::message::Message;
11+
use rand::rngs::StdRng;
12+
use rand::{Rng, SeedableRng};
13+
14+
#[test]
15+
#[ignore = "fuzz-like deserialization; run manually"]
16+
// Randomized deserialization should never panic, even on malformed input.
17+
fn fuzz_message_deserialization_does_not_panic() {
18+
let mut rng = StdRng::seed_from_u64(4242);
19+
20+
for _ in 0..1000 {
21+
let len = rng.gen_range(0..512);
22+
let mut bytes = vec![0u8; len];
23+
rng.fill(&mut bytes[..]);
24+
25+
let result = std::panic::catch_unwind(|| {
26+
let mut cursor = Cursor::new(bytes);
27+
let _ = Message::read(&mut cursor);
28+
});
29+
30+
assert!(result.is_ok(), "deserialization panicked");
31+
}
32+
}

0 commit comments

Comments
 (0)