Move ChannelMonitor deserialization to new ser framework
[rust-lightning] / fuzz / fuzz_targets / chanmon_deser_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::channelmonitor;
7 use lightning::util::reset_rng_state;
8 use lightning::util::ser::Readable;
9
10 use std::io::Cursor;
11
12 #[inline]
13 pub fn do_test(data: &[u8]) {
14         reset_rng_state();
15         if let Ok(monitor) = channelmonitor::ChannelMonitor::read(&mut Cursor::new(data)) {
16                 assert!(channelmonitor::ChannelMonitor::read(&mut Cursor::new(&monitor.serialize_for_disk()[..])).unwrap() == monitor);
17                 monitor.serialize_for_watchtower();
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
45         #[test]
46         fn duplicate_crash() {
47                 super::do_test(&::hex::decode("00").unwrap());
48         }
49 }