Document Channel::get_funding_redeemscript precondition
[rust-lightning] / fuzz / fuzz_targets / channel_target.rs
index 903b45fbcf703e5999c91d4d0b085e7c1d12b50e..7b3b7df1ce2ec3ddcc039212e92352bddef8b246 100644 (file)
@@ -8,7 +8,7 @@ use bitcoin::util::hash::Sha256dHash;
 use bitcoin::network::serialize::{serialize, BitcoinHash};
 
 use lightning::ln::channel::{Channel, ChannelKeys};
-use lightning::ln::channelmanager::{HTLCFailReason, PendingForwardHTLCInfo};
+use lightning::ln::channelmanager::{HTLCFailReason, PendingHTLCStatus};
 use lightning::ln::msgs;
 use lightning::ln::msgs::{MsgDecodable, ErrorAction};
 use lightning::chain::chaininterface::{FeeEstimator, ConfirmationTarget};
@@ -124,6 +124,7 @@ pub fn do_test(data: &[u8]) {
                                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,
@@ -146,6 +147,7 @@ pub fn do_test(data: &[u8]) {
                                        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,
@@ -228,7 +230,7 @@ pub fn do_test(data: &[u8]) {
                        Ok(chan) => chan,
                        Err(_) => return,
                };
-               chan.get_accept_channel().unwrap();
+               chan.get_accept_channel();
 
                tx.output.push(TxOut{ value: open_chan.funding_satoshis, script_pubkey: chan.get_funding_redeemscript().to_v0_p2wsh() });
                let funding_output = OutPoint::new(Sha256dHash::from_data(&serialize(&tx).unwrap()[..]), 0);
@@ -256,7 +258,6 @@ pub fn do_test(data: &[u8]) {
                                Ok(r) => Some(r),
                                Err(e) => match e.action {
                                        None => return,
-                                       Some(ErrorAction::UpdateFailHTLC {..}) => None,
                                        Some(ErrorAction::DisconnectPeer {..}) => return,
                                        Some(ErrorAction::IgnoreError) => None,
                                        Some(ErrorAction::SendErrorMessage {..}) => None,
@@ -270,7 +271,7 @@ pub fn do_test(data: &[u8]) {
                        0 => {
                                test_err!(channel.send_htlc(slice_to_be64(get_slice!(8)), [42; 32], slice_to_be32(get_slice!(4)), msgs::OnionPacket {
                                        version: get_slice!(1)[0],
-                                       public_key: get_pubkey!(),
+                                       public_key: PublicKey::from_slice(&secp_ctx, get_slice!(33)),
                                        hop_data: [0; 20*65],
                                        hmac: [0; 32],
                                }));
@@ -280,7 +281,7 @@ pub fn do_test(data: &[u8]) {
                        },
                        2 => {
                                let update_add_htlc = decode_msg!(msgs::UpdateAddHTLC, 32+8+8+32+4+4+33+20*65+32);
-                               test_err!(channel.update_add_htlc(&update_add_htlc, PendingForwardHTLCInfo::dummy()));
+                               test_err!(channel.update_add_htlc(&update_add_htlc, PendingHTLCStatus::dummy()));
                        },
                        3 => {
                                let update_fulfill_htlc = decode_msg!(msgs::UpdateFulfillHTLC, 32 + 8 + 32);
@@ -325,11 +326,11 @@ pub fn do_test(data: &[u8]) {
 }
 
 #[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);
        });
 }