@@ -2517,3 +2517,86 @@ fn no_double_pay_with_stale_channelmanager() {
25172517 // generated in response to the duplicate invoice.
25182518 assert ! ( nodes[ 0 ] . node. get_and_clear_pending_events( ) . is_empty( ) ) ;
25192519}
2520+
2521+ // Pay and offer while adding the contacts information the invoice request!
2522+ #[ test]
2523+ fn pay_offer_and_add_contacts_info_blip42 ( ) {
2524+ let mut features = channelmanager:: provided_init_features ( & accept_forward_cfg) ;
2525+ features. set_onion_messages_optional ( ) ;
2526+ features. set_route_blinding_optional ( ) ;
2527+
2528+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
2529+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
2530+
2531+ * node_cfgs[ 1 ] . override_init_features . borrow_mut ( ) = Some ( features) ;
2532+
2533+ let node_chanmgrs = create_node_chanmgrs (
2534+ 2 , & node_cfgs, & [ None , None ]
2535+ ) ;
2536+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
2537+
2538+ create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 10_000_000 , 1_000_000_000 ) ;
2539+
2540+ let ( alice, bob) = ( & nodes[ 0 ] , & nodes[ 1 ] ) ;
2541+ let alice_id = alice. node . get_our_node_id ( ) ;
2542+ let bob_id = bob. node . get_our_node_id ( ) ;
2543+
2544+ // For the Offer Builder we do not need to change anything
2545+ // because the contacts are not included in the offer itself.
2546+ let offer = alice. node
2547+ . create_offer_builder ( )
2548+ . unwrap ( )
2549+ . amount_msats ( 10_000_000 )
2550+ . build ( )
2551+ . unwrap ( ) ;
2552+
2553+
2554+ assert_ne ! ( offer. issuer_signing_pubkey( ) , Some ( alice_id) ) ;
2555+ assert ! ( !offer. paths( ) . is_empty( ) ) ;
2556+
2557+ let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
2558+ bob. node . pay_for_offer ( & offer, None , payment_id, Default :: default ( ) ) . unwrap ( ) ;
2559+ // Probably a good place to add the information that we use for the contact secret.
2560+ // but need to double check if the sender of the invoice request still need to ask anything.
2561+ expect_recent_payment ! ( bob, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
2562+ let onion_message = alice. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ;
2563+
2564+ let ( invoice_request, reply_path) = extract_invoice_request ( alice, & onion_message) ;
2565+ // TODO: check if the invoice request contains the contact information.
2566+
2567+ let payment_context = PaymentContext :: Bolt12Offer ( Bolt12OfferContext {
2568+ offer_id : offer. id ( ) ,
2569+ invoice_request : InvoiceRequestFields {
2570+ payer_signing_pubkey : invoice_request. payer_signing_pubkey ( ) ,
2571+ quantity : None ,
2572+ payer_note_truncated : None ,
2573+ human_readable_name : None ,
2574+ } ,
2575+ } ) ;
2576+ assert_eq ! ( invoice_request. amount_msats( ) , Some ( 10_000_000 ) ) ;
2577+ assert_ne ! ( invoice_request. payer_signing_pubkey( ) , bob_id) ;
2578+ assert ! ( check_compact_path_introduction_node( & reply_path, alice, bob_id) ) ;
2579+
2580+ let onion_message = alice. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ;
2581+ bob. onion_messenger . handle_onion_message ( alice_id, & onion_message) ;
2582+
2583+ let ( invoice, reply_path) = extract_invoice ( bob, & onion_message) ;
2584+ assert_eq ! ( invoice. amount_msats( ) , 10_000_000 ) ;
2585+ assert_ne ! ( invoice. signing_pubkey( ) , alice_id) ;
2586+ assert ! ( !invoice. payment_paths( ) . is_empty( ) ) ;
2587+
2588+ for path in invoice. payment_paths ( ) {
2589+ assert_eq ! ( path. introduction_node( ) , & IntroductionNode :: NodeId ( alice_id) ) ;
2590+ }
2591+ assert ! ( check_compact_path_introduction_node( & reply_path, bob, alice_id) ) ;
2592+
2593+ route_bolt12_payment ( bob, & [ alice] , & invoice) ;
2594+ expect_recent_payment ! ( bob, RecentPaymentDetails :: Pending , payment_id) ;
2595+
2596+ claim_bolt12_payment ( bob, & [ alice] , payment_context, & invoice) ;
2597+ expect_recent_payment ! ( bob, RecentPaymentDetails :: Fulfilled , payment_id) ;
2598+
2599+ // TODO: now should be possible that alice will be able to repay bob without that
2600+ // bob give any offer in exchange!! but there is a contact list somewhere that allow
2601+ // to run something like bob.pay_for_contact(alice_contact_name, amount);
2602+ }
0 commit comments