extern crate lightning;
extern crate secp256k1;
+use bitcoin::network::constants::Network;
+
+use lightning::chain::chaininterface;
use lightning::ln::channelmanager::ChannelDetails;
use lightning::ln::msgs;
use lightning::ln::msgs::{MsgDecodable, RoutingMessageHandler};
use lightning::ln::router::{Router, RouteHint};
use lightning::util::reset_rng_state;
+use lightning::util::logger::Logger;
use secp256k1::key::PublicKey;
use secp256k1::Secp256k1;
+mod utils;
+
+use utils::test_logger;
+
+use std::sync::Arc;
+
#[inline]
pub fn slice_to_be16(v: &[u8]) -> u16 {
((v[0] as u16) << 8*1) |
Ok(msg) => msg,
Err(e) => match e {
msgs::DecodeError::UnknownRealmByte => return,
+ msgs::DecodeError::UnknownRequiredFeature => return,
msgs::DecodeError::BadPublicKey => return,
msgs::DecodeError::BadSignature => return,
msgs::DecodeError::BadText => return,
}
}
+ let logger: Arc<Logger> = Arc::new(test_logger::TestLogger{});
+ let chain_monitor = Arc::new(chaininterface::ChainWatchInterfaceUtil::new(Network::Bitcoin, Arc::clone(&logger)));
+
let our_pubkey = get_pubkey!();
- let router = Router::new(our_pubkey.clone());
+ let router = Router::new(our_pubkey.clone(), chain_monitor, Arc::clone(&logger));
loop {
match get_slice!(1)[0] {
last_hops_vec.push(RouteHint {
src_node_id: get_pubkey!(),
short_channel_id: slice_to_be64(get_slice!(8)),
- fee_base_msat: slice_to_be64(get_slice!(8)),
+ fee_base_msat: slice_to_be32(get_slice!(4)),
fee_proportional_millionths: slice_to_be32(get_slice!(4)),
cltv_expiry_delta: slice_to_be16(get_slice!(2)),
htlc_minimum_msat: slice_to_be64(get_slice!(8)),
}
#[cfg(feature = "afl")]
-extern crate afl;
+#[macro_use] extern crate afl;
#[cfg(feature = "afl")]
fn main() {
- afl::read_stdio_bytes(|data| {
- do_test(&data);
+ fuzz!(|data| {
+ do_test(data);
});
}
}
}
+extern crate hex;
#[cfg(test)]
mod tests {
- fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
- let mut b = 0;
- for (idx, c) in hex.as_bytes().iter().enumerate() {
- b <<= 4;
- match *c {
- b'A'...b'F' => b |= c - b'A' + 10,
- b'a'...b'f' => b |= c - b'a' + 10,
- b'0'...b'9' => b |= c - b'0',
- _ => panic!("Bad hex"),
- }
- if (idx & 1) == 1 {
- out.push(b);
- b = 0;
- }
- }
- }
#[test]
fn duplicate_crash() {
- let mut a = Vec::new();
- extend_vec_from_hex("00", &mut a);
- super::do_test(&a);
+ super::do_test(&::hex::decode("00").unwrap());
}
}