From 2c6b40be7894f93727c225c1850c3abf29fec623 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Tue, 29 Oct 2019 12:51:32 +1100 Subject: [PATCH] Allow slot clock to work on genesis (#573) * Allow slot clock to work on genesis * Loose over-strict requirements for slot clock tests --- eth2/utils/slot_clock/src/system_time_slot_clock.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/eth2/utils/slot_clock/src/system_time_slot_clock.rs b/eth2/utils/slot_clock/src/system_time_slot_clock.rs index d2ebd42ea..23159e79d 100644 --- a/eth2/utils/slot_clock/src/system_time_slot_clock.rs +++ b/eth2/utils/slot_clock/src/system_time_slot_clock.rs @@ -29,10 +29,10 @@ impl SlotClock for SystemTimeSlotClock { let now = SystemTime::now().duration_since(UNIX_EPOCH).ok()?; let genesis = self.genesis_duration; - if now > genesis { + if now >= genesis { let since_genesis = now .checked_sub(genesis) - .expect("Control flow ensures now is greater than genesis"); + .expect("Control flow ensures now is greater than or equal to genesis"); let slot = Slot::from((since_genesis.as_millis() / self.slot_duration.as_millis()) as u64); Some(slot + self.genesis_slot) @@ -50,7 +50,7 @@ impl SlotClock for SystemTimeSlotClock { genesis + slot * self.slot_duration }; - if now > genesis { + if now >= genesis { Some( slot_start(self.now()? + 1) .checked_sub(now) @@ -100,12 +100,12 @@ mod tests { let clock = SystemTimeSlotClock::new(genesis_slot, prior_genesis(500), Duration::from_secs(1)); assert_eq!(clock.now(), Some(Slot::new(0))); - assert!(clock.duration_to_next_slot().unwrap() < Duration::from_millis(500)); + assert!(clock.duration_to_next_slot().unwrap() <= Duration::from_millis(500)); let clock = SystemTimeSlotClock::new(genesis_slot, prior_genesis(1_500), Duration::from_secs(1)); assert_eq!(clock.now(), Some(Slot::new(1))); - assert!(clock.duration_to_next_slot().unwrap() < Duration::from_millis(500)); + assert!(clock.duration_to_next_slot().unwrap() <= Duration::from_millis(500)); } #[test]