2018-07-16 21:12:54 -07:00
|
|
|
// This file is auto-generated by gen_target.sh based on msg_target_template.txt
|
|
|
|
// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
|
|
|
|
|
2018-10-24 11:14:12 -04:00
|
|
|
extern crate bitcoin;
|
2019-03-04 18:02:02 +01:00
|
|
|
extern crate bitcoin_hashes;
|
2018-07-16 21:12:54 -07:00
|
|
|
extern crate lightning;
|
|
|
|
|
2019-03-04 18:02:02 +01:00
|
|
|
use bitcoin_hashes::sha256d::Hash as Sha256dHash;
|
2018-10-24 11:14:12 -04:00
|
|
|
|
2018-07-16 21:12:54 -07:00
|
|
|
use lightning::ln::channelmonitor;
|
|
|
|
use lightning::util::reset_rng_state;
|
2018-10-18 15:00:12 -04:00
|
|
|
use lightning::util::ser::{ReadableArgs, Writer};
|
|
|
|
|
|
|
|
mod utils;
|
|
|
|
use utils::test_logger;
|
2018-09-19 13:17:16 -04:00
|
|
|
|
|
|
|
use std::io::Cursor;
|
2018-10-18 15:00:12 -04:00
|
|
|
use std::sync::Arc;
|
2018-07-16 21:12:54 -07:00
|
|
|
|
2018-09-19 13:31:14 -04:00
|
|
|
struct VecWriter(Vec<u8>);
|
|
|
|
impl Writer for VecWriter {
|
|
|
|
fn write_all(&mut self, buf: &[u8]) -> Result<(), ::std::io::Error> {
|
|
|
|
self.0.extend_from_slice(buf);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
fn size_hint(&mut self, size: usize) {
|
|
|
|
self.0.reserve_exact(size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-16 21:12:54 -07:00
|
|
|
#[inline]
|
|
|
|
pub fn do_test(data: &[u8]) {
|
|
|
|
reset_rng_state();
|
2019-01-08 15:06:43 -05:00
|
|
|
let logger = Arc::new(test_logger::TestLogger::new("".to_owned()));
|
2018-10-24 11:14:12 -04:00
|
|
|
if let Ok((latest_block_hash, monitor)) = <(Sha256dHash, channelmonitor::ChannelMonitor)>::read(&mut Cursor::new(data), logger.clone()) {
|
2018-09-19 13:31:14 -04:00
|
|
|
let mut w = VecWriter(Vec::new());
|
|
|
|
monitor.write_for_disk(&mut w).unwrap();
|
2018-10-24 11:14:12 -04:00
|
|
|
let deserialized_copy = <(Sha256dHash, channelmonitor::ChannelMonitor)>::read(&mut Cursor::new(&w.0), logger.clone()).unwrap();
|
|
|
|
assert!(latest_block_hash == deserialized_copy.0);
|
|
|
|
assert!(monitor == deserialized_copy.1);
|
2018-09-19 13:31:14 -04:00
|
|
|
w.0.clear();
|
|
|
|
monitor.write_for_watchtower(&mut w).unwrap();
|
2018-07-16 21:12:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "afl")]
|
2018-08-16 14:20:34 -04:00
|
|
|
#[macro_use] extern crate afl;
|
2018-07-16 21:12:54 -07:00
|
|
|
#[cfg(feature = "afl")]
|
|
|
|
fn main() {
|
2018-08-16 14:20:34 -04:00
|
|
|
fuzz!(|data| {
|
|
|
|
do_test(data);
|
2018-07-16 21:12:54 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "honggfuzz")]
|
|
|
|
#[macro_use] extern crate honggfuzz;
|
|
|
|
#[cfg(feature = "honggfuzz")]
|
|
|
|
fn main() {
|
|
|
|
loop {
|
|
|
|
fuzz!(|data| {
|
|
|
|
do_test(data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-28 09:44:15 -07:00
|
|
|
extern crate hex;
|
2018-07-16 21:12:54 -07:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn duplicate_crash() {
|
2018-07-28 09:44:15 -07:00
|
|
|
super::do_test(&::hex::decode("00").unwrap());
|
2018-07-16 21:12:54 -07:00
|
|
|
}
|
|
|
|
}
|