@@ -15,7 +15,7 @@ use chain::channelmonitor::ChannelMonitor;
1515use chain:: transaction:: OutPoint ;
1616use ln:: { PaymentPreimage , PaymentHash , PaymentSecret } ;
1717use 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 } ;
1919use routing:: router:: { PaymentParameters , Route , get_route} ;
2020use ln:: features:: { InitFeatures , InvoiceFeatures } ;
2121use ln:: msgs;
@@ -1466,8 +1466,10 @@ impl<'a> PaymentFailedConditions<'a> {
14661466#[ cfg( test) ]
14671467macro_rules! expect_payment_failed_with_update {
14681468 ( $node: expr, $expected_payment_hash: expr, $rejected_by_dest: expr, $scid: expr, $chan_closed: expr) => {
1469- expect_payment_failed_conditions!( $node, $expected_payment_hash, $rejected_by_dest,
1470- $crate:: ln:: functional_test_utils:: PaymentFailedConditions :: new( ) . blamed_scid( $scid) . blamed_chan_closed( $chan_closed) ) ;
1469+ $crate:: ln:: functional_test_utils:: expect_payment_failed_conditions(
1470+ & $node, $expected_payment_hash, $rejected_by_dest,
1471+ $crate:: ln:: functional_test_utils:: PaymentFailedConditions :: new( )
1472+ . blamed_scid( $scid) . blamed_chan_closed( $chan_closed) ) ;
14711473 }
14721474}
14731475
@@ -1479,64 +1481,72 @@ macro_rules! expect_payment_failed {
14791481 $(
14801482 conditions = conditions. expected_htlc_error_data( $expected_error_code, & $expected_error_data) ;
14811483 ) *
1482- expect_payment_failed_conditions! ( $node, $expected_payment_hash, $rejected_by_dest, conditions) ;
1484+ $crate :: ln :: functional_test_utils :: expect_payment_failed_conditions( & $node, $expected_payment_hash, $rejected_by_dest, conditions) ;
14831485 } ;
14841486}
14851487
1486- #[ cfg( test) ]
1487- macro_rules! expect_payment_failed_conditions {
1488- ( $node: expr, $expected_payment_hash: expr, $rejected_by_dest: expr, $conditions: expr) => {
1489- let events = $node. node. get_and_clear_pending_events( ) ;
1490- assert_eq!( events. len( ) , 1 ) ;
1491- let expected_payment_id = match events[ 0 ] {
1492- Event :: PaymentPathFailed { ref payment_hash, rejected_by_dest, ref error_code, ref error_data, ref path, ref retry, ref payment_id, ref network_update, .. } => {
1493- assert_eq!( * payment_hash, $expected_payment_hash, "unexpected payment_hash" ) ;
1494- assert_eq!( rejected_by_dest, $rejected_by_dest, "unexpected rejected_by_dest value" ) ;
1495- assert!( retry. is_some( ) , "expected retry.is_some()" ) ;
1496- assert_eq!( retry. as_ref( ) . unwrap( ) . final_value_msat, path. last( ) . unwrap( ) . fee_msat, "Retry amount should match last hop in path" ) ;
1497- assert_eq!( retry. as_ref( ) . unwrap( ) . payment_params. payee_pubkey, path. last( ) . unwrap( ) . pubkey, "Retry payee node_id should match last hop in path" ) ;
1498-
1488+ pub fn expect_payment_failed_conditions < ' a , ' b , ' c , ' d , ' e > (
1489+ node : & ' a Node < ' b , ' c , ' d > , expected_payment_hash : PaymentHash , expected_rejected_by_dest : bool ,
1490+ conditions : PaymentFailedConditions < ' e >
1491+ ) {
1492+ let mut events = node. node . get_and_clear_pending_events ( ) ;
1493+ assert_eq ! ( events. len( ) , 1 ) ;
1494+ let expected_payment_id = match events. pop ( ) . unwrap ( ) {
1495+ Event :: PaymentPathFailed { payment_hash, rejected_by_dest, path, retry, payment_id, network_update,
1496+ #[ cfg( test) ]
1497+ error_code,
1498+ #[ cfg( test) ]
1499+ error_data, .. } => {
1500+ assert_eq ! ( payment_hash, expected_payment_hash, "unexpected payment_hash" ) ;
1501+ assert_eq ! ( rejected_by_dest, expected_rejected_by_dest, "unexpected rejected_by_dest value" ) ;
1502+ assert ! ( retry. is_some( ) , "expected retry.is_some()" ) ;
1503+ assert_eq ! ( retry. as_ref( ) . unwrap( ) . final_value_msat, path. last( ) . unwrap( ) . fee_msat, "Retry amount should match last hop in path" ) ;
1504+ assert_eq ! ( retry. as_ref( ) . unwrap( ) . payment_params. payee_pubkey, path. last( ) . unwrap( ) . pubkey, "Retry payee node_id should match last hop in path" ) ;
1505+
1506+ #[ cfg( test) ]
1507+ {
14991508 assert ! ( error_code. is_some( ) , "expected error_code.is_some() = true" ) ;
15001509 assert ! ( error_data. is_some( ) , "expected error_data.is_some() = true" ) ;
1501- if let Some ( ( code, data) ) = $ conditions. expected_htlc_error_data {
1510+ if let Some ( ( code, data) ) = conditions. expected_htlc_error_data {
15021511 assert_eq ! ( error_code. unwrap( ) , code, "unexpected error code" ) ;
15031512 assert_eq ! ( & error_data. as_ref( ) . unwrap( ) [ ..] , data, "unexpected error data" ) ;
15041513 }
1514+ }
15051515
1506- if let Some ( chan_closed) = $ conditions. expected_blamed_chan_closed {
1507- match network_update {
1508- & Some ( $crate :: routing :: gossip :: NetworkUpdate :: ChannelUpdateMessage { ref msg } ) if !chan_closed => {
1509- if let Some ( scid) = $ conditions. expected_blamed_scid {
1510- assert_eq!( msg. contents. short_channel_id, scid) ;
1511- }
1512- assert_eq! ( msg . contents . flags & 2 , 0 ) ;
1513- } ,
1514- & Some ( $crate :: routing :: gossip :: NetworkUpdate :: ChannelFailure { short_channel_id , is_permanent } ) if chan_closed => {
1515- if let Some ( scid ) = $conditions . expected_blamed_scid {
1516- assert_eq! ( short_channel_id , scid) ;
1517- }
1518- assert! ( is_permanent ) ;
1519- } ,
1520- Some ( _ ) => panic! ( "Unexpected update type" ) ,
1521- None => panic!( "Expected update" ) ,
1522- }
1516+ if let Some ( chan_closed) = conditions. expected_blamed_chan_closed {
1517+ match network_update {
1518+ Some ( NetworkUpdate :: ChannelUpdateMessage { ref msg } ) if !chan_closed => {
1519+ if let Some ( scid) = conditions. expected_blamed_scid {
1520+ assert_eq ! ( msg. contents. short_channel_id, scid) ;
1521+ }
1522+ const CHAN_DISABLED_FLAG : u8 = 2 ;
1523+ assert_eq ! ( msg . contents . flags & CHAN_DISABLED_FLAG , 0 ) ;
1524+ } ,
1525+ Some ( NetworkUpdate :: ChannelFailure { short_channel_id , is_permanent } ) if chan_closed => {
1526+ if let Some ( scid) = conditions . expected_blamed_scid {
1527+ assert_eq ! ( short_channel_id , scid ) ;
1528+ }
1529+ assert ! ( is_permanent ) ;
1530+ } ,
1531+ Some ( _ ) => panic ! ( "Unexpected update type " ) ,
1532+ None => panic ! ( "Expected update" ) ,
15231533 }
1534+ }
15241535
1525- payment_id. unwrap( )
1526- } ,
1527- _ => panic!( "Unexpected event" ) ,
1528- } ;
1529- if !$conditions. expected_mpp_parts_remain {
1530- $node. node. abandon_payment( expected_payment_id) ;
1531- let events = $node. node. get_and_clear_pending_events( ) ;
1532- assert_eq!( events. len( ) , 1 ) ;
1533- match events[ 0 ] {
1534- Event :: PaymentFailed { ref payment_hash, ref payment_id } => {
1535- assert_eq!( * payment_hash, $expected_payment_hash, "unexpected second payment_hash" ) ;
1536- assert_eq!( * payment_id, expected_payment_id) ;
1537- }
1538- _ => panic!( "Unexpected second event" ) ,
1536+ payment_id. unwrap ( )
1537+ } ,
1538+ _ => panic ! ( "Unexpected event" ) ,
1539+ } ;
1540+ if !conditions. expected_mpp_parts_remain {
1541+ node. node . abandon_payment ( expected_payment_id) ;
1542+ let events = node. node . get_and_clear_pending_events ( ) ;
1543+ assert_eq ! ( events. len( ) , 1 ) ;
1544+ match events[ 0 ] {
1545+ Event :: PaymentFailed { ref payment_hash, ref payment_id } => {
1546+ assert_eq ! ( * payment_hash, expected_payment_hash, "unexpected second payment_hash" ) ;
1547+ assert_eq ! ( * payment_id, expected_payment_id) ;
15391548 }
1549+ _ => panic ! ( "Unexpected second event" ) ,
15401550 }
15411551 }
15421552}
0 commit comments