@@ -24,7 +24,7 @@ use util::enforcing_trait_impls::EnforcingSigner;
24
24
use util:: scid_utils;
25
25
use util:: test_utils;
26
26
use util:: test_utils:: { panicking, TestChainMonitor } ;
27
- use util:: events:: { Event , MessageSendEvent , MessageSendEventsProvider , PaymentPurpose } ;
27
+ use util:: events:: { Event , HTLCDestination , MessageSendEvent , MessageSendEventsProvider , PaymentPurpose } ;
28
28
use util:: errors:: APIError ;
29
29
use util:: config:: UserConfig ;
30
30
use util:: ser:: { ReadableArgs , Writeable } ;
@@ -1254,24 +1254,101 @@ macro_rules! get_route_and_payment_hash {
1254
1254
} }
1255
1255
}
1256
1256
1257
+ pub struct HTLCHandlingFailedConditions {
1258
+ pub expected_pending_htlcs_forwardable : bool ,
1259
+ pub expected_htlc_processing_failed : Option < usize > ,
1260
+ pub expected_destinations : Vec < HTLCDestination > ,
1261
+ }
1262
+
1263
+ impl HTLCHandlingFailedConditions {
1264
+ pub fn new ( ) -> Self {
1265
+ Self {
1266
+ expected_pending_htlcs_forwardable : false ,
1267
+ expected_htlc_processing_failed : None ,
1268
+ expected_destinations : vec ! [ ] ,
1269
+ }
1270
+ }
1271
+
1272
+ pub fn with_reason ( mut self , reason : HTLCDestination ) -> Self {
1273
+ self . expected_htlc_processing_failed = Some ( 1 ) ;
1274
+ self . expected_destinations = vec ! [ reason] ;
1275
+ self
1276
+ }
1277
+
1278
+ pub fn with_reasons ( mut self , reasons : Vec < HTLCDestination > ) -> Self {
1279
+ self . expected_htlc_processing_failed = Some ( reasons. len ( ) ) ;
1280
+ self . expected_destinations = reasons;
1281
+ self
1282
+ }
1283
+ }
1284
+
1257
1285
#[ macro_export]
1258
- /// Clears (and ignores) a PendingHTLCsForwardable event
1259
- macro_rules! expect_pending_htlcs_forwardable_ignore {
1260
- ( $node : expr ) => { {
1286
+ macro_rules! expect_pending_htlcs_forwardable_conditions {
1287
+ ( $node : expr , $conditions : expr ) => { {
1288
+ let conditions = $conditions ;
1261
1289
let events = $node. node. get_and_clear_pending_events( ) ;
1262
- assert_eq!( events. len( ) , 1 ) ;
1263
1290
match events[ 0 ] {
1264
1291
$crate:: util:: events:: Event :: PendingHTLCsForwardable { .. } => { } ,
1265
1292
_ => panic!( "Unexpected event" ) ,
1266
1293
} ;
1294
+
1295
+ let count = conditions. expected_htlc_processing_failed. unwrap_or( 0 ) + 1 ;
1296
+ assert_eq!( events. len( ) , count) ;
1297
+
1298
+ if conditions. expected_destinations. len( ) > 0 {
1299
+ expect_htlc_handling_failed_destinations!( events, conditions. expected_destinations)
1300
+ }
1301
+ } }
1302
+ }
1303
+
1304
+ #[ macro_export]
1305
+ macro_rules! expect_htlc_handling_failed_destinations {
1306
+ ( $events: expr, $destinations: expr) => { {
1307
+ for event in $events {
1308
+ match event {
1309
+ $crate:: util:: events:: Event :: PendingHTLCsForwardable { .. } => { } ,
1310
+ $crate:: util:: events:: Event :: HTLCHandlingFailed { ref failed_next_destination, .. } => {
1311
+ assert!( $destinations. contains( & failed_next_destination) )
1312
+ } ,
1313
+ _ => panic!( "Unexpected destination" ) ,
1314
+ }
1315
+ }
1267
1316
} }
1268
1317
}
1269
1318
1319
+ #[ macro_export]
1320
+ /// Clears (and ignores) a PendingHTLCsForwardable event
1321
+ macro_rules! expect_pending_htlcs_forwardable_ignore {
1322
+ ( $node: expr) => { {
1323
+ expect_pending_htlcs_forwardable_conditions!( $node, $crate:: ln:: functional_test_utils:: HTLCHandlingFailedConditions :: new( ) ) ;
1324
+ } } ;
1325
+ }
1326
+
1327
+ #[ macro_export]
1328
+ /// Clears (and ignores) PendingHTLCsForwardable and HTLCHandlingFailed events
1329
+ macro_rules! expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore {
1330
+ ( $node: expr, $conditions: expr) => { {
1331
+ expect_pending_htlcs_forwardable_conditions!( $node, $conditions) ;
1332
+ } } ;
1333
+ }
1334
+
1270
1335
#[ macro_export]
1271
1336
/// Handles a PendingHTLCsForwardable event
1272
1337
macro_rules! expect_pending_htlcs_forwardable {
1273
1338
( $node: expr) => { {
1274
- $crate:: expect_pending_htlcs_forwardable_ignore!( $node) ;
1339
+ expect_pending_htlcs_forwardable_ignore!( $node) ;
1340
+ $node. node. process_pending_htlc_forwards( ) ;
1341
+
1342
+ // Ensure process_pending_htlc_forwards is idempotent.
1343
+ $node. node. process_pending_htlc_forwards( ) ;
1344
+ } } ;
1345
+ }
1346
+
1347
+ #[ macro_export]
1348
+ /// Handles a PendingHTLCsForwardable and HTLCHandlingFailed event
1349
+ macro_rules! expect_pending_htlcs_forwardable_and_htlc_handling_failed {
1350
+ ( $node: expr, $conditions: expr) => { {
1351
+ expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!( $node, $conditions) ;
1275
1352
$node. node. process_pending_htlc_forwards( ) ;
1276
1353
1277
1354
// Ensure process_pending_htlc_forwards is idempotent.
0 commit comments