Skip to content

Commit 2566089

Browse files
committed
Introduce handle_message_received test
- Add a test to verify the functionality of the handle_message_received function. - Ensure the test covers scenarios where InvoiceRequest messages are retried for PendingOutboundPayments after a simulated connection loss.
1 parent 100aee7 commit 2566089

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

lightning/src/ln/offers_tests.rs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -649,11 +649,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
649649
expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
650650
}
651651

652-
/// Checks that an offer can be paid through a one-hop blinded path and that ephemeral pubkeys are
653-
/// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
654-
/// introduction node of the blinded path.
655-
#[test]
656-
fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
652+
fn do_creates_and_pays_for_offer_using_one_hop_blinded_path(with_message_retry: bool) {
657653
let chanmon_cfgs = create_chanmon_cfgs(2);
658654
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
659655
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
@@ -675,12 +671,20 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
675671
for path in offer.paths() {
676672
assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
677673
}
678-
679674
let payment_id = PaymentId([1; 32]);
680675
bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
681676
expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
682677

683-
let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
678+
let mut onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
679+
680+
// Simulate a scenario where the original onion_message is lost before reaching Alice.
681+
// Use handle_message_received to regenerate the message.
682+
// If with_message_retry is true, ensure handle_message_received executes successfully.
683+
if with_message_retry {
684+
assert!(bob.node.handle_message_received().is_ok(), "handle_message_received failed");
685+
onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
686+
}
687+
684688
alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
685689

686690
let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
@@ -695,25 +699,43 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
695699
assert_eq!(invoice_request.amount_msats(), None);
696700
assert_ne!(invoice_request.payer_id(), bob_id);
697701
assert_eq!(reply_path.introduction_node, IntroductionNode::NodeId(bob_id));
698-
699702
let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
700703
bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
701704

705+
if with_message_retry {
706+
// Expect no more OffersMessage to be enqueued by this point, even after calling
707+
// handle_message_received.
708+
assert!(bob.node.handle_message_received().is_ok(), "handle_message_received failed");
709+
710+
let result = bob.onion_messenger.next_onion_message_for_peer(alice_id);
711+
match result {
712+
Some(_) => panic!("Unexpected message enqueued after retry tick."),
713+
None => assert!(true),
714+
}
715+
}
716+
702717
let invoice = extract_invoice(bob, &onion_message);
703718
assert_eq!(invoice.amount_msats(), 10_000_000);
704719
assert_ne!(invoice.signing_pubkey(), alice_id);
705720
assert!(!invoice.payment_paths().is_empty());
706721
for (_, path) in invoice.payment_paths() {
707722
assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
708723
}
709-
710724
route_bolt12_payment(bob, &[alice], &invoice);
711725
expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
712-
713726
claim_bolt12_payment(bob, &[alice], payment_context);
714727
expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
715728
}
716729

730+
/// Checks that an offer can be paid through a one-hop blinded path and that ephemeral pubkeys are
731+
/// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
732+
/// introduction node of the blinded path.
733+
#[test]
734+
fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
735+
do_creates_and_pays_for_offer_using_one_hop_blinded_path(false);
736+
do_creates_and_pays_for_offer_using_one_hop_blinded_path(true);
737+
}
738+
717739
/// Checks that a refund can be paid through a one-hop blinded path and that ephemeral pubkeys are
718740
/// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
719741
/// introduction node of the blinded path.

0 commit comments

Comments
 (0)