Skip to content

Commit 9b4daa4

Browse files
committed
Introduce test for check asynchronous Invoice Request Response
1 parent 3a37880 commit 9b4daa4

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

lightning/src/ln/offers_tests.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,78 @@ fn pays_bolt12_invoice_asynchronously() {
12271227
);
12281228
}
12291229

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

lightning/src/onion_message/messenger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl OnionMessageRecipient {
347347
#[derive(Clone, Debug, Eq, PartialEq)]
348348
pub struct Responder {
349349
/// The path along which a response can be sent.
350-
reply_path: BlindedMessagePath,
350+
pub(crate) reply_path: BlindedMessagePath,
351351
}
352352

353353
impl_writeable_tlv_based!(Responder, {

0 commit comments

Comments
 (0)