Correct excess-data handling in NodeAnnouncement
[rust-lightning] / fuzz / fuzz_targets / msg_error_message_target.rs
1 extern crate lightning;
2
3 use lightning::ln::msgs;
4 use lightning::util::reset_rng_state;
5
6 use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
7
8 #[inline]
9 pub fn do_test(data: &[u8]) {
10         reset_rng_state();
11         if let Ok(msg) = msgs::ErrorMessage::decode(data){
12                 let enc = msg.encode();
13                 assert_eq!(&data[0..32], &enc[0..32]);
14                 assert_eq!(&data[34..enc.len()], &enc[34..]);
15         }
16 }
17
18 #[cfg(feature = "afl")]
19 #[macro_use] extern crate afl;
20 #[cfg(feature = "afl")]
21 fn main() {
22         fuzz!(|data| {
23                 do_test(data);
24         });
25 }
26
27 #[cfg(feature = "honggfuzz")]
28 #[macro_use] extern crate honggfuzz;
29 #[cfg(feature = "honggfuzz")]
30 fn main() {
31         loop {
32                 fuzz!(|data| {
33                         do_test(data);
34                 });
35         }
36 }
37
38 extern crate hex;
39 #[cfg(test)]
40 mod tests {
41         #[test]
42         fn duplicate_crash() {
43                 super::do_test(&::hex::decode("00").unwrap());
44         }
45 }