Skip to content

Commit 65b0fa3

Browse files
committed
Introduce test for retry_tick_occurred
1 parent f3efda6 commit 65b0fa3

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

lightning/src/ln/offers_tests.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
521521
expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
522522
}
523523

524-
/// Checks that an offer can be paid through a one-hop blinded path and that ephemeral pubkeys are
525-
/// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
526-
/// introduction node of the blinded path.
527-
#[test]
528-
fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
524+
fn do_creates_and_pays_for_offer_using_one_hop_blinded_path(with_retry_tick_occurred: bool) {
529525
let chanmon_cfgs = create_chanmon_cfgs(2);
530526
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
531527
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
@@ -552,7 +548,14 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
552548
bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
553549
expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
554550

555-
let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
551+
let mut onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
552+
553+
// Simulating a scenario where the original onion_message is lost before reaching Alice.
554+
// However, the retry_timer_tick mechanism ensures regeneration of the onion_message.
555+
if with_retry_tick_occurred {
556+
bob.node.timer_tick_occurred();
557+
onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
558+
}
556559
alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
557560

558561
let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
@@ -571,6 +574,15 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
571574
let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
572575
bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
573576

577+
if with_retry_tick_occurred {
578+
// We expect no more OffersMessage to be enqueued by this point, after the retry tick has occurred.
579+
bob.node.timer_tick_occurred();
580+
let result = bob.onion_messenger.next_onion_message_for_peer(alice_id);
581+
match result {
582+
Some(_) => panic!("Unexpected message enqueued after retry tick."),
583+
None => assert!(true),
584+
}
585+
}
574586
let invoice = extract_invoice(bob, &onion_message);
575587
assert_eq!(invoice.amount_msats(), 10_000_000);
576588
assert_ne!(invoice.signing_pubkey(), alice_id);
@@ -586,6 +598,16 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
586598
expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
587599
}
588600

601+
602+
/// Checks that an offer can be paid through a one-hop blinded path and that ephemeral pubkeys are
603+
/// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
604+
/// introduction node of the blinded path.
605+
#[test]
606+
fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
607+
do_creates_and_pays_for_offer_using_one_hop_blinded_path(false);
608+
do_creates_and_pays_for_offer_using_one_hop_blinded_path(true);
609+
}
610+
589611
/// Checks that a refund can be paid through a one-hop blinded path and that ephemeral pubkeys are
590612
/// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
591613
/// introduction node of the blinded path.

0 commit comments

Comments
 (0)