Skip to content

Commit c8c3349

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 9f91eb4 commit c8c3349

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
@@ -650,11 +650,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
650650
expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
651651
}
652652

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

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

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

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

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

0 commit comments

Comments
 (0)