@@ -483,6 +483,25 @@ mod tests {
483
483
. unwrap ( )
484
484
}
485
485
486
+ fn will_expire_in_1_sec_invoice ( payment_preimage : PaymentPreimage ) -> Invoice {
487
+ let payment_hash = Sha256 :: hash ( & payment_preimage. 0 ) ;
488
+ let private_key = SecretKey :: from_slice ( & [ 42 ; 32 ] ) . unwrap ( ) ;
489
+ let timestamp = SystemTime :: now ( )
490
+ . checked_sub ( Duration :: from_secs ( DEFAULT_EXPIRY_TIME - 1 ) )
491
+ . unwrap ( ) ;
492
+ InvoiceBuilder :: new ( Currency :: Bitcoin )
493
+ . description ( "test" . into ( ) )
494
+ . payment_hash ( payment_hash)
495
+ . payment_secret ( PaymentSecret ( [ 0 ; 32 ] ) )
496
+ . timestamp ( timestamp)
497
+ . min_final_cltv_expiry ( 144 )
498
+ . amount_milli_satoshis ( 128 )
499
+ . build_signed ( |hash| {
500
+ Secp256k1 :: new ( ) . sign_recoverable ( hash, & private_key)
501
+ } )
502
+ . unwrap ( )
503
+ }
504
+
486
505
#[ test]
487
506
fn pays_invoice_on_first_attempt ( ) {
488
507
let event_handled = core:: cell:: RefCell :: new ( false ) ;
@@ -692,7 +711,26 @@ mod tests {
692
711
693
712
let payment_preimage = PaymentPreimage ( [ 1 ; 32 ] ) ;
694
713
let invoice = expired_invoice ( payment_preimage) ;
714
+ if let PaymentError :: Invoice ( msg) = invoice_payer. pay_invoice ( & invoice) . unwrap_err ( ) {
715
+ assert_eq ! ( msg, "Invoice expired prior to send" ) ;
716
+ } else { panic ! ( "Expected Invoice Error" ) ; }
717
+ }
718
+
719
+ #[ test]
720
+ fn fails_retrying_invoice_after_expiration ( ) {
721
+ let event_handled = core:: cell:: RefCell :: new ( false ) ;
722
+ let event_handler = |_: & _ | { * event_handled. borrow_mut ( ) = true ; } ;
723
+
724
+ let payer = TestPayer :: new ( ) ;
725
+ let router = TestRouter { } ;
726
+ let logger = TestLogger :: new ( ) ;
727
+ let invoice_payer =
728
+ InvoicePayer :: new ( & payer, router, & logger, event_handler, RetryAttempts ( 2 ) ) ;
729
+
730
+ let payment_preimage = PaymentPreimage ( [ 1 ; 32 ] ) ;
731
+ let invoice = will_expire_in_1_sec_invoice ( payment_preimage) ;
695
732
let payment_id = Some ( invoice_payer. pay_invoice ( & invoice) . unwrap ( ) ) ;
733
+ std:: thread:: sleep ( Duration :: from_secs ( 2 ) ) ;
696
734
assert_eq ! ( * payer. attempts. borrow( ) , 1 ) ;
697
735
698
736
let event = Event :: PaymentPathFailed {
0 commit comments