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.
5 extern crate bitcoin_hashes;
6 extern crate lightning;
8 use bitcoin_hashes::sha256d::Hash as Sha256dHash;
10 use lightning::ln::channelmonitor;
11 use lightning::util::ser::{ReadableArgs, Writer};
14 use utils::test_logger;
19 struct VecWriter(Vec<u8>);
20 impl Writer for VecWriter {
21 fn write_all(&mut self, buf: &[u8]) -> Result<(), ::std::io::Error> {
22 self.0.extend_from_slice(buf);
25 fn size_hint(&mut self, size: usize) {
26 self.0.reserve_exact(size);
31 pub fn do_test(data: &[u8]) {
32 let logger = Arc::new(test_logger::TestLogger::new("".to_owned()));
33 if let Ok((latest_block_hash, monitor)) = <(Sha256dHash, channelmonitor::ChannelMonitor)>::read(&mut Cursor::new(data), logger.clone()) {
34 let mut w = VecWriter(Vec::new());
35 monitor.write_for_disk(&mut w).unwrap();
36 let deserialized_copy = <(Sha256dHash, channelmonitor::ChannelMonitor)>::read(&mut Cursor::new(&w.0), logger.clone()).unwrap();
37 assert!(latest_block_hash == deserialized_copy.0);
38 assert!(monitor == deserialized_copy.1);
40 monitor.write_for_watchtower(&mut w).unwrap();
44 #[cfg(feature = "afl")]
45 #[macro_use] extern crate afl;
46 #[cfg(feature = "afl")]
53 #[cfg(feature = "honggfuzz")]
54 #[macro_use] extern crate honggfuzz;
55 #[cfg(feature = "honggfuzz")]
69 fn duplicate_crash() {
70 super::do_test(&::hex::decode("00").unwrap());