Skip to content

Commit

Permalink
Test ChannelDetails serialization to catch mutants
Browse files Browse the repository at this point in the history
  • Loading branch information
dunxen committed Aug 20, 2024
1 parent f21e138 commit 76b601e
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions lightning/src/ln/channel_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,3 +715,68 @@ impl_writeable_tlv_based_enum!(ChannelShutdownState,
(6, NegotiatingClosingFee) => {},
(8, ShutdownComplete) => {},
);

#[cfg(test)]
mod tests {
use bitcoin::{hashes::Hash as _, secp256k1::PublicKey};
use lightning_types::features::Features;

use crate::{
chain::transaction::OutPoint,
ln::types::ChannelId,
util::ser::{Readable, Writeable},
};

use super::{ChannelCounterparty, ChannelDetails, ChannelShutdownState};

#[test]
fn test_channel_details_serialization() {
#[allow(deprecated)]
let channel_details = ChannelDetails {
channel_id: ChannelId::new_zero(),
counterparty: ChannelCounterparty {
features: Features::empty(),
node_id: PublicKey::from_slice(&[2; 33]).unwrap(),
unspendable_punishment_reserve: 0,
forwarding_info: None,
outbound_htlc_minimum_msat: None,
outbound_htlc_maximum_msat: None,
},
funding_txo: Some(OutPoint {
txid: bitcoin::Txid::from_slice(&[0; 32]).unwrap(),
index: 0,
}),
channel_type: None,
short_channel_id: None,
outbound_scid_alias: None,
inbound_scid_alias: None,
channel_value_satoshis: 0,
user_channel_id: (u64::MAX as u128) + 1, // Gets us into the high bytes
balance_msat: 0,
outbound_capacity_msat: 0,
next_outbound_htlc_limit_msat: 0,
next_outbound_htlc_minimum_msat: 0,
inbound_capacity_msat: 42,
unspendable_punishment_reserve: None,
confirmations_required: None,
confirmations: None,
force_close_spend_delay: None,
is_outbound: true,
is_channel_ready: true,
is_usable: true,
is_public: true,
inbound_htlc_minimum_msat: None,
inbound_htlc_maximum_msat: None,
config: None,
feerate_sat_per_1000_weight: None,
channel_shutdown_state: Some(ChannelShutdownState::NotShuttingDown),
pending_inbound_htlcs: Vec::new(),
pending_outbound_htlcs: Vec::new(),
};
let mut buffer = Vec::new();
channel_details.write(&mut buffer).unwrap();
let deser_channel_details = ChannelDetails::read(&mut buffer.as_slice()).unwrap();

assert_eq!(deser_channel_details, channel_details);
}
}

0 comments on commit 76b601e

Please sign in to comment.