@@ -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 < u32 > ,
1260
+ pub expected_destination : Option < 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_destination : None ,
1269
+ }
1270
+ }
1271
+
1272
+ pub fn htlc_processing_failed_with_count ( mut self , count : u32 ) -> Self {
1273
+ self . expected_htlc_processing_failed = Some ( count) ;
1274
+ self
1275
+ }
1276
+
1277
+ pub fn htlc_processing_failed_with_reason ( mut self , reason : HTLCDestination ) -> Self {
1278
+ self . expected_htlc_processing_failed = Some ( 1 ) ;
1279
+ self . expected_destination = Some ( reason) ;
1280
+ self
1281
+ }
1282
+
1283
+ pub fn htlc_processing_failed_with_count_and_reason ( mut self , count : u32 , reason : HTLCDestination ) -> Self {
1284
+ self . expected_htlc_processing_failed = Some ( count) ;
1285
+ self . expected_destination = Some ( reason) ;
1286
+ self
1287
+ }
1288
+ }
1289
+
1257
1290
#[ macro_export]
1258
- /// Clears (and ignores) a PendingHTLCsForwardable event
1259
- macro_rules! expect_pending_htlcs_forwardable_ignore {
1260
- ( $node: expr) => { {
1291
+ macro_rules! expect_pending_htlcs_forwardable_conditions {
1292
+ ( $node: expr, $conditions: expr) => { {
1261
1293
let events = $node. node. get_and_clear_pending_events( ) ;
1262
- assert_eq!( events. len( ) , 1 ) ;
1263
1294
match events[ 0 ] {
1264
1295
$crate:: util:: events:: Event :: PendingHTLCsForwardable { .. } => { } ,
1265
1296
_ => panic!( "Unexpected event" ) ,
1266
1297
} ;
1298
+
1299
+ if let Some ( count) = $conditions. expected_htlc_processing_failed {
1300
+ assert_eq!( events. len( ) as u32 , count + 1u32 ) ;
1301
+ } else {
1302
+ assert_eq!( events. len( ) , 1 ) ;
1303
+ }
1304
+
1305
+ if let Some ( reason) = $conditions. expected_destination {
1306
+ for event in events {
1307
+ match event {
1308
+ $crate:: util:: events:: Event :: PendingHTLCsForwardable { .. } => { } ,
1309
+ $crate:: util:: events:: Event :: HTLCHandlingFailed { ref failed_next_destination, .. } => {
1310
+ assert_eq!( reason, failed_next_destination. clone( ) ) ;
1311
+ } ,
1312
+ _ => panic!( "Unexpected event" ) ,
1313
+ }
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.
@@ -1282,6 +1359,8 @@ macro_rules! expect_pending_htlcs_forwardable {
1282
1359
#[ cfg( test) ]
1283
1360
macro_rules! expect_pending_htlcs_forwardable_from_events {
1284
1361
( $node: expr, $events: expr, $ignore: expr) => { {
1362
+ // We need to clear pending events since there may possibly be `PaymentForwardingFailed` events here
1363
+ $node. node. get_and_clear_pending_events( ) ;
1285
1364
assert_eq!( $events. len( ) , 1 ) ;
1286
1365
match $events[ 0 ] {
1287
1366
Event :: PendingHTLCsForwardable { .. } => { } ,
0 commit comments