@@ -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:: gossip:: { P2PGossipSync , NetworkGraph } ;
18
+ use routing:: gossip:: { P2PGossipSync , NetworkGraph , NetworkUpdate } ;
19
19
use routing:: router:: { PaymentParameters , Route , get_route} ;
20
20
use ln:: features:: { InitFeatures , InvoiceFeatures } ;
21
21
use ln:: msgs;
@@ -1467,8 +1467,10 @@ impl<'a> PaymentFailedConditions<'a> {
1467
1467
#[ cfg( test) ]
1468
1468
macro_rules! expect_payment_failed_with_update {
1469
1469
( $node: expr, $expected_payment_hash: expr, $rejected_by_dest: expr, $scid: expr, $chan_closed: expr) => {
1470
- expect_payment_failed_conditions!( $node, $expected_payment_hash, $rejected_by_dest,
1471
- $crate:: ln:: functional_test_utils:: PaymentFailedConditions :: new( ) . blamed_scid( $scid) . blamed_chan_closed( $chan_closed) ) ;
1470
+ $crate:: ln:: functional_test_utils:: expect_payment_failed_conditions(
1471
+ & $node, $expected_payment_hash, $rejected_by_dest,
1472
+ $crate:: ln:: functional_test_utils:: PaymentFailedConditions :: new( )
1473
+ . blamed_scid( $scid) . blamed_chan_closed( $chan_closed) ) ;
1472
1474
}
1473
1475
}
1474
1476
@@ -1480,64 +1482,72 @@ macro_rules! expect_payment_failed {
1480
1482
$(
1481
1483
conditions = conditions. expected_htlc_error_data( $expected_error_code, & $expected_error_data) ;
1482
1484
) *
1483
- expect_payment_failed_conditions! ( $node, $expected_payment_hash, $rejected_by_dest, conditions) ;
1485
+ $crate :: ln :: functional_test_utils :: expect_payment_failed_conditions( & $node, $expected_payment_hash, $rejected_by_dest, conditions) ;
1484
1486
} ;
1485
1487
}
1486
1488
1487
- #[ cfg( test) ]
1488
- macro_rules! expect_payment_failed_conditions {
1489
- ( $node: expr, $expected_payment_hash: expr, $rejected_by_dest: expr, $conditions: expr) => {
1490
- let events = $node. node. get_and_clear_pending_events( ) ;
1491
- assert_eq!( events. len( ) , 1 ) ;
1492
- let expected_payment_id = match events[ 0 ] {
1493
- Event :: PaymentPathFailed { ref payment_hash, rejected_by_dest, ref error_code, ref error_data, ref path, ref retry, ref payment_id, ref network_update, .. } => {
1494
- assert_eq!( * payment_hash, $expected_payment_hash, "unexpected payment_hash" ) ;
1495
- assert_eq!( rejected_by_dest, $rejected_by_dest, "unexpected rejected_by_dest value" ) ;
1496
- assert!( retry. is_some( ) , "expected retry.is_some()" ) ;
1497
- assert_eq!( retry. as_ref( ) . unwrap( ) . final_value_msat, path. last( ) . unwrap( ) . fee_msat, "Retry amount should match last hop in path" ) ;
1498
- assert_eq!( retry. as_ref( ) . unwrap( ) . payment_params. payee_pubkey, path. last( ) . unwrap( ) . pubkey, "Retry payee node_id should match last hop in path" ) ;
1499
-
1489
+ pub fn expect_payment_failed_conditions < ' a , ' b , ' c , ' d , ' e > (
1490
+ node : & ' a Node < ' b , ' c , ' d > , expected_payment_hash : PaymentHash , expected_rejected_by_dest : bool ,
1491
+ conditions : PaymentFailedConditions < ' e >
1492
+ ) {
1493
+ let mut events = node. node . get_and_clear_pending_events ( ) ;
1494
+ assert_eq ! ( events. len( ) , 1 ) ;
1495
+ let expected_payment_id = match events. pop ( ) . unwrap ( ) {
1496
+ Event :: PaymentPathFailed { payment_hash, rejected_by_dest, path, retry, payment_id, network_update,
1497
+ #[ cfg( test) ]
1498
+ error_code,
1499
+ #[ cfg( test) ]
1500
+ error_data, .. } => {
1501
+ assert_eq ! ( payment_hash, expected_payment_hash, "unexpected payment_hash" ) ;
1502
+ assert_eq ! ( rejected_by_dest, expected_rejected_by_dest, "unexpected rejected_by_dest value" ) ;
1503
+ assert ! ( retry. is_some( ) , "expected retry.is_some()" ) ;
1504
+ assert_eq ! ( retry. as_ref( ) . unwrap( ) . final_value_msat, path. last( ) . unwrap( ) . fee_msat, "Retry amount should match last hop in path" ) ;
1505
+ assert_eq ! ( retry. as_ref( ) . unwrap( ) . payment_params. payee_pubkey, path. last( ) . unwrap( ) . pubkey, "Retry payee node_id should match last hop in path" ) ;
1506
+
1507
+ #[ cfg( test) ]
1508
+ {
1500
1509
assert ! ( error_code. is_some( ) , "expected error_code.is_some() = true" ) ;
1501
1510
assert ! ( error_data. is_some( ) , "expected error_data.is_some() = true" ) ;
1502
- if let Some ( ( code, data) ) = $ conditions. expected_htlc_error_data {
1511
+ if let Some ( ( code, data) ) = conditions. expected_htlc_error_data {
1503
1512
assert_eq ! ( error_code. unwrap( ) , code, "unexpected error code" ) ;
1504
1513
assert_eq ! ( & error_data. as_ref( ) . unwrap( ) [ ..] , data, "unexpected error data" ) ;
1505
1514
}
1515
+ }
1506
1516
1507
- if let Some ( chan_closed) = $ conditions. expected_blamed_chan_closed {
1508
- match network_update {
1509
- & Some ( $crate :: routing :: gossip :: NetworkUpdate :: ChannelUpdateMessage { ref msg } ) if !chan_closed => {
1510
- if let Some ( scid) = $ conditions. expected_blamed_scid {
1511
- assert_eq!( msg. contents. short_channel_id, scid) ;
1512
- }
1513
- assert_eq! ( msg . contents . flags & 2 , 0 ) ;
1514
- } ,
1515
- & Some ( $crate :: routing :: gossip :: NetworkUpdate :: ChannelFailure { short_channel_id , is_permanent } ) if chan_closed => {
1516
- if let Some ( scid ) = $conditions . expected_blamed_scid {
1517
- assert_eq! ( short_channel_id , scid) ;
1518
- }
1519
- assert! ( is_permanent ) ;
1520
- } ,
1521
- Some ( _ ) => panic! ( "Unexpected update type" ) ,
1522
- None => panic!( "Expected update" ) ,
1523
- }
1517
+ if let Some ( chan_closed) = conditions. expected_blamed_chan_closed {
1518
+ match network_update {
1519
+ Some ( NetworkUpdate :: ChannelUpdateMessage { ref msg } ) if !chan_closed => {
1520
+ if let Some ( scid) = conditions. expected_blamed_scid {
1521
+ assert_eq ! ( msg. contents. short_channel_id, scid) ;
1522
+ }
1523
+ const CHAN_DISABLED_FLAG : u8 = 2 ;
1524
+ assert_eq ! ( msg . contents . flags & CHAN_DISABLED_FLAG , 0 ) ;
1525
+ } ,
1526
+ Some ( NetworkUpdate :: ChannelFailure { short_channel_id , is_permanent } ) if chan_closed => {
1527
+ if let Some ( scid) = conditions . expected_blamed_scid {
1528
+ assert_eq ! ( short_channel_id , scid ) ;
1529
+ }
1530
+ assert ! ( is_permanent ) ;
1531
+ } ,
1532
+ Some ( _ ) => panic ! ( "Unexpected update type " ) ,
1533
+ None => panic ! ( "Expected update" ) ,
1524
1534
}
1535
+ }
1525
1536
1526
- payment_id. unwrap( )
1527
- } ,
1528
- _ => panic!( "Unexpected event" ) ,
1529
- } ;
1530
- if !$conditions. expected_mpp_parts_remain {
1531
- $node. node. abandon_payment( expected_payment_id) ;
1532
- let events = $node. node. get_and_clear_pending_events( ) ;
1533
- assert_eq!( events. len( ) , 1 ) ;
1534
- match events[ 0 ] {
1535
- Event :: PaymentFailed { ref payment_hash, ref payment_id } => {
1536
- assert_eq!( * payment_hash, $expected_payment_hash, "unexpected second payment_hash" ) ;
1537
- assert_eq!( * payment_id, expected_payment_id) ;
1538
- }
1539
- _ => panic!( "Unexpected second event" ) ,
1537
+ payment_id. unwrap ( )
1538
+ } ,
1539
+ _ => panic ! ( "Unexpected event" ) ,
1540
+ } ;
1541
+ if !conditions. expected_mpp_parts_remain {
1542
+ node. node . abandon_payment ( expected_payment_id) ;
1543
+ let events = node. node . get_and_clear_pending_events ( ) ;
1544
+ assert_eq ! ( events. len( ) , 1 ) ;
1545
+ match events[ 0 ] {
1546
+ Event :: PaymentFailed { ref payment_hash, ref payment_id } => {
1547
+ assert_eq ! ( * payment_hash, expected_payment_hash, "unexpected second payment_hash" ) ;
1548
+ assert_eq ! ( * payment_id, expected_payment_id) ;
1540
1549
}
1550
+ _ => panic ! ( "Unexpected second event" ) ,
1541
1551
}
1542
1552
}
1543
1553
}
0 commit comments