@@ -614,13 +614,14 @@ where
614614mod test {
615615 use super :: * ;
616616 use crate :: chain:: channelmonitor:: HTLC_FAIL_BACK_BUFFER ;
617+ use crate :: events:: Event ;
617618 use crate :: ln:: channelmanager:: {
618619 Bolt11InvoiceParameters , OptionalPaymentParams , PaymentId , PhantomRouteHints ,
619620 RecipientOnionFields , Retry , MIN_FINAL_CLTV_EXPIRY_DELTA ,
620621 } ;
621622 use crate :: ln:: functional_test_utils:: * ;
622623 use crate :: ln:: msgs:: { BaseMessageHandler , ChannelMessageHandler , MessageSendEvent } ;
623- use crate :: routing:: router:: { PaymentParameters , RouteParameters } ;
624+ use crate :: routing:: router:: { PaymentParameters , RouteParameters , RouteParametersConfig } ;
624625 use crate :: sign:: PhantomKeysManager ;
625626 use crate :: types:: payment:: { PaymentHash , PaymentPreimage } ;
626627 use crate :: util:: config:: UserConfig ;
@@ -663,26 +664,26 @@ mod test {
663664 }
664665
665666 #[ test]
666- fn create_and_pay_for_bolt11_invoice ( ) {
667+ fn create_and_pay_for_bolt11_invoice_with_custom_tlvs ( ) {
667668 let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
668669 let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
669670 let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
670671 let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
671672 create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100000 , 10001 ) ;
672673
673- let node_a_id = nodes[ 0 ] . node . get_our_node_id ( ) ;
674-
675674 let description =
676675 Bolt11InvoiceDescription :: Direct ( Description :: new ( "test" . to_string ( ) ) . unwrap ( ) ) ;
677676 let non_default_invoice_expiry_secs = 4200 ;
677+ let amt_msats = 10_000 ;
678+
678679 let invoice_params = Bolt11InvoiceParameters {
679- amount_msats : Some ( 10_000 ) ,
680+ amount_msats : Some ( amt_msats ) ,
680681 description,
681682 invoice_expiry_delta_secs : Some ( non_default_invoice_expiry_secs) ,
682683 ..Default :: default ( )
683684 } ;
684685 let invoice = nodes[ 1 ] . node . create_bolt11_invoice ( invoice_params) . unwrap ( ) ;
685- assert_eq ! ( invoice. amount_milli_satoshis( ) , Some ( 10_000 ) ) ;
686+ assert_eq ! ( invoice. amount_milli_satoshis( ) , Some ( amt_msats ) ) ;
686687 // If no `min_final_cltv_expiry_delta` is specified, then it should be `MIN_FINAL_CLTV_EXPIRY_DELTA`.
687688 assert_eq ! ( invoice. min_final_cltv_expiry_delta( ) , MIN_FINAL_CLTV_EXPIRY_DELTA as u64 ) ;
688689 assert_eq ! (
@@ -694,6 +695,11 @@ mod test {
694695 Duration :: from_secs( non_default_invoice_expiry_secs. into( ) )
695696 ) ;
696697
698+ let ( payment_hash, payment_secret) =
699+ ( PaymentHash ( invoice. payment_hash ( ) . to_byte_array ( ) ) , * invoice. payment_secret ( ) ) ;
700+
701+ let preimage = nodes[ 1 ] . node . get_payment_preimage ( payment_hash, payment_secret) . unwrap ( ) ;
702+
697703 // Invoice SCIDs should always use inbound SCID aliases over the real channel ID, if one is
698704 // available.
699705 let chan = & nodes[ 1 ] . node . list_usable_channels ( ) [ 0 ] ;
@@ -707,25 +713,36 @@ mod test {
707713 assert_eq ! ( invoice. route_hints( ) [ 0 ] . 0 [ 0 ] . htlc_minimum_msat, chan. inbound_htlc_minimum_msat) ;
708714 assert_eq ! ( invoice. route_hints( ) [ 0 ] . 0 [ 0 ] . htlc_maximum_msat, chan. inbound_htlc_maximum_msat) ;
709715
716+ let custom_tlvs = vec ! [ ( 65537 , vec![ 42 ; 42 ] ) ] ;
717+ let optional_params = OptionalPaymentParams {
718+ custom_tlvs : custom_tlvs. clone ( ) ,
719+ route_params_config : RouteParametersConfig :: default ( ) ,
720+ retry_strategy : Retry :: Attempts ( 0 ) ,
721+ } ;
722+
710723 nodes[ 0 ]
711724 . node
712- . pay_for_bolt11_invoice (
713- & invoice,
714- PaymentId ( [ 42 ; 32 ] ) ,
715- None ,
716- OptionalPaymentParams :: default ( ) ,
717- )
725+ . pay_for_bolt11_invoice ( & invoice, PaymentId ( [ 42 ; 32 ] ) , None , optional_params)
718726 . unwrap ( ) ;
719727 check_added_monitors ( & nodes[ 0 ] , 1 ) ;
720728
721729 let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
722730 assert_eq ! ( events. len( ) , 1 ) ;
723- let payment_event = SendEvent :: from_event ( events. remove ( 0 ) ) ;
724- nodes[ 1 ] . node . handle_update_add_htlc ( node_a_id, & payment_event. msgs [ 0 ] ) ;
725- nodes[ 1 ] . node . handle_commitment_signed_batch_test ( node_a_id, & payment_event. commitment_msg ) ;
726- check_added_monitors ( & nodes[ 1 ] , 1 ) ;
727- let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
728- assert_eq ! ( events. len( ) , 2 ) ;
731+
732+ let ev = remove_first_msg_event_to_node ( & nodes[ 1 ] . node . get_our_node_id ( ) , & mut events) ;
733+
734+ let path = & [ & nodes[ 1 ] ] ;
735+ let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , path, amt_msats, payment_hash, ev)
736+ . with_payment_preimage ( preimage)
737+ . with_payment_secret ( payment_secret)
738+ . with_custom_tlvs ( custom_tlvs. clone ( ) ) ;
739+
740+ do_pass_along_path ( args) ;
741+
742+ claim_payment_along_route (
743+ ClaimAlongRouteArgs :: new ( & nodes[ 0 ] , & [ & [ & nodes[ 1 ] ] ] , preimage)
744+ . with_custom_tlvs ( custom_tlvs) ,
745+ ) ;
729746 }
730747
731748 fn do_create_invoice_min_final_cltv_delta ( with_custom_delta : bool ) {
@@ -1211,7 +1228,7 @@ mod test {
12111228 }
12121229
12131230 fn do_test_multi_node_receive ( user_generated_pmt_hash : bool ) {
1214- use crate :: events:: { Event , EventsProvider } ;
1231+ use crate :: events:: EventsProvider ;
12151232 use core:: cell:: RefCell ;
12161233
12171234 let mut chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
0 commit comments