Skip to content

Commit 1c8291f

Browse files
committed
ln/format: run rust fmt on channel_type_tests
1 parent 4fd7eb2 commit 1c8291f

File tree

1 file changed

+201
-67
lines changed

1 file changed

+201
-67
lines changed
Lines changed: 201 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
#![cfg_attr(rustfmt, rustfmt_skip)]
2-
3-
use bitcoin::constants::ChainHash;
4-
use bitcoin::network::Network;
5-
use lightning_types::features::{ChannelTypeFeatures, InitFeatures};
6-
use crate::ln::channel::{OutboundV1Channel, InboundV1Channel};
71
use crate::chain::chaininterface::LowerBoundedFeeEstimator;
8-
use bitcoin::secp256k1::{SecretKey, PublicKey};
2+
use crate::ln::channel::{InboundV1Channel, OutboundV1Channel};
93
use crate::ln::channelmanager;
4+
use crate::prelude::*;
105
use crate::util::config::UserConfig;
116
use crate::util::test_utils::{TestFeeEstimator, TestKeysInterface, TestLogger};
12-
use bitcoin::secp256k1::Secp256k1;
13-
use crate::prelude::*;
7+
use bitcoin::constants::ChainHash;
8+
use bitcoin::network::Network;
9+
use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
10+
use lightning_types::features::{ChannelTypeFeatures, InitFeatures};
1411

1512
#[test]
1613
fn test_zero_conf_channel_type_support() {
@@ -22,20 +19,48 @@ fn test_zero_conf_channel_type_support() {
2219
let keys_provider = TestKeysInterface::new(&seed, network);
2320
let logger = TestLogger::new();
2421

25-
let node_b_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
22+
let node_b_node_id =
23+
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
2624
let config = UserConfig::default();
27-
let mut node_a_chan = OutboundV1Channel::<&TestKeysInterface>::new(&feeest, &&keys_provider, &&keys_provider,
28-
node_b_node_id, &channelmanager::provided_init_features(&config), 10000000, 100000, 42, &config, 0, 42, None, &logger).unwrap();
25+
let mut node_a_chan = OutboundV1Channel::<&TestKeysInterface>::new(
26+
&feeest,
27+
&&keys_provider,
28+
&&keys_provider,
29+
node_b_node_id,
30+
&channelmanager::provided_init_features(&config),
31+
10000000,
32+
100000,
33+
42,
34+
&config,
35+
0,
36+
42,
37+
None,
38+
&logger,
39+
)
40+
.unwrap();
2941

3042
let mut channel_type_features = ChannelTypeFeatures::only_static_remote_key();
3143
channel_type_features.set_zero_conf_required();
3244

33-
let mut open_channel_msg = node_a_chan.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
45+
let mut open_channel_msg =
46+
node_a_chan.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
3447
open_channel_msg.common_fields.channel_type = Some(channel_type_features);
35-
let node_b_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap());
36-
let res = InboundV1Channel::<&TestKeysInterface>::new(&feeest, &&keys_provider, &&keys_provider,
37-
node_b_node_id, &channelmanager::provided_channel_type_features(&config),
38-
&channelmanager::provided_init_features(&config), &open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false);
48+
let node_b_node_id =
49+
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap());
50+
let res = InboundV1Channel::<&TestKeysInterface>::new(
51+
&feeest,
52+
&&keys_provider,
53+
&&keys_provider,
54+
node_b_node_id,
55+
&channelmanager::provided_channel_type_features(&config),
56+
&channelmanager::provided_init_features(&config),
57+
&open_channel_msg,
58+
7,
59+
&config,
60+
0,
61+
&&logger,
62+
/*is_0conf=*/ false,
63+
);
3964
assert!(res.is_ok());
4065
}
4166

@@ -50,37 +75,72 @@ fn test_supports_anchors_zero_htlc_tx_fee() {
5075
let keys_provider = TestKeysInterface::new(&[42; 32], network);
5176
let logger = TestLogger::new();
5277

53-
let node_id_a = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[1; 32]).unwrap());
54-
let node_id_b = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[2; 32]).unwrap());
78+
let node_id_a =
79+
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[1; 32]).unwrap());
80+
let node_id_b =
81+
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[2; 32]).unwrap());
5582

5683
let mut config = UserConfig::default();
5784
config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
5885

5986
// It is not enough for just the initiator to signal `option_anchors_zero_fee_htlc_tx`, both
6087
// need to signal it.
6188
let channel_a = OutboundV1Channel::<&TestKeysInterface>::new(
62-
&fee_estimator, &&keys_provider, &&keys_provider, node_id_b,
63-
&channelmanager::provided_init_features(&UserConfig::default()), 10000000, 100000, 42,
64-
&config, 0, 42, None, &logger
65-
).unwrap();
89+
&fee_estimator,
90+
&&keys_provider,
91+
&&keys_provider,
92+
node_id_b,
93+
&channelmanager::provided_init_features(&UserConfig::default()),
94+
10000000,
95+
100000,
96+
42,
97+
&config,
98+
0,
99+
42,
100+
None,
101+
&logger,
102+
)
103+
.unwrap();
66104
assert!(!channel_a.funding.get_channel_type().supports_anchors_zero_fee_htlc_tx());
67105

68106
let mut expected_channel_type = ChannelTypeFeatures::empty();
69107
expected_channel_type.set_static_remote_key_required();
70108
expected_channel_type.set_anchors_zero_fee_htlc_tx_required();
71109

72110
let mut channel_a = OutboundV1Channel::<&TestKeysInterface>::new(
73-
&fee_estimator, &&keys_provider, &&keys_provider, node_id_b,
74-
&channelmanager::provided_init_features(&config), 10000000, 100000, 42, &config, 0, 42,
75-
None, &logger
76-
).unwrap();
77-
78-
let open_channel_msg = channel_a.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
111+
&fee_estimator,
112+
&&keys_provider,
113+
&&keys_provider,
114+
node_id_b,
115+
&channelmanager::provided_init_features(&config),
116+
10000000,
117+
100000,
118+
42,
119+
&config,
120+
0,
121+
42,
122+
None,
123+
&logger,
124+
)
125+
.unwrap();
126+
127+
let open_channel_msg =
128+
channel_a.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
79129
let channel_b = InboundV1Channel::<&TestKeysInterface>::new(
80-
&fee_estimator, &&keys_provider, &&keys_provider, node_id_a,
81-
&channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config),
82-
&open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false
83-
).unwrap();
130+
&fee_estimator,
131+
&&keys_provider,
132+
&&keys_provider,
133+
node_id_a,
134+
&channelmanager::provided_channel_type_features(&config),
135+
&channelmanager::provided_init_features(&config),
136+
&open_channel_msg,
137+
7,
138+
&config,
139+
0,
140+
&&logger,
141+
/*is_0conf=*/ false,
142+
)
143+
.unwrap();
84144

85145
assert_eq!(channel_a.funding.get_channel_type(), &expected_channel_type);
86146
assert_eq!(channel_b.funding.get_channel_type(), &expected_channel_type);
@@ -97,33 +157,57 @@ fn test_rejects_implicit_simple_anchors() {
97157
let keys_provider = TestKeysInterface::new(&[42; 32], network);
98158
let logger = TestLogger::new();
99159

100-
let node_id_a = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[1; 32]).unwrap());
101-
let node_id_b = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[2; 32]).unwrap());
160+
let node_id_a =
161+
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[1; 32]).unwrap());
162+
let node_id_b =
163+
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[2; 32]).unwrap());
102164

103165
let config = UserConfig::default();
104166

105167
// See feature bit assignments: https://github.com/lightning/bolts/blob/master/09-features.md
106168
let static_remote_key_required: u64 = 1 << 12;
107169
let simple_anchors_required: u64 = 1 << 20;
108170
let raw_init_features = static_remote_key_required | simple_anchors_required;
109-
let init_features_with_simple_anchors = InitFeatures::from_le_bytes(raw_init_features.to_le_bytes().to_vec());
171+
let init_features_with_simple_anchors =
172+
InitFeatures::from_le_bytes(raw_init_features.to_le_bytes().to_vec());
110173

111174
let mut channel_a = OutboundV1Channel::<&TestKeysInterface>::new(
112-
&fee_estimator, &&keys_provider, &&keys_provider, node_id_b,
113-
&channelmanager::provided_init_features(&config), 10000000, 100000, 42, &config, 0, 42,
114-
None, &logger
115-
).unwrap();
175+
&fee_estimator,
176+
&&keys_provider,
177+
&&keys_provider,
178+
node_id_b,
179+
&channelmanager::provided_init_features(&config),
180+
10000000,
181+
100000,
182+
42,
183+
&config,
184+
0,
185+
42,
186+
None,
187+
&logger,
188+
)
189+
.unwrap();
116190

117191
// Set `channel_type` to `None` to force the implicit feature negotiation.
118-
let mut open_channel_msg = channel_a.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
192+
let mut open_channel_msg =
193+
channel_a.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
119194
open_channel_msg.common_fields.channel_type = None;
120195

121196
// Since A supports both `static_remote_key` and `option_anchors`, but B only accepts
122197
// `static_remote_key`, it will fail the channel.
123198
let channel_b = InboundV1Channel::<&TestKeysInterface>::new(
124-
&fee_estimator, &&keys_provider, &&keys_provider, node_id_a,
125-
&channelmanager::provided_channel_type_features(&config), &init_features_with_simple_anchors,
126-
&open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false
199+
&fee_estimator,
200+
&&keys_provider,
201+
&&keys_provider,
202+
node_id_a,
203+
&channelmanager::provided_channel_type_features(&config),
204+
&init_features_with_simple_anchors,
205+
&open_channel_msg,
206+
7,
207+
&config,
208+
0,
209+
&&logger,
210+
/*is_0conf=*/ false,
127211
);
128212
assert!(channel_b.is_err());
129213
}
@@ -139,36 +223,61 @@ fn test_rejects_simple_anchors_channel_type() {
139223
let keys_provider = TestKeysInterface::new(&[42; 32], network);
140224
let logger = TestLogger::new();
141225

142-
let node_id_a = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[1; 32]).unwrap());
143-
let node_id_b = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[2; 32]).unwrap());
226+
let node_id_a =
227+
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[1; 32]).unwrap());
228+
let node_id_b =
229+
PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[2; 32]).unwrap());
144230

145231
let config = UserConfig::default();
146232

147233
// See feature bit assignments: https://github.com/lightning/bolts/blob/master/09-features.md
148234
let static_remote_key_required: u64 = 1 << 12;
149235
let simple_anchors_required: u64 = 1 << 20;
150236
let simple_anchors_raw_features = static_remote_key_required | simple_anchors_required;
151-
let simple_anchors_init = InitFeatures::from_le_bytes(simple_anchors_raw_features.to_le_bytes().to_vec());
152-
let simple_anchors_channel_type = ChannelTypeFeatures::from_le_bytes(simple_anchors_raw_features.to_le_bytes().to_vec());
237+
let simple_anchors_init =
238+
InitFeatures::from_le_bytes(simple_anchors_raw_features.to_le_bytes().to_vec());
239+
let simple_anchors_channel_type =
240+
ChannelTypeFeatures::from_le_bytes(simple_anchors_raw_features.to_le_bytes().to_vec());
153241
assert!(!simple_anchors_init.requires_unknown_bits());
154242
assert!(!simple_anchors_channel_type.requires_unknown_bits());
155243

156244
// First, we'll try to open a channel between A and B where A requests a channel type for
157245
// the original `option_anchors` feature (non zero fee htlc tx). This should be rejected by
158246
// B as it's not supported by LDK.
159247
let mut channel_a = OutboundV1Channel::<&TestKeysInterface>::new(
160-
&fee_estimator, &&keys_provider, &&keys_provider, node_id_b,
161-
&channelmanager::provided_init_features(&config), 10000000, 100000, 42, &config, 0, 42,
162-
None, &logger
163-
).unwrap();
164-
165-
let mut open_channel_msg = channel_a.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
248+
&fee_estimator,
249+
&&keys_provider,
250+
&&keys_provider,
251+
node_id_b,
252+
&channelmanager::provided_init_features(&config),
253+
10000000,
254+
100000,
255+
42,
256+
&config,
257+
0,
258+
42,
259+
None,
260+
&logger,
261+
)
262+
.unwrap();
263+
264+
let mut open_channel_msg =
265+
channel_a.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
166266
open_channel_msg.common_fields.channel_type = Some(simple_anchors_channel_type.clone());
167267

168268
let res = InboundV1Channel::<&TestKeysInterface>::new(
169-
&fee_estimator, &&keys_provider, &&keys_provider, node_id_a,
170-
&channelmanager::provided_channel_type_features(&config), &simple_anchors_init,
171-
&open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false
269+
&fee_estimator,
270+
&&keys_provider,
271+
&&keys_provider,
272+
node_id_a,
273+
&channelmanager::provided_channel_type_features(&config),
274+
&simple_anchors_init,
275+
&open_channel_msg,
276+
7,
277+
&config,
278+
0,
279+
&&logger,
280+
/*is_0conf=*/ false,
172281
);
173282
assert!(res.is_err());
174283

@@ -177,23 +286,48 @@ fn test_rejects_simple_anchors_channel_type() {
177286
// original `option_anchors` feature, which should be rejected by A as it's not supported by
178287
// LDK.
179288
let mut channel_a = OutboundV1Channel::<&TestKeysInterface>::new(
180-
&fee_estimator, &&keys_provider, &&keys_provider, node_id_b, &simple_anchors_init,
181-
10000000, 100000, 42, &config, 0, 42, None, &logger
182-
).unwrap();
183-
184-
let open_channel_msg = channel_a.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
289+
&fee_estimator,
290+
&&keys_provider,
291+
&&keys_provider,
292+
node_id_b,
293+
&simple_anchors_init,
294+
10000000,
295+
100000,
296+
42,
297+
&config,
298+
0,
299+
42,
300+
None,
301+
&logger,
302+
)
303+
.unwrap();
304+
305+
let open_channel_msg =
306+
channel_a.get_open_channel(ChainHash::using_genesis_block(network), &&logger).unwrap();
185307

186308
let mut channel_b = InboundV1Channel::<&TestKeysInterface>::new(
187-
&fee_estimator, &&keys_provider, &&keys_provider, node_id_a,
188-
&channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config),
189-
&open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false
190-
).unwrap();
309+
&fee_estimator,
310+
&&keys_provider,
311+
&&keys_provider,
312+
node_id_a,
313+
&channelmanager::provided_channel_type_features(&config),
314+
&channelmanager::provided_init_features(&config),
315+
&open_channel_msg,
316+
7,
317+
&config,
318+
0,
319+
&&logger,
320+
/*is_0conf=*/ false,
321+
)
322+
.unwrap();
191323

192324
let mut accept_channel_msg = channel_b.get_accept_channel_message(&&logger).unwrap();
193325
accept_channel_msg.common_fields.channel_type = Some(simple_anchors_channel_type.clone());
194326

195327
let res = channel_a.accept_channel(
196-
&accept_channel_msg, &config.channel_handshake_limits, &simple_anchors_init
328+
&accept_channel_msg,
329+
&config.channel_handshake_limits,
330+
&simple_anchors_init,
197331
);
198332
assert!(res.is_err());
199333
}

0 commit comments

Comments
 (0)