Skip to content

Commit

Permalink
Add some checks for the new field
Browse files Browse the repository at this point in the history
  • Loading branch information
optout21 committed Dec 19, 2023
1 parent c570853 commit 702c374
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 6 additions & 1 deletion lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,7 @@ pub struct ExpectedCloseEvent {
pub counterparty_node_id: Option<PublicKey>,
pub discard_funding: bool,
pub reason: Option<ClosureReason>,
pub channel_funding_txo: Option<OutPoint>,
}

impl ExpectedCloseEvent {
Expand All @@ -1544,6 +1545,7 @@ impl ExpectedCloseEvent {
counterparty_node_id: None,
discard_funding,
reason: Some(reason),
channel_funding_txo: None,
}
}
}
Expand All @@ -1562,12 +1564,14 @@ pub fn check_closed_events(node: &Node, expected_close_events: &[ExpectedCloseEv
reason,
counterparty_node_id,
channel_capacity_sats,
channel_funding_txo,
..
} if (
expected_event.channel_id.map(|expected| *channel_id == expected).unwrap_or(true) &&
expected_event.reason.as_ref().map(|expected| reason == expected).unwrap_or(true) &&
expected_event.counterparty_node_id.map(|expected| *counterparty_node_id == Some(expected)).unwrap_or(true) &&
expected_event.channel_capacity_sats.map(|expected| *channel_capacity_sats == Some(expected)).unwrap_or(true)
expected_event.channel_capacity_sats.map(|expected| *channel_capacity_sats == Some(expected)).unwrap_or(true) &&
expected_event.channel_funding_txo.map(|expected| *channel_funding_txo == Some(expected)).unwrap_or(true)
)
)));
}
Expand All @@ -1592,6 +1596,7 @@ pub fn check_closed_event(node: &Node, events_count: usize, expected_reason: Clo
counterparty_node_id: Some(*node_id),
discard_funding: is_check_discard_funding,
reason: Some(expected_reason.clone()),
channel_funding_txo: None,
}).collect::<Vec<_>>();
check_closed_events(node, expected_close_events.as_slice());
}
Expand Down
16 changes: 12 additions & 4 deletions lightning/src/ln/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10596,17 +10596,21 @@ fn test_disconnect_in_funding_batch() {
nodes[0].node.peer_disconnected(&nodes[2].node.get_our_node_id());

// The channels in the batch will close immediately.
let channel_id_1 = OutPoint { txid: tx.txid(), index: 0 }.to_channel_id();
let channel_id_2 = OutPoint { txid: tx.txid(), index: 1 }.to_channel_id();
let funding_txo_1 = OutPoint { txid: tx.txid(), index: 0 };
let funding_txo_2 = OutPoint { txid: tx.txid(), index: 1 };
let channel_id_1 = funding_txo_1.to_channel_id();
let channel_id_2 = funding_txo_2.to_channel_id();
check_closed_events(&nodes[0], &[
ExpectedCloseEvent {
channel_id: Some(channel_id_1),
discard_funding: true,
channel_funding_txo: Some(funding_txo_1),
..Default::default()
},
ExpectedCloseEvent {
channel_id: Some(channel_id_2),
discard_funding: true,
channel_funding_txo: Some(funding_txo_2),
..Default::default()
},
]);
Expand Down Expand Up @@ -10664,8 +10668,10 @@ fn test_batch_funding_close_after_funding_signed() {
assert_eq!(nodes[0].tx_broadcaster.txn_broadcast().len(), 0);

// Force-close the channel for which we've completed the initial monitor.
let channel_id_1 = OutPoint { txid: tx.txid(), index: 0 }.to_channel_id();
let channel_id_2 = OutPoint { txid: tx.txid(), index: 1 }.to_channel_id();
let funding_txo_1 = OutPoint { txid: tx.txid(), index: 0 };
let funding_txo_2 = OutPoint { txid: tx.txid(), index: 1 };
let channel_id_1 = funding_txo_1.to_channel_id();
let channel_id_2 = funding_txo_2.to_channel_id();
nodes[0].node.force_close_broadcasting_latest_txn(&channel_id_1, &nodes[1].node.get_our_node_id()).unwrap();
check_added_monitors(&nodes[0], 2);
{
Expand Down Expand Up @@ -10697,11 +10703,13 @@ fn test_batch_funding_close_after_funding_signed() {
ExpectedCloseEvent {
channel_id: Some(channel_id_1),
discard_funding: true,
channel_funding_txo: Some(funding_txo_1),
..Default::default()
},
ExpectedCloseEvent {
channel_id: Some(channel_id_2),
discard_funding: true,
channel_funding_txo: Some(funding_txo_2),
..Default::default()
},
]);
Expand Down

0 comments on commit 702c374

Please sign in to comment.