+#[derive(Default)]
+pub struct ExpectedCloseEvent {
+ pub channel_capacity_sats: Option<u64>,
+ pub channel_id: Option<ChannelId>,
+ pub counterparty_node_id: Option<PublicKey>,
+ pub discard_funding: bool,
+ pub reason: Option<ClosureReason>,
+ pub channel_funding_txo: Option<OutPoint>,
+ pub user_channel_id: Option<u128>,
+}
+
+impl ExpectedCloseEvent {
+ pub fn from_id_reason(channel_id: ChannelId, discard_funding: bool, reason: ClosureReason) -> Self {
+ Self {
+ channel_capacity_sats: None,
+ channel_id: Some(channel_id),
+ counterparty_node_id: None,
+ discard_funding,
+ reason: Some(reason),
+ channel_funding_txo: None,
+ user_channel_id: None,
+ }
+ }
+}
+
+/// Check that multiple channel closing events have been issued.
+pub fn check_closed_events(node: &Node, expected_close_events: &[ExpectedCloseEvent]) {
+ let closed_events_count = expected_close_events.len();
+ let discard_events_count = expected_close_events.iter().filter(|e| e.discard_funding).count();
+ let events = node.node.get_and_clear_pending_events();
+ assert_eq!(events.len(), closed_events_count + discard_events_count, "{:?}", events);
+ for expected_event in expected_close_events {
+ assert!(events.iter().any(|e| matches!(
+ e,
+ Event::ChannelClosed {
+ channel_id,
+ reason,
+ counterparty_node_id,
+ channel_capacity_sats,
+ channel_funding_txo,
+ user_channel_id,
+ ..
+ } 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_funding_txo
+ .map(|expected| *channel_funding_txo == Some(expected)).unwrap_or(true) &&
+ expected_event.user_channel_id
+ .map(|expected| *user_channel_id == expected).unwrap_or(true)
+ )
+ )));
+ }
+ assert_eq!(events.iter().filter(|e| matches!(
+ e,
+ Event::DiscardFunding { .. },
+ )).count(), discard_events_count);
+}
+