Update error deserialization in compliance with BOLT #1
[rust-lightning] / fuzz / fuzz_targets / msg_error_message_target.rs
1 // This file is auto-generated by gen_target.sh based on msg_target_template.txt
2 // To modify it, modify msg_target_template.txt and run gen_target.sh instead.
3
4 extern crate lightning;
5
6 use lightning::ln::msgs;
7 use lightning::util::reset_rng_state;
8
9 use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
10
11 #[inline]
12 pub fn do_test(data: &[u8]) {
13         reset_rng_state();
14         if let Ok(msg) = msgs::ErrorMessage::decode(data){
15                 let enc = msg.encode();
16                 assert_eq!(&data[0..32], &enc[0..32]);
17                 assert_eq!(&data[34..enc.len()], &enc[34..]);
18         }
19 }
20
21 #[cfg(feature = "afl")]
22 #[macro_use] extern crate afl;
23 #[cfg(feature = "afl")]
24 fn main() {
25         fuzz!(|data| {
26                 do_test(data);
27         });
28 }
29
30 #[cfg(feature = "honggfuzz")]
31 #[macro_use] extern crate honggfuzz;
32 #[cfg(feature = "honggfuzz")]
33 fn main() {
34         loop {
35                 fuzz!(|data| {
36                         do_test(data);
37                 });
38         }
39 }
40
41 extern crate hex;
42 #[cfg(test)]
43 mod tests {
44         #[test]
45         fn duplicate_crash() {
46                 super::do_test(&::hex::decode("00").unwrap());
47         }
48 }