issuance.rs (1394B)
1 use radroots_domain::{ContextError, FIRST_ISSUANCE_MAX_SECONDS, IssuanceWindow, UnixSeconds}; 2 3 fn time(value: u64) -> UnixSeconds { 4 UnixSeconds::new(value).unwrap() 5 } 6 7 #[test] 8 fn preparation_captures_exact_fixed_window_and_shorter_authorization() { 9 assert_eq!(FIRST_ISSUANCE_MAX_SECONDS, 120); 10 for (prepared, authorization, deadline) in [ 11 (100, 900, 220), 12 (100, 150, 150), 13 (100, 101, 101), 14 (253_402_300_798, 253_402_300_799, 253_402_300_799), 15 ] { 16 let window = IssuanceWindow::capture(time(prepared), time(authorization)).unwrap(); 17 assert_eq!(window.prepared_at(), time(prepared)); 18 assert_eq!(window.first_issue_not_after(), time(deadline)); 19 assert_eq!( 20 IssuanceWindow::new(time(prepared), time(deadline)).unwrap(), 21 window 22 ); 23 } 24 } 25 26 #[test] 27 fn invalid_or_extended_retained_windows_are_refused_without_reading_a_clock() { 28 for (prepared, deadline) in [(0, 1), (100, 0), (100, 100), (100, 99), (100, 221)] { 29 assert_eq!( 30 IssuanceWindow::new(time(prepared), time(deadline)), 31 Err(ContextError::OutOfRange) 32 ); 33 } 34 for (prepared, deadline) in [(0, 100), (100, 0), (100, 100), (100, 99)] { 35 assert_eq!( 36 IssuanceWindow::capture(time(prepared), time(deadline)), 37 Err(ContextError::OutOfRange) 38 ); 39 } 40 }