Skip to content

Commit 4dd148d

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

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

lightning/src/ln/offers_tests.rs

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -652,19 +652,19 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
652652
/// Checks that an offer can be paid through a one-hop blinded path and that ephemeral pubkeys are
653653
/// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
654654
/// introduction node of the blinded path.
655-
#[test]
656-
fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
657-
let chanmon_cfgs = create_chanmon_cfgs(2);
658-
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
659-
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
660-
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
655+
fn do_creates_and_pays_for_offer_using_one_hop_blinded_path(with_message_retry: bool) {
656+
let chanmon_cfgs = create_chanmon_cfgs(3);
657+
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
658+
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]);
659+
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
661660

662661
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
663662

664663
let alice = &nodes[0];
665664
let alice_id = alice.node.get_our_node_id();
666665
let bob = &nodes[1];
667666
let bob_id = bob.node.get_our_node_id();
667+
let charlie = &nodes[2];
668668

669669
let offer = alice.node
670670
.create_offer_builder(None).unwrap()
@@ -680,7 +680,15 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
680680
bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
681681
expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
682682

683-
let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
683+
let mut onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
684+
685+
// Simulating a scenario where the original onion_message is lost before reaching Alice.
686+
// However, the we receive a message from another peer ensuring regeneration of the onion_message.
687+
if with_message_retry {
688+
disconnect_peers(bob, &[charlie]);
689+
onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
690+
}
691+
684692
alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
685693

686694
let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
@@ -699,6 +707,18 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
699707
let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
700708
bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
701709

710+
if with_message_retry {
711+
// We expect no more OffersMessage to be enqueued by this point, even if we receive
712+
// some other unrelated message from another peer.
713+
connect_peers(bob, charlie);
714+
715+
let result = bob.onion_messenger.next_onion_message_for_peer(alice_id);
716+
match result {
717+
Some(_) => panic!("Unexpected message enqueued after retry tick."),
718+
None => assert!(true),
719+
}
720+
}
721+
702722
let invoice = extract_invoice(bob, &onion_message);
703723
assert_eq!(invoice.amount_msats(), 10_000_000);
704724
assert_ne!(invoice.signing_pubkey(), alice_id);
@@ -714,6 +734,15 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
714734
expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
715735
}
716736

737+
/// Checks that an offer can be paid through a one-hop blinded path and that ephemeral pubkeys are
738+
/// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
739+
/// introduction node of the blinded path.
740+
#[test]
741+
fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
742+
do_creates_and_pays_for_offer_using_one_hop_blinded_path(false);
743+
do_creates_and_pays_for_offer_using_one_hop_blinded_path(true);
744+
}
745+
717746
/// Checks that a refund can be paid through a one-hop blinded path and that ephemeral pubkeys are
718747
/// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
719748
/// introduction node of the blinded path.

0 commit comments

Comments
 (0)