]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add some basic sanity tests for feature flags 2020-01-feature-sanity
authorMatt Corallo <git@bluematt.me>
Tue, 7 Jan 2020 18:58:50 +0000 (13:58 -0500)
committerMatt Corallo <git@bluematt.me>
Wed, 12 Feb 2020 22:16:42 +0000 (17:16 -0500)
lightning/src/ln/features.rs

index 4f45b9338c62c4e84c03e5223abcb248717e195e..61a862c0c55c71bb62975fc8dd4360a1e3f7f5bf 100644 (file)
@@ -293,3 +293,41 @@ impl<R: ::std::io::Read, T: sealed::Context> Readable<R> for Features<T> {
                })
        }
 }
+
+#[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());
+
+               assert!(InitFeatures::supported().supports_variable_length_onion());
+               assert!(NodeFeatures::supported().supports_variable_length_onion());
+
+               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());
+       }
+}