@@ -1478,27 +1478,61 @@ macro_rules! check_closed_broadcast {
1478
1478
}
1479
1479
}
1480
1480
1481
+ #[ derive( Default ) ]
1482
+ pub struct ExpectedCloseEvent {
1483
+ pub channel_capacity_sats : Option < u64 > ,
1484
+ pub channel_id : Option < ChannelId > ,
1485
+ pub counterparty_node_id : Option < PublicKey > ,
1486
+ pub discard_funding : bool ,
1487
+ pub reason : Option < ClosureReason > ,
1488
+ }
1489
+
1490
+ /// Check that multiple channel closing events have been issued.
1491
+ pub fn check_closed_events ( node : & Node , expected_close_events : & [ ExpectedCloseEvent ] ) {
1492
+ let closed_events_count = expected_close_events. len ( ) ;
1493
+ let discard_events_count = expected_close_events. iter ( ) . filter ( |e| e. discard_funding ) . count ( ) ;
1494
+ let events = node. node . get_and_clear_pending_events ( ) ;
1495
+ assert_eq ! ( events. len( ) , closed_events_count + discard_events_count, "{:?}" , events) ;
1496
+ for expected_event in expected_close_events {
1497
+ assert ! ( events. iter( ) . any( |e| matches!(
1498
+ e,
1499
+ Event :: ChannelClosed {
1500
+ channel_id,
1501
+ reason,
1502
+ counterparty_node_id,
1503
+ channel_capacity_sats,
1504
+ ..
1505
+ } if (
1506
+ expected_event. channel_id. map( |expected| * channel_id == expected) . unwrap_or( true ) &&
1507
+ expected_event. reason. as_ref( ) . map( |expected| reason == expected) . unwrap_or( true ) &&
1508
+ expected_event. counterparty_node_id. map( |expected| * counterparty_node_id == Some ( expected) ) . unwrap_or( true ) &&
1509
+ expected_event. channel_capacity_sats. map( |expected| * channel_capacity_sats == Some ( expected) ) . unwrap_or( true )
1510
+ )
1511
+ ) ) ) ;
1512
+ }
1513
+ assert_eq ! ( events. iter( ) . filter( |e| matches!(
1514
+ e,
1515
+ Event :: DiscardFunding { .. } ,
1516
+ ) ) . count( ) , discard_events_count) ;
1517
+ }
1518
+
1481
1519
/// Check that a channel's closing channel events has been issued
1482
1520
pub fn check_closed_event ( node : & Node , events_count : usize , expected_reason : ClosureReason , is_check_discard_funding : bool ,
1483
1521
expected_counterparty_node_ids : & [ PublicKey ] , expected_channel_capacity : u64 ) {
1484
- let events = node. node . get_and_clear_pending_events ( ) ;
1485
- assert_eq ! ( events. len( ) , events_count, "{:?}" , events) ;
1486
- let mut issues_discard_funding = false ;
1487
- for event in events {
1488
- match event {
1489
- Event :: ChannelClosed { ref reason, counterparty_node_id,
1490
- channel_capacity_sats, .. } => {
1491
- assert_eq ! ( * reason, expected_reason) ;
1492
- assert ! ( expected_counterparty_node_ids. iter( ) . any( |id| id == & counterparty_node_id. unwrap( ) ) ) ;
1493
- assert_eq ! ( channel_capacity_sats. unwrap( ) , expected_channel_capacity) ;
1494
- } ,
1495
- Event :: DiscardFunding { .. } => {
1496
- issues_discard_funding = true ;
1497
- }
1498
- _ => panic ! ( "Unexpected event" ) ,
1499
- }
1500
- }
1501
- assert_eq ! ( is_check_discard_funding, issues_discard_funding) ;
1522
+ let expected_events_count = if is_check_discard_funding {
1523
+ 2 * expected_counterparty_node_ids. len ( )
1524
+ } else {
1525
+ expected_counterparty_node_ids. len ( )
1526
+ } ;
1527
+ assert_eq ! ( events_count, expected_events_count) ;
1528
+ let expected_close_events = expected_counterparty_node_ids. iter ( ) . map ( |node_id| ExpectedCloseEvent {
1529
+ channel_capacity_sats : Some ( expected_channel_capacity) ,
1530
+ channel_id : None ,
1531
+ counterparty_node_id : Some ( * node_id) ,
1532
+ discard_funding : is_check_discard_funding,
1533
+ reason : Some ( expected_reason. clone ( ) ) ,
1534
+ } ) . collect :: < Vec < _ > > ( ) ;
1535
+ check_closed_events ( node, expected_close_events. as_slice ( ) ) ;
1502
1536
}
1503
1537
1504
1538
/// Check that a channel's closing channel events has been issued
0 commit comments