Skip to content

Commit ff76783

Browse files
committed
Introduce test for retry_tick_occurred
1 parent 0dfc4aa commit ff76783

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
@@ -523,11 +523,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
523523
expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
524524
}
525525

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

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

560563
let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
@@ -573,6 +576,15 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
573576
let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
574577
bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
575578

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

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

0 commit comments

Comments
 (0)