11use crate :: chain:: chaininterface:: LowerBoundedFeeEstimator ;
2- use crate :: ln:: channel:: { InboundV1Channel , OutboundV1Channel } ;
2+ use crate :: ln:: channel:: { get_initial_channel_type , InboundV1Channel , OutboundV1Channel } ;
33use crate :: ln:: channelmanager;
44use crate :: prelude:: * ;
55use crate :: util:: config:: UserConfig ;
@@ -9,6 +9,66 @@ use bitcoin::network::Network;
99use bitcoin:: secp256k1:: { PublicKey , Secp256k1 , SecretKey } ;
1010use lightning_types:: features:: { ChannelTypeFeatures , InitFeatures } ;
1111
12+ #[ test]
13+ fn test_option_scid_privacy_initial ( ) {
14+ let mut expected_type = ChannelTypeFeatures :: only_static_remote_key ( ) ;
15+ expected_type. set_scid_privacy_required ( ) ;
16+
17+ do_test_get_initial_channel_type (
18+ UserConfig :: default ( ) ,
19+ InitFeatures :: empty ( ) ,
20+ ChannelTypeFeatures :: only_static_remote_key ( ) ,
21+ |cfg : & mut UserConfig | {
22+ cfg. channel_handshake_config . announce_for_forwarding = false ;
23+ cfg. channel_handshake_config . negotiate_scid_privacy = true ;
24+ } ,
25+ |their_features : & mut InitFeatures | {
26+ their_features. set_scid_privacy_optional ( ) ;
27+ } ,
28+ expected_type,
29+ )
30+ }
31+
32+ #[ test]
33+ fn test_option_anchors_zero_fee_initial ( ) {
34+ let mut expected_type = ChannelTypeFeatures :: only_static_remote_key ( ) ;
35+ expected_type. set_anchors_zero_fee_htlc_tx_required ( ) ;
36+
37+ do_test_get_initial_channel_type (
38+ UserConfig :: default ( ) ,
39+ InitFeatures :: empty ( ) ,
40+ ChannelTypeFeatures :: only_static_remote_key ( ) ,
41+ |cfg : & mut UserConfig | {
42+ cfg. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx = true ;
43+ } ,
44+ |their_features : & mut InitFeatures | {
45+ their_features. set_anchors_zero_fee_htlc_tx_optional ( ) ;
46+ } ,
47+ expected_type,
48+ )
49+ }
50+
51+ fn do_test_get_initial_channel_type < F1 , F2 > (
52+ start_cfg : UserConfig , start_features : InitFeatures , start_type : ChannelTypeFeatures ,
53+ mut local_cfg_mod : F1 , mut remote_features_mod : F2 , channel_type : ChannelTypeFeatures ,
54+ ) where
55+ F1 : FnOnce ( & mut UserConfig ) ,
56+ F2 : FnOnce ( & mut InitFeatures ) ,
57+ {
58+ // Local node supports feature, remote does not.
59+ let mut config = start_cfg. clone ( ) ;
60+ local_cfg_mod ( & mut config) ;
61+ assert_eq ! ( get_initial_channel_type( & config, & start_features) , start_type) ;
62+
63+ // Remote node supports feature, local does not.
64+ let mut their_features = start_features. clone ( ) ;
65+ remote_features_mod ( & mut their_features) ;
66+ assert_eq ! ( get_initial_channel_type( & start_cfg, & their_features) , start_type) ;
67+
68+ // Both support feature.
69+ assert_eq ! ( get_initial_channel_type( & config, & their_features) , channel_type)
70+ }
71+
1272#[ test]
1373fn test_zero_conf_channel_type_support ( ) {
1474 let test_est = TestFeeEstimator :: new ( 15000 ) ;
0 commit comments