Skip to content

Commit 7f5c6bd

Browse files
committed
f expiry through event.
1 parent 8717881 commit 7f5c6bd

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

lightning-invoice/src/payment.rs

+6-21
Original file line numberDiff line numberDiff line change
@@ -517,25 +517,6 @@ mod tests {
517517
.unwrap()
518518
}
519519

520-
fn will_expire_in_2_secs_invoice(payment_preimage: PaymentPreimage) -> Invoice {
521-
let payment_hash = Sha256::hash(&payment_preimage.0);
522-
let private_key = SecretKey::from_slice(&[42; 32]).unwrap();
523-
let timestamp = SystemTime::now()
524-
.checked_sub(Duration::from_secs(DEFAULT_EXPIRY_TIME - 2))
525-
.unwrap();
526-
InvoiceBuilder::new(Currency::Bitcoin)
527-
.description("test".into())
528-
.payment_hash(payment_hash)
529-
.payment_secret(PaymentSecret([0; 32]))
530-
.timestamp(timestamp)
531-
.min_final_cltv_expiry(144)
532-
.amount_milli_satoshis(128)
533-
.build_signed(|hash| {
534-
Secp256k1::new().sign_recoverable(hash, &private_key)
535-
})
536-
.unwrap()
537-
}
538-
539520
#[test]
540521
fn pays_invoice_on_first_attempt() {
541522
let event_handled = core::cell::RefCell::new(false);
@@ -769,11 +750,15 @@ mod tests {
769750
InvoicePayer::new(&payer, router, &scorer, &logger, event_handler, RetryAttempts(2));
770751

771752
let payment_preimage = PaymentPreimage([1; 32]);
772-
let invoice = will_expire_in_2_secs_invoice(payment_preimage);
753+
let invoice = invoice(payment_preimage);
773754
let payment_id = Some(invoice_payer.pay_invoice(&invoice).unwrap());
774755
std::thread::sleep(Duration::from_secs(4));
775756
assert_eq!(*payer.attempts.borrow(), 1);
776757

758+
let mut retry_data = TestRouter::retry_for_invoice(&invoice);
759+
retry_data.payee.expiry_time = Some(SystemTime::now()
760+
.checked_sub(Duration::from_secs(2)).unwrap()
761+
.duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs());
777762
let event = Event::PaymentPathFailed {
778763
payment_id,
779764
payment_hash: PaymentHash(invoice.payment_hash().clone().into_inner()),
@@ -782,7 +767,7 @@ mod tests {
782767
all_paths_failed: false,
783768
path: vec![],
784769
short_channel_id: None,
785-
retry: Some(TestRouter::retry_for_invoice(&invoice)),
770+
retry: Some(retry_data),
786771
};
787772
invoice_payer.handle_event(&event);
788773
assert_eq!(*event_handled.borrow(), true);

0 commit comments

Comments
 (0)