@@ -15,7 +15,7 @@ use chain::channelmonitor::ChannelMonitor;
15
15
use chain:: transaction:: OutPoint ;
16
16
use ln:: { PaymentPreimage , PaymentHash , PaymentSecret } ;
17
17
use ln:: channelmanager:: { ChainParameters , ChannelManager , ChannelManagerReadArgs , RAACommitmentOrder , PaymentSendFailure , PaymentId , MIN_CLTV_EXPIRY_DELTA } ;
18
- use routing:: network_graph:: { NetGraphMsgHandler , NetworkGraph } ;
18
+ use routing:: network_graph:: { NetGraphMsgHandler , NetworkGraph , NetworkUpdate } ;
19
19
use routing:: router:: { PaymentParameters , Route , get_route} ;
20
20
use ln:: features:: { InitFeatures , InvoiceFeatures } ;
21
21
use ln:: msgs;
@@ -1394,7 +1394,7 @@ impl<'a> PaymentFailedConditions<'a> {
1394
1394
#[ cfg( test) ]
1395
1395
macro_rules! expect_payment_failed_with_update {
1396
1396
( $node: expr, $expected_payment_hash: expr, $rejected_by_dest: expr, $scid: expr, $chan_closed: expr) => {
1397
- expect_payment_failed_conditions! ( $node, $expected_payment_hash, $rejected_by_dest,
1397
+ $crate :: ln :: functional_test_utils :: expect_payment_failed_conditions( & $node, $expected_payment_hash, $rejected_by_dest,
1398
1398
$crate:: ln:: functional_test_utils:: PaymentFailedConditions :: new( ) . blamed_scid( $scid) . blamed_chan_closed( $chan_closed) ) ;
1399
1399
}
1400
1400
}
@@ -1407,64 +1407,71 @@ macro_rules! expect_payment_failed {
1407
1407
$(
1408
1408
conditions = conditions. expected_htlc_error_data( $expected_error_code, & $expected_error_data) ;
1409
1409
) *
1410
- expect_payment_failed_conditions! ( $node, $expected_payment_hash, $rejected_by_dest, conditions) ;
1410
+ $crate :: ln :: functional_test_utils :: expect_payment_failed_conditions( & $node, $expected_payment_hash, $rejected_by_dest, conditions) ;
1411
1411
} ;
1412
1412
}
1413
1413
1414
- #[ cfg( test) ]
1415
- macro_rules! expect_payment_failed_conditions {
1416
- ( $node: expr, $expected_payment_hash: expr, $rejected_by_dest: expr, $conditions: expr) => {
1417
- let events = $node. node. get_and_clear_pending_events( ) ;
1418
- assert_eq!( events. len( ) , 1 ) ;
1419
- let expected_payment_id = match events[ 0 ] {
1420
- Event :: PaymentPathFailed { ref payment_hash, rejected_by_dest, ref error_code, ref error_data, ref path, ref retry, ref payment_id, ref network_update, .. } => {
1421
- assert_eq!( * payment_hash, $expected_payment_hash, "unexpected payment_hash" ) ;
1422
- assert_eq!( rejected_by_dest, $rejected_by_dest, "unexpected rejected_by_dest value" ) ;
1423
- assert!( retry. is_some( ) , "expected retry.is_some()" ) ;
1424
- assert_eq!( retry. as_ref( ) . unwrap( ) . final_value_msat, path. last( ) . unwrap( ) . fee_msat, "Retry amount should match last hop in path" ) ;
1425
- assert_eq!( retry. as_ref( ) . unwrap( ) . payment_params. payee_pubkey, path. last( ) . unwrap( ) . pubkey, "Retry payee node_id should match last hop in path" ) ;
1426
-
1414
+ pub fn expect_payment_failed_conditions < ' a , ' b , ' c , ' d , ' e > (
1415
+ node : & ' a Node < ' b , ' c , ' d > , expected_payment_hash : PaymentHash , rejected_by_dest : bool ,
1416
+ conditions : PaymentFailedConditions < ' e >
1417
+ ) {
1418
+ let mut events = node. node . get_and_clear_pending_events ( ) ;
1419
+ assert_eq ! ( events. len( ) , 1 ) ;
1420
+ let expected_payment_id = match events. pop ( ) . unwrap ( ) {
1421
+ Event :: PaymentPathFailed { payment_hash, rejected_by_dest : lulz, path, retry, payment_id, network_update,
1422
+ #[ cfg( test) ]
1423
+ error_code,
1424
+ #[ cfg( test) ]
1425
+ error_data, .. } => {
1426
+ assert_eq ! ( payment_hash, expected_payment_hash, "unexpected payment_hash" ) ;
1427
+ assert_eq ! ( rejected_by_dest, lulz, "unexpected rejected_by_dest value" ) ;
1428
+ assert ! ( retry. is_some( ) , "expected retry.is_some()" ) ;
1429
+ assert_eq ! ( retry. as_ref( ) . unwrap( ) . final_value_msat, path. last( ) . unwrap( ) . fee_msat, "Retry amount should match last hop in path" ) ;
1430
+ assert_eq ! ( retry. as_ref( ) . unwrap( ) . payment_params. payee_pubkey, path. last( ) . unwrap( ) . pubkey, "Retry payee node_id should match last hop in path" ) ;
1431
+
1432
+ #[ cfg( test) ]
1433
+ {
1427
1434
assert ! ( error_code. is_some( ) , "expected error_code.is_some() = true" ) ;
1428
1435
assert ! ( error_data. is_some( ) , "expected error_data.is_some() = true" ) ;
1429
- if let Some ( ( code, data) ) = $ conditions. expected_htlc_error_data {
1436
+ if let Some ( ( code, data) ) = conditions. expected_htlc_error_data {
1430
1437
assert_eq ! ( error_code. unwrap( ) , code, "unexpected error code" ) ;
1431
1438
assert_eq ! ( & error_data. as_ref( ) . unwrap( ) [ ..] , data, "unexpected error data" ) ;
1432
1439
}
1440
+ }
1433
1441
1434
- if let Some ( chan_closed) = $conditions. expected_blamed_chan_closed {
1435
- match network_update {
1436
- & Some ( $crate:: routing:: network_graph:: NetworkUpdate :: ChannelUpdateMessage { ref msg } ) if !chan_closed => {
1437
- if let Some ( scid) = $conditions. expected_blamed_scid {
1438
- assert_eq!( msg. contents. short_channel_id, scid) ;
1439
- }
1440
- assert_eq!( msg. contents. flags & 2 , 0 ) ;
1441
- } ,
1442
- & Some ( $crate:: routing:: network_graph:: NetworkUpdate :: ChannelClosed { short_channel_id, is_permanent } ) if chan_closed => {
1443
- if let Some ( scid) = $conditions. expected_blamed_scid {
1444
- assert_eq!( short_channel_id, scid) ;
1445
- }
1446
- assert!( is_permanent) ;
1447
- } ,
1448
- Some ( _) => panic!( "Unexpected update type" ) ,
1449
- None => panic!( "Expected update" ) ,
1450
- }
1442
+ if let Some ( chan_closed) = conditions. expected_blamed_chan_closed {
1443
+ match network_update {
1444
+ Some ( NetworkUpdate :: ChannelUpdateMessage { ref msg } ) if !chan_closed => {
1445
+ if let Some ( scid) = conditions. expected_blamed_scid {
1446
+ assert_eq ! ( msg. contents. short_channel_id, scid) ;
1447
+ }
1448
+ assert_eq ! ( msg. contents. flags & 2 , 0 ) ;
1449
+ } ,
1450
+ Some ( NetworkUpdate :: ChannelClosed { short_channel_id, is_permanent } ) if chan_closed => {
1451
+ if let Some ( scid) = conditions. expected_blamed_scid {
1452
+ assert_eq ! ( short_channel_id, scid) ;
1453
+ }
1454
+ assert ! ( is_permanent) ;
1455
+ } ,
1456
+ Some ( _) => panic ! ( "Unexpected update type" ) ,
1457
+ None => panic ! ( "Expected update" ) ,
1451
1458
}
1459
+ }
1452
1460
1453
- payment_id. unwrap( )
1454
- } ,
1455
- _ => panic!( "Unexpected event" ) ,
1456
- } ;
1457
- if !$conditions. expected_mpp_parts_remain {
1458
- $node. node. abandon_payment( expected_payment_id) ;
1459
- let events = $node. node. get_and_clear_pending_events( ) ;
1460
- assert_eq!( events. len( ) , 1 ) ;
1461
- match events[ 0 ] {
1462
- Event :: PaymentFailed { ref payment_hash, ref payment_id } => {
1463
- assert_eq!( * payment_hash, $expected_payment_hash, "unexpected second payment_hash" ) ;
1464
- assert_eq!( * payment_id, expected_payment_id) ;
1465
- }
1466
- _ => panic!( "Unexpected second event" ) ,
1461
+ payment_id. unwrap ( )
1462
+ } ,
1463
+ _ => panic ! ( "Unexpected event" ) ,
1464
+ } ;
1465
+ if !conditions. expected_mpp_parts_remain {
1466
+ node. node . abandon_payment ( expected_payment_id) ;
1467
+ let events = node. node . get_and_clear_pending_events ( ) ;
1468
+ assert_eq ! ( events. len( ) , 1 ) ;
1469
+ match events[ 0 ] {
1470
+ Event :: PaymentFailed { ref payment_hash, ref payment_id } => {
1471
+ assert_eq ! ( * payment_hash, expected_payment_hash, "unexpected second payment_hash" ) ;
1472
+ assert_eq ! ( * payment_id, expected_payment_id) ;
1467
1473
}
1474
+ _ => panic ! ( "Unexpected second event" ) ,
1468
1475
}
1469
1476
}
1470
1477
}
0 commit comments