Skip to content

Commit 7c92614

Browse files
committed
Remove explicit use of Channel variants from tests
The old ChannelPhase variants will be used internally in Channel, so they should no longer be used elsewhere.
1 parent 17b4972 commit 7c92614

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

lightning/src/ln/channel.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,11 @@ impl<SP: Deref> Channel<SP> where
11931193
}
11941194
}
11951195

1196+
#[cfg(test)]
1197+
pub fn is_unfunded_v1(&self) -> bool {
1198+
matches!(self, Channel::UnfundedOutboundV1(_) | Channel::UnfundedInboundV1(_))
1199+
}
1200+
11961201
pub fn is_unfunded_outbound_v1(&self) -> bool {
11971202
matches!(self, Channel::UnfundedOutboundV1(_))
11981203
}

lightning/src/ln/functional_tests.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,11 @@ fn do_test_counterparty_no_reserve(send_from_initiator: bool) {
215215
let mut sender_node_per_peer_lock;
216216
let mut sender_node_peer_state_lock;
217217

218-
let channel_phase = get_channel_ref!(sender_node, counterparty_node, sender_node_per_peer_lock, sender_node_peer_state_lock, temp_channel_id);
219-
match channel_phase {
220-
Channel::UnfundedInboundV1(_) | Channel::UnfundedOutboundV1(_) => {
221-
let chan_context = channel_phase.context_mut();
222-
chan_context.holder_selected_channel_reserve_satoshis = 0;
223-
chan_context.holder_max_htlc_value_in_flight_msat = 100_000_000;
224-
},
225-
_ => assert!(false),
226-
}
218+
let channel = get_channel_ref!(sender_node, counterparty_node, sender_node_per_peer_lock, sender_node_peer_state_lock, temp_channel_id);
219+
assert!(channel.is_unfunded_v1());
220+
let chan_context = channel.context_mut();
221+
chan_context.holder_selected_channel_reserve_satoshis = 0;
222+
chan_context.holder_max_htlc_value_in_flight_msat = 100_000_000;
227223
}
228224

229225
let funding_tx = sign_funding_transaction(&nodes[0], &nodes[1], 100_000, temp_channel_id);
@@ -9501,12 +9497,12 @@ fn test_duplicate_chan_id() {
95019497
// another channel in the ChannelManager - an invalid state. Thus, we'd panic later when we
95029498
// try to create another channel. Instead, we drop the channel entirely here (leaving the
95039499
// channelmanager in a possibly nonsense state instead).
9504-
match a_peer_state.channel_by_id.remove(&open_chan_2_msg.common_fields.temporary_channel_id).unwrap() {
9505-
Channel::UnfundedOutboundV1(mut chan) => {
9506-
let logger = test_utils::TestLogger::new();
9507-
chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap()
9508-
},
9509-
_ => panic!("Unexpected Channel variant"),
9500+
let mut channel = a_peer_state.channel_by_id.remove(&open_chan_2_msg.common_fields.temporary_channel_id).unwrap();
9501+
if let Some(mut chan) = channel.as_unfunded_outbound_v1_mut() {
9502+
let logger = test_utils::TestLogger::new();
9503+
chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap()
9504+
} else {
9505+
panic!("Unexpected Channel variant")
95109506
}.unwrap()
95119507
};
95129508
check_added_monitors!(nodes[0], 0);
@@ -10207,11 +10203,11 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e
1020710203
if on_holder_tx {
1020810204
let mut node_0_per_peer_lock;
1020910205
let mut node_0_peer_state_lock;
10210-
match get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, temporary_channel_id) {
10211-
Channel::UnfundedOutboundV1(chan) => {
10212-
chan.context.holder_dust_limit_satoshis = 546;
10213-
},
10214-
_ => panic!("Unexpected Channel variant"),
10206+
let channel = get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, temporary_channel_id);
10207+
if let Some(mut chan) = channel.as_unfunded_outbound_v1_mut() {
10208+
chan.context.holder_dust_limit_satoshis = 546;
10209+
} else {
10210+
panic!("Unexpected Channel variant");
1021510211
}
1021610212
}
1021710213

0 commit comments

Comments
 (0)