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,112 @@ 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+ // announce_for_forwarding = false is required, but set by UserConfig::default().
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+ #[ test]
52+ fn test_option_zero_fee_commitments_initial ( ) {
53+ let mut expected_type = ChannelTypeFeatures :: empty ( ) ;
54+ expected_type. set_anchor_zero_fee_commitments_required ( ) ;
55+
56+ do_test_get_initial_channel_type (
57+ UserConfig :: default ( ) ,
58+ InitFeatures :: empty ( ) ,
59+ ChannelTypeFeatures :: only_static_remote_key ( ) ,
60+ |cfg : & mut UserConfig | {
61+ cfg. channel_handshake_config . negotiate_anchor_zero_fee_commitments = true ;
62+ } ,
63+ |their_features : & mut InitFeatures | {
64+ their_features. set_anchor_zero_fee_commitments_optional ( ) ;
65+ } ,
66+ expected_type,
67+ )
68+ }
69+
70+ #[ test]
71+ fn test_option_zero_fee_commitments_from_zero_htlc_anchors_initial ( ) {
72+ let mut start_cfg = UserConfig :: default ( ) ;
73+ start_cfg. channel_handshake_config . negotiate_anchors_zero_fee_htlc_tx = true ;
74+
75+ let mut start_features = InitFeatures :: empty ( ) ;
76+ start_features. set_anchors_zero_fee_htlc_tx_optional ( ) ;
77+
78+ let mut start_type = ChannelTypeFeatures :: anchors_zero_htlc_fee_and_dependencies ( ) ;
79+
80+ let mut expected_type = ChannelTypeFeatures :: empty ( ) ;
81+ expected_type. set_anchor_zero_fee_commitments_required ( ) ;
82+
83+ do_test_get_initial_channel_type (
84+ start_cfg,
85+ start_features,
86+ start_type,
87+ |cfg : & mut UserConfig | {
88+ cfg. channel_handshake_config . negotiate_anchor_zero_fee_commitments = true ;
89+ } ,
90+ |their_features : & mut InitFeatures | {
91+ their_features. set_anchor_zero_fee_commitments_optional ( ) ;
92+ } ,
93+ expected_type,
94+ )
95+ }
96+
97+ fn do_test_get_initial_channel_type < F1 , F2 > (
98+ start_cfg : UserConfig , start_features : InitFeatures , start_type : ChannelTypeFeatures ,
99+ mut local_cfg_mod : F1 , mut remote_features_mod : F2 , channel_type : ChannelTypeFeatures ,
100+ ) where
101+ F1 : FnOnce ( & mut UserConfig ) ,
102+ F2 : FnOnce ( & mut InitFeatures ) ,
103+ {
104+ // Local node supports feature, remote does not.
105+ let mut config = start_cfg. clone ( ) ;
106+ local_cfg_mod ( & mut config) ;
107+ assert_eq ! ( get_initial_channel_type( & config, & start_features) , start_type) ;
108+
109+ // Remote node supports feature, local does not.
110+ let mut their_features = start_features. clone ( ) ;
111+ remote_features_mod ( & mut their_features) ;
112+ assert_eq ! ( get_initial_channel_type( & start_cfg, & their_features) , start_type) ;
113+
114+ // Both support feature.
115+ assert_eq ! ( get_initial_channel_type( & config, & their_features) , channel_type)
116+ }
117+
12118#[ test]
13119fn test_zero_conf_channel_type_support ( ) {
14120 let test_est = TestFeeEstimator :: new ( 15000 ) ;
0 commit comments