@@ -742,7 +742,7 @@ fn ignore_duplicate_invoice() {
742742 static_invoice. clone ( ) ,
743743 reply_path,
744744 invoice_request,
745- invoice_flow_res. invoice_request_path ,
745+ invoice_flow_res. invoice_request_path . clone ( ) ,
746746 )
747747 . unwrap ( ) ;
748748
@@ -751,17 +751,15 @@ fn ignore_duplicate_invoice() {
751751 // payer.
752752 let invreq_om =
753753 always_online_node. onion_messenger . next_onion_message_for_peer ( async_recipient_id) . unwrap ( ) ;
754-
755754 let peeled_msg = async_recipient. onion_messenger . peel_onion_message ( & invreq_om) . unwrap ( ) ;
756755 assert ! ( matches!( peeled_msg, PeeledOnion :: Offers ( OffersMessage :: InvoiceRequest ( _) , _, _) ) ) ;
757756
758757 let static_invoice_om =
759758 always_online_node. onion_messenger . next_onion_message_for_peer ( sender_node_id) . unwrap ( ) ;
760-
761759 let peeled_msg = sender. onion_messenger . peel_onion_message ( & static_invoice_om) . unwrap ( ) ;
762760 assert ! ( matches!( peeled_msg, PeeledOnion :: Offers ( OffersMessage :: StaticInvoice ( _) , _, _) ) ) ;
763761
764- // Handling the `invoice_request` from the async recipient we should get back a invoice.
762+ // Handling the `invoice_request` from the async recipient we should get back an invoice.
765763 async_recipient. onion_messenger . handle_onion_message ( always_online_node_id, & invreq_om) ;
766764 let invoice_om =
767765 async_recipient. onion_messenger . next_onion_message_for_peer ( sender_node_id) . unwrap ( ) ;
@@ -782,7 +780,6 @@ fn ignore_duplicate_invoice() {
782780
783781 let release_held_htlc_om =
784782 async_recipient. onion_messenger . next_onion_message_for_peer ( sender_node_id) . unwrap ( ) ;
785-
786783 sender. onion_messenger . handle_onion_message ( async_recipient_id, & release_held_htlc_om) ;
787784
788785 let mut events = sender. node . get_and_clear_pending_msg_events ( ) ;
@@ -797,7 +794,7 @@ fn ignore_duplicate_invoice() {
797794 let keysend_preimage = extract_payment_preimage ( & claimable_ev) ;
798795 let ( res, _) =
799796 claim_payment_along_route ( ClaimAlongRouteArgs :: new ( sender, route, keysend_preimage) ) ;
800- assert_eq ! ( res, Some ( PaidBolt12Invoice :: StaticInvoice ( static_invoice) ) ) ;
797+ assert_eq ! ( res, Some ( PaidBolt12Invoice :: StaticInvoice ( static_invoice. clone ( ) ) ) ) ;
801798
802799 // After paying the static invoice, check that regular invoice received from async recipient is ignored.
803800 match sender. onion_messenger . peel_onion_message ( & invoice_om) {
@@ -809,6 +806,90 @@ fn ignore_duplicate_invoice() {
809806 } ,
810807 _ => panic ! ( ) ,
811808 }
809+
810+ // Now handle case where the sender pays regular invoice and ignores static invoice.
811+ let payment_id = PaymentId ( [ 2 ; 32 ] ) ;
812+ sender
813+ . node
814+ . pay_for_offer ( & offer, None , Some ( amt_msat) , None , payment_id, Retry :: Attempts ( 0 ) , params)
815+ . unwrap ( ) ;
816+
817+ let invreq_om =
818+ sender. onion_messenger . next_onion_message_for_peer ( always_online_node_id) . unwrap ( ) ;
819+ always_online_node. onion_messenger . handle_onion_message ( sender_node_id, & invreq_om) ;
820+
821+ let mut events = always_online_node. node . get_and_clear_pending_events ( ) ;
822+ assert_eq ! ( events. len( ) , 1 ) ;
823+ let ( reply_path, invoice_request) = match events. pop ( ) . unwrap ( ) {
824+ Event :: StaticInvoiceRequested {
825+ recipient_id : ev_id,
826+ invoice_slot : _,
827+ reply_path,
828+ invoice_request,
829+ } => {
830+ assert_eq ! ( recipient_id, ev_id) ;
831+ ( reply_path, invoice_request)
832+ } ,
833+ _ => panic ! ( ) ,
834+ } ;
835+
836+ always_online_node
837+ . node
838+ . send_response_static_invoice_request (
839+ static_invoice. clone ( ) ,
840+ reply_path,
841+ invoice_request,
842+ invoice_flow_res. invoice_request_path ,
843+ )
844+ . unwrap ( ) ;
845+
846+ let invreq_om =
847+ always_online_node. onion_messenger . next_onion_message_for_peer ( async_recipient_id) . unwrap ( ) ;
848+ let peeled_msg = async_recipient. onion_messenger . peel_onion_message ( & invreq_om) . unwrap ( ) ;
849+ assert ! ( matches!( peeled_msg, PeeledOnion :: Offers ( OffersMessage :: InvoiceRequest ( _) , _, _) ) ) ;
850+
851+ let static_invoice_om =
852+ always_online_node. onion_messenger . next_onion_message_for_peer ( sender_node_id) . unwrap ( ) ;
853+ let peeled_msg = sender. onion_messenger . peel_onion_message ( & static_invoice_om) . unwrap ( ) ;
854+ assert ! ( matches!( peeled_msg, PeeledOnion :: Offers ( OffersMessage :: StaticInvoice ( _) , _, _) ) ) ;
855+
856+ async_recipient. onion_messenger . handle_onion_message ( always_online_node_id, & invreq_om) ;
857+ let invoice_om =
858+ async_recipient. onion_messenger . next_onion_message_for_peer ( sender_node_id) . unwrap ( ) ;
859+
860+ let ( invoice, context) = match sender. onion_messenger . peel_onion_message ( & invoice_om) {
861+ Ok ( PeeledOnion :: Offers ( OffersMessage :: Invoice ( invoice) , context, _) ) => ( invoice, context) ,
862+ _ => panic ! ( ) ,
863+ } ;
864+
865+ assert ! ( matches!(
866+ sender. node. send_payment_for_bolt12_invoice( & invoice, context. as_ref( ) ) ,
867+ Ok ( ( ) )
868+ ) ) ;
869+
870+ let mut events = sender. node . get_and_clear_pending_msg_events ( ) ;
871+ assert_eq ! ( events. len( ) , 1 ) ;
872+ let ev = remove_first_msg_event_to_node ( & always_online_node_id, & mut events) ;
873+ let payment_hash = extract_payment_hash ( & ev) ;
874+ check_added_monitors ! ( sender, 1 ) ;
875+
876+ let args = PassAlongPathArgs :: new ( sender, route[ 0 ] , amt_msat, payment_hash, ev)
877+ . without_clearing_recipient_events ( ) ;
878+ do_pass_along_path ( args) ;
879+
880+ let payment_preimage = match get_event ! ( async_recipient, Event :: PaymentClaimable ) {
881+ Event :: PaymentClaimable { purpose, .. } => purpose. preimage ( ) . unwrap ( ) ,
882+ _ => panic ! ( "No Event::PaymentClaimable" ) ,
883+ } ;
884+
885+ // After paying invoice, check that static invoice is ignored.
886+ let res = claim_payment ( sender, route[ 0 ] , payment_preimage) ;
887+ assert_eq ! ( res, Some ( PaidBolt12Invoice :: Bolt12Invoice ( invoice) ) ) ;
888+
889+ sender. onion_messenger . handle_onion_message ( always_online_node_id, & static_invoice_om) ;
890+ let async_pmts_msgs = AsyncPaymentsMessageHandler :: release_pending_messages ( sender. node ) ;
891+ assert ! ( async_pmts_msgs. is_empty( ) ) ;
892+ assert ! ( nodes[ 0 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
812893}
813894
814895#[ test]
0 commit comments