Skip to content

Commit fcdbabf

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 c1a0123 commit fcdbabf

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
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: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,13 @@ fn do_test_counterparty_no_reserve(send_from_initiator: bool) {
214214
let mut sender_node_per_peer_lock;
215215
let mut sender_node_peer_state_lock;
216216

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

@@ -9220,12 +9219,12 @@ fn test_duplicate_chan_id() {
92209219
// another channel in the ChannelManager - an invalid state. Thus, we'd panic later when we
92219220
// try to create another channel. Instead, we drop the channel entirely here (leaving the
92229221
// channelmanager in a possibly nonsense state instead).
9223-
match a_peer_state.channel_by_id.remove(&open_chan_2_msg.common_fields.temporary_channel_id).unwrap() {
9224-
Channel::UnfundedOutboundV1(mut chan) => {
9225-
let logger = test_utils::TestLogger::new();
9226-
chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap()
9227-
},
9228-
_ => panic!("Unexpected Channel variant"),
9222+
let mut channel = a_peer_state.channel_by_id.remove(&open_chan_2_msg.common_fields.temporary_channel_id).unwrap();
9223+
if let Some(mut chan) = channel.as_unfunded_outbound_v1_mut() {
9224+
let logger = test_utils::TestLogger::new();
9225+
chan.get_funding_created(tx.clone(), funding_outpoint, false, &&logger).map_err(|_| ()).unwrap()
9226+
} else {
9227+
panic!("Unexpected Channel variant")
92299228
}.unwrap()
92309229
};
92319230
check_added_monitors!(nodes[0], 0);
@@ -9926,11 +9925,11 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e
99269925
if on_holder_tx {
99279926
let mut node_0_per_peer_lock;
99289927
let mut node_0_peer_state_lock;
9929-
match get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, temporary_channel_id) {
9930-
Channel::UnfundedOutboundV1(chan) => {
9931-
chan.context.holder_dust_limit_satoshis = 546;
9932-
},
9933-
_ => panic!("Unexpected Channel variant"),
9928+
let channel = get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, temporary_channel_id);
9929+
if let Some(mut chan) = channel.as_unfunded_outbound_v1_mut() {
9930+
chan.context.holder_dust_limit_satoshis = 546;
9931+
} else {
9932+
panic!("Unexpected Channel variant");
99349933
}
99359934
}
99369935

0 commit comments

Comments
 (0)