From 53df134ab9f55888e36204babb61b5e0c270073d Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 7 Jan 2020 13:58:50 -0500 Subject: [PATCH] Add some basic sanity tests for feature flags --- lightning/src/ln/features.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index d7e0299e8..b87501eb0 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -284,3 +284,38 @@ impl Readable for Features { }) } } + +#[cfg(test)] +mod tests { + use super::{ChannelFeatures, InitFeatures, NodeFeatures}; + + #[test] + fn sanity_test_our_features() { + assert!(!ChannelFeatures::supported().requires_unknown_bits()); + assert!(!ChannelFeatures::supported().supports_unknown_bits()); + assert!(!InitFeatures::supported().requires_unknown_bits()); + assert!(!InitFeatures::supported().supports_unknown_bits()); + assert!(!NodeFeatures::supported().requires_unknown_bits()); + assert!(!NodeFeatures::supported().supports_unknown_bits()); + + assert!(InitFeatures::supported().supports_upfront_shutdown_script()); + assert!(NodeFeatures::supported().supports_upfront_shutdown_script()); + + assert!(InitFeatures::supported().supports_data_loss_protect()); + assert!(NodeFeatures::supported().supports_data_loss_protect()); + + let mut init_features = InitFeatures::supported(); + init_features.set_initial_routing_sync(); + assert!(!init_features.requires_unknown_bits()); + assert!(!init_features.supports_unknown_bits()); + } + + #[test] + fn sanity_test_unkown_bits_testing() { + let mut features = ChannelFeatures::supported(); + features.set_require_unknown_bits(); + assert!(features.requires_unknown_bits()); + features.clear_require_unknown_bits(); + assert!(!features.requires_unknown_bits()); + } +} -- 2.39.5