@@ -620,7 +620,8 @@ mod test {
620620 } ;
621621 use crate :: ln:: functional_test_utils:: * ;
622622 use crate :: ln:: msgs:: { BaseMessageHandler , ChannelMessageHandler , MessageSendEvent } ;
623- use crate :: routing:: router:: { PaymentParameters , RouteParameters } ;
623+ use crate :: ln:: outbound_payment:: RecipientCustomTlvs ;
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-
674+ let amt_msat = 10_000 ;
675675 let description =
676676 Bolt11InvoiceDescription :: Direct ( Description :: new ( "test" . to_string ( ) ) . unwrap ( ) ) ;
677677 let non_default_invoice_expiry_secs = 4200 ;
678+
678679 let invoice_params = Bolt11InvoiceParameters {
679- amount_msats : Some ( 10_000 ) ,
680+ amount_msats : Some ( amt_msat ) ,
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_msat ) ) ;
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,10 @@ mod test {
694695 Duration :: from_secs( non_default_invoice_expiry_secs. into( ) )
695696 ) ;
696697
698+ let ( payment_hash, payment_secret) = ( invoice. payment_hash ( ) , * invoice. payment_secret ( ) ) ;
699+
700+ let preimage = nodes[ 1 ] . node . get_payment_preimage ( payment_hash, payment_secret) . unwrap ( ) ;
701+
697702 // Invoice SCIDs should always use inbound SCID aliases over the real channel ID, if one is
698703 // available.
699704 let chan = & nodes[ 1 ] . node . list_usable_channels ( ) [ 0 ] ;
@@ -707,25 +712,34 @@ mod test {
707712 assert_eq ! ( invoice. route_hints( ) [ 0 ] . 0 [ 0 ] . htlc_minimum_msat, chan. inbound_htlc_minimum_msat) ;
708713 assert_eq ! ( invoice. route_hints( ) [ 0 ] . 0 [ 0 ] . htlc_maximum_msat, chan. inbound_htlc_maximum_msat) ;
709714
715+ let custom_tlvs = RecipientCustomTlvs :: new ( vec ! [ ( 65537 , vec![ 42 ; 42 ] ) ] ) . unwrap ( ) ;
716+ let optional_params = OptionalBolt11PaymentParams {
717+ custom_tlvs : custom_tlvs. clone ( ) ,
718+ route_params_config : RouteParametersConfig :: default ( ) ,
719+ retry_strategy : Retry :: Attempts ( 0 ) ,
720+ } ;
721+
710722 nodes[ 0 ]
711723 . node
712- . pay_for_bolt11_invoice (
713- & invoice,
714- PaymentId ( [ 42 ; 32 ] ) ,
715- None ,
716- OptionalBolt11PaymentParams :: default ( ) ,
717- )
724+ . pay_for_bolt11_invoice ( & invoice, PaymentId ( [ 42 ; 32 ] ) , None , optional_params)
718725 . unwrap ( ) ;
719726 check_added_monitors ( & nodes[ 0 ] , 1 ) ;
720727
721728 let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
722729 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 ) ;
730+ let ev = remove_first_msg_event_to_node ( & nodes[ 1 ] . node . get_our_node_id ( ) , & mut events) ;
731+
732+ let path = & [ & nodes[ 1 ] ] ;
733+ let args = PassAlongPathArgs :: new ( & nodes[ 0 ] , path, amt_msat, payment_hash, ev)
734+ . with_payment_preimage ( preimage)
735+ . with_payment_secret ( payment_secret)
736+ . with_custom_tlvs ( custom_tlvs. clone ( ) . into_inner ( ) ) ;
737+
738+ do_pass_along_path ( args) ;
739+ claim_payment_along_route (
740+ ClaimAlongRouteArgs :: new ( & nodes[ 0 ] , & [ & [ & nodes[ 1 ] ] ] , preimage)
741+ . with_custom_tlvs ( custom_tlvs. into_inner ( ) ) ,
742+ ) ;
729743 }
730744
731745 fn do_create_invoice_min_final_cltv_delta ( with_custom_delta : bool ) {
0 commit comments