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