+ // Check that cleared flags are kept blank when converting back:
+ // - initial_routing_sync was not applicable to NodeContext
+ // - upfront_shutdown_script was cleared before converting
+ // - gossip_queries was cleared before converting
+ let features: InitFeatures = node_features.to_context_internal();
+ assert!(!features.initial_routing_sync());
+ assert!(!features.supports_upfront_shutdown_script());
+ assert!(!init_features.supports_gossip_queries());
+ }
+
+ #[test]
+ fn convert_to_context_with_unknown_flags() {
+ // Ensure the `from` context has fewer known feature bytes than the `to` context.
+ assert!(InvoiceFeatures::known().flags.len() < NodeFeatures::known().flags.len());
+ let invoice_features = InvoiceFeatures::known().set_unknown_feature_optional();
+ assert!(invoice_features.supports_unknown_bits());
+ let node_features: NodeFeatures = invoice_features.to_context();
+ assert!(!node_features.supports_unknown_bits());
+ }
+
+ #[test]
+ fn set_feature_bits() {
+ let features = InvoiceFeatures::empty()
+ .set_basic_mpp_optional()
+ .set_payment_secret_required();
+ assert!(features.supports_basic_mpp());
+ assert!(!features.requires_basic_mpp());
+ assert!(features.requires_payment_secret());
+ assert!(features.supports_payment_secret());
+ }
+
+ #[test]
+ fn invoice_features_encoding() {
+ let features_as_u5s = vec![
+ u5::try_from_u8(6).unwrap(),
+ u5::try_from_u8(10).unwrap(),
+ u5::try_from_u8(25).unwrap(),
+ u5::try_from_u8(1).unwrap(),
+ u5::try_from_u8(10).unwrap(),
+ u5::try_from_u8(0).unwrap(),
+ u5::try_from_u8(20).unwrap(),
+ u5::try_from_u8(2).unwrap(),
+ u5::try_from_u8(0).unwrap(),
+ u5::try_from_u8(6).unwrap(),
+ u5::try_from_u8(0).unwrap(),
+ u5::try_from_u8(16).unwrap(),
+ u5::try_from_u8(1).unwrap(),
+ ];
+ let features = InvoiceFeatures::from_le_bytes(vec![1, 2, 3, 4, 5, 42, 100, 101]);
+
+ // Test length calculation.
+ assert_eq!(features.base32_len(), 13);
+
+ // Test serialization.
+ let features_serialized = features.to_base32();
+ assert_eq!(features_as_u5s, features_serialized);
+
+ // Test deserialization.
+ let features_deserialized = InvoiceFeatures::from_base32(&features_as_u5s).unwrap();
+ assert_eq!(features, features_deserialized);
+ }
+
+ #[test]
+ fn test_channel_type_mapping() {
+ // If we map an InvoiceFeatures with StaticRemoteKey optional, it should map into a
+ // required-StaticRemoteKey ChannelTypeFeatures.
+ let init_features = InitFeatures::empty().set_static_remote_key_optional();
+ let converted_features = ChannelTypeFeatures::from_counterparty_init(&init_features);
+ assert_eq!(converted_features, ChannelTypeFeatures::only_static_remote_key());
+ assert!(!converted_features.supports_any_optional_bits());
+ assert!(converted_features.requires_static_remote_key());