Skip to content

Commit d94369f

Browse files
committed
ln/refactor: add helper function for channel type tests
1 parent 214a1dd commit d94369f

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

lightning/src/ln/channel.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13125,6 +13125,17 @@ mod tests {
1312513125
fn test_supports_anchors_zero_htlc_tx_fee() {
1312613126
// Tests that if both sides support and negotiate `anchors_zero_fee_htlc_tx`, it is the
1312713127
// resulting `channel_type`.
13128+
let mut config = UserConfig::default();
13129+
config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
13130+
13131+
let mut expected_channel_type = ChannelTypeFeatures::empty();
13132+
expected_channel_type.set_static_remote_key_required();
13133+
expected_channel_type.set_anchors_zero_fee_htlc_tx_required();
13134+
13135+
do_test_supports_channel_type(config, expected_channel_type)
13136+
}
13137+
13138+
fn do_test_supports_channel_type(config: UserConfig, expected_channel_type: ChannelTypeFeatures) {
1312813139
let secp_ctx = Secp256k1::new();
1312913140
let fee_estimator = LowerBoundedFeeEstimator::new(&TestFeeEstimator{fee_est: 15000});
1313013141
let network = Network::Testnet;
@@ -13134,21 +13145,14 @@ mod tests {
1313413145
let node_id_a = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[1; 32]).unwrap());
1313513146
let node_id_b = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[2; 32]).unwrap());
1313613147

13137-
let mut config = UserConfig::default();
13138-
config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
13139-
13140-
// It is not enough for just the initiator to signal `option_anchors_zero_fee_htlc_tx`, both
13141-
// need to signal it.
13148+
// Assert that we don't get the target channel type when the receiving node does not signal
13149+
// support.
1314213150
let channel_a = OutboundV1Channel::<&TestKeysInterface>::new(
1314313151
&fee_estimator, &&keys_provider, &&keys_provider, node_id_b,
1314413152
&channelmanager::provided_init_features(&UserConfig::default()), 10000000, 100000, 42,
1314513153
&config, 0, 42, None, &logger
1314613154
).unwrap();
13147-
assert!(!channel_a.funding.get_channel_type().supports_anchors_zero_fee_htlc_tx());
13148-
13149-
let mut expected_channel_type = ChannelTypeFeatures::empty();
13150-
expected_channel_type.set_static_remote_key_required();
13151-
expected_channel_type.set_anchors_zero_fee_htlc_tx_required();
13155+
assert!(channel_a.funding.get_channel_type() != &expected_channel_type);
1315213156

1315313157
let mut channel_a = OutboundV1Channel::<&TestKeysInterface>::new(
1315413158
&fee_estimator, &&keys_provider, &&keys_provider, node_id_b,

0 commit comments

Comments
 (0)