From a6572442df6f35643b3e73b6e43b307b9543feef Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Fri, 8 Dec 2023 10:20:20 -0800 Subject: [PATCH] Add note and test regarding ChannelState's implicit ordering --- lightning/src/ln/channel.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index b3657701a..ab3bdb98c 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -419,6 +419,8 @@ define_state_flags!( ] ); +// Note that the order of this enum is implicitly defined by where each variant is placed. Take this +// into account when introducing new states and update `test_channel_state_order` accordingly. #[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq)] enum ChannelState { /// We are negotiating the parameters required for the channel prior to funding it. @@ -8374,6 +8376,18 @@ mod tests { use bitcoin::address::{WitnessProgram, WitnessVersion}; use crate::prelude::*; + #[test] + fn test_channel_state_order() { + use crate::ln::channel::NegotiatingFundingFlags; + use crate::ln::channel::AwaitingChannelReadyFlags; + use crate::ln::channel::ChannelReadyFlags; + + assert!(ChannelState::NegotiatingFunding(NegotiatingFundingFlags::new()) < ChannelState::FundingNegotiated); + assert!(ChannelState::FundingNegotiated < ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new())); + assert!(ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new()) < ChannelState::ChannelReady(ChannelReadyFlags::new())); + assert!(ChannelState::ChannelReady(ChannelReadyFlags::new()) < ChannelState::ShutdownComplete); + } + struct TestFeeEstimator { fee_est: u32 } -- 2.39.5