Skip to content

Commit 80f5205

Browse files
committed
Introduce test for retry_tick_occurred
1 parent 5811f52 commit 80f5205

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

lightning/src/ln/offers_tests.rs

+28-6
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
526526
expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
527527
}
528528

529-
/// Checks that an offer can be paid through a one-hop blinded path and that ephemeral pubkeys are
530-
/// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
531-
/// introduction node of the blinded path.
532-
#[test]
533-
fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
529+
fn do_creates_and_pays_for_offer_using_one_hop_blinded_path(with_retry_tick_occurred: bool) {
534530
let chanmon_cfgs = create_chanmon_cfgs(2);
535531
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
536532
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
@@ -557,7 +553,14 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
557553
bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
558554
expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
559555

560-
let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
556+
let mut onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
557+
558+
// Simulating a scenario where the original onion_message is lost before reaching Alice.
559+
// However, the retry_timer_tick mechanism ensures regeneration of the onion_message.
560+
if with_retry_tick_occurred {
561+
bob.node.timer_tick_occurred();
562+
onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
563+
}
561564
alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
562565

563566
let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
@@ -578,6 +581,15 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
578581
let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
579582
bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
580583

584+
if with_retry_tick_occurred {
585+
// We expect no more OffersMessage to be enqueued by this point, after the retry tick has occurred.
586+
bob.node.timer_tick_occurred();
587+
let result = bob.onion_messenger.next_onion_message_for_peer(alice_id);
588+
match result {
589+
Some(_) => panic!("Unexpected message enqueued after retry tick."),
590+
None => assert!(true),
591+
}
592+
}
581593
let invoice = extract_invoice(bob, &onion_message);
582594
assert_eq!(invoice.amount_msats(), 10_000_000);
583595
assert_ne!(invoice.signing_pubkey(), alice_id);
@@ -593,6 +605,16 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
593605
expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
594606
}
595607

608+
609+
/// Checks that an offer can be paid through a one-hop blinded path and that ephemeral pubkeys are
610+
/// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
611+
/// introduction node of the blinded path.
612+
#[test]
613+
fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
614+
do_creates_and_pays_for_offer_using_one_hop_blinded_path(false);
615+
do_creates_and_pays_for_offer_using_one_hop_blinded_path(true);
616+
}
617+
596618
/// Checks that a refund can be paid through a one-hop blinded path and that ephemeral pubkeys are
597619
/// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
598620
/// introduction node of the blinded path.

0 commit comments

Comments
 (0)