2018-05-08 21:57:20 +09:00
|
|
|
extern crate lightning;
|
|
|
|
|
|
|
|
use lightning::ln::msgs;
|
|
|
|
use lightning::util::reset_rng_state;
|
|
|
|
|
|
|
|
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn do_test(data: &[u8]) {
|
|
|
|
reset_rng_state();
|
2018-08-26 16:35:26 -04:00
|
|
|
if let Ok(msg) = msgs::UpdateAddHTLC::decode(data){
|
|
|
|
let enc = msg.encode();
|
|
|
|
assert_eq!(&data[0..85], &enc[0..85]);
|
|
|
|
assert_eq!(&data[85+33..enc.len()], &enc[85+33..]);
|
|
|
|
}
|
2018-05-08 21:57:20 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "afl")]
|
2018-08-16 14:20:34 -04:00
|
|
|
#[macro_use] extern crate afl;
|
2018-05-08 21:57:20 +09:00
|
|
|
#[cfg(feature = "afl")]
|
|
|
|
fn main() {
|
2018-08-16 14:20:34 -04:00
|
|
|
fuzz!(|data| {
|
|
|
|
do_test(data);
|
2018-05-08 21:57:20 +09: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-05-08 21:57:20 +09: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-05-08 21:57:20 +09:00
|
|
|
}
|
|
|
|
}
|