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