@@ -1226,6 +1226,78 @@ fn pays_bolt12_invoice_asynchronously() {
1226
1226
) ;
1227
1227
}
1228
1228
1229
+ #[ test]
1230
+ fn send_invoice_request_response_asynchronously ( ) {
1231
+ let mut manually_respond_cfg = test_default_channel_config ( ) ;
1232
+ manually_respond_cfg. manually_handle_bolt12_messages = true ;
1233
+
1234
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
1235
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1236
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ Some ( manually_respond_cfg) , None ] ) ;
1237
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1238
+
1239
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 10_000_000 , 1_000_000_000 ) ;
1240
+
1241
+ let alice = & nodes[ 0 ] ;
1242
+ let alice_id = alice. node . get_our_node_id ( ) ;
1243
+ let bob = & nodes[ 1 ] ;
1244
+ let bob_id = bob. node . get_our_node_id ( ) ;
1245
+
1246
+ let offer = alice. node
1247
+ . create_offer_builder ( None ) . unwrap ( )
1248
+ . amount_msats ( 10_000_000 )
1249
+ . build ( ) . unwrap ( ) ;
1250
+
1251
+ let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
1252
+ bob. node . pay_for_offer ( & offer, None , None , None , payment_id, Retry :: Attempts ( 0 ) , None ) . unwrap ( ) ;
1253
+ expect_recent_payment ! ( bob, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
1254
+
1255
+ let onion_message = bob. onion_messenger . next_onion_message_for_peer ( alice_id) . unwrap ( ) ;
1256
+ alice. onion_messenger . handle_onion_message ( bob_id, & onion_message) ;
1257
+
1258
+ let ( invoice_request, context, responder) = match get_event ! ( alice, Event :: InvoiceRequestReceived ) {
1259
+ Event :: InvoiceRequestReceived { invoice_request, context, responder } => {
1260
+ ( invoice_request, context, responder)
1261
+ }
1262
+ _ => panic ! ( "No Event::InvoiceReceived" ) ,
1263
+ } ;
1264
+
1265
+ let payment_context = PaymentContext :: Bolt12Offer ( Bolt12OfferContext {
1266
+ offer_id : offer. id ( ) ,
1267
+ invoice_request : InvoiceRequestFields {
1268
+ payer_id : invoice_request. payer_id ( ) ,
1269
+ quantity : None ,
1270
+ payer_note_truncated : None ,
1271
+ } ,
1272
+ } ) ;
1273
+
1274
+ assert_eq ! ( invoice_request. amount_msats( ) , None ) ;
1275
+ assert_ne ! ( invoice_request. payer_id( ) , bob_id) ;
1276
+ assert_eq ! ( responder. as_ref( ) . unwrap( ) . reply_path. introduction_node( ) , & IntroductionNode :: NodeId ( bob_id) ) ;
1277
+
1278
+ match alice. node . send_invoice_request_response ( invoice_request, context, None , responder. unwrap ( ) ) {
1279
+ Ok ( ( ) ) => ( ) ,
1280
+ Err ( _) => panic ! ( "Unexpected Error." )
1281
+ }
1282
+
1283
+ let onion_message = alice. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ;
1284
+ bob. onion_messenger . handle_onion_message ( alice_id, & onion_message) ;
1285
+
1286
+ let ( invoice, _) = extract_invoice ( bob, & onion_message) ;
1287
+ assert_eq ! ( invoice. amount_msats( ) , 10_000_000 ) ;
1288
+ assert_ne ! ( invoice. signing_pubkey( ) , alice_id) ;
1289
+ assert ! ( !invoice. payment_paths( ) . is_empty( ) ) ;
1290
+ for path in invoice. payment_paths ( ) {
1291
+ assert_eq ! ( path. introduction_node( ) , & IntroductionNode :: NodeId ( alice_id) ) ;
1292
+ }
1293
+
1294
+ route_bolt12_payment ( bob, & [ alice] , & invoice) ;
1295
+ expect_recent_payment ! ( bob, RecentPaymentDetails :: Pending , payment_id) ;
1296
+
1297
+ claim_bolt12_payment ( bob, & [ alice] , payment_context) ;
1298
+ expect_recent_payment ! ( bob, RecentPaymentDetails :: Fulfilled , payment_id) ;
1299
+ }
1300
+
1229
1301
/// Checks that an offer can be created using an unannounced node as a blinded path's introduction
1230
1302
/// node. This is only preferred if there are no other options which may indicated either the offer
1231
1303
/// is intended for the unannounced node or that the node is actually announced (e.g., an LSP) but
0 commit comments