From 59c9326e0d38278a2d7997d5c201affb556fa787 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Sat, 16 Apr 2022 13:59:07 +0800 Subject: [PATCH] fix tests --- core/src/replay_stage.rs | 20 +++++++++++++------- poh/src/poh_recorder.rs | 7 ++++--- runtime/src/bank.rs | 13 +++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index 1796ae2b64e127..5815c4c02783e6 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -6002,13 +6002,19 @@ pub mod tests { assert_eq!(tower.last_voted_slot().unwrap(), 1); // Create a bank where the last vote transaction will have expired - let expired_bank = Arc::new(Bank::new_from_parent( - &bank2, - &Pubkey::default(), - bank2.slot() + MAX_PROCESSING_AGE as Slot, - )); - expired_bank.fill_bank_with_ticks(); - expired_bank.freeze(); + let expired_bank = { + let mut parent_bank = bank2.clone(); + for _ in 0..MAX_PROCESSING_AGE { + parent_bank = Arc::new(Bank::new_from_parent( + &parent_bank, + &Pubkey::default(), + parent_bank.slot() + 1, + )); + parent_bank.fill_bank_with_ticks(); + parent_bank.freeze(); + } + parent_bank + }; // Now trying to refresh the vote for slot 1 will succeed because the recent blockhash // of the last vote transaction has expired diff --git a/poh/src/poh_recorder.rs b/poh/src/poh_recorder.rs index 1163355a86cf86..6160690704f5fc 100644 --- a/poh/src/poh_recorder.rs +++ b/poh/src/poh_recorder.rs @@ -1962,12 +1962,13 @@ mod tests { ); //create a new bank let bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), 2)); - //put 2 slots worth of virtual ticks into poh - for _ in 0..(bank.ticks_per_slot() * 2) { + // add virtual ticks into poh for slots 0, 1, and 2 + for _ in 0..(bank.ticks_per_slot() * 3) { poh_recorder.tick(); } poh_recorder.set_bank(&bank); - assert_eq!(Some(false), bank.check_hash_age(&genesis_hash, 1)); + assert_eq!(Some(false), bank.check_hash_age(&genesis_hash, 0)); + assert_eq!(Some(true), bank.check_hash_age(&genesis_hash, 1)); } } diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 6fc6e6f9a3ec48..2b86c80e9c213c 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -6483,16 +6483,9 @@ impl Bank { } pub fn fill_bank_with_ticks(&self) { - let parent_distance = if self.slot() == 0 { - 1 - } else { - self.slot() - self.parent_slot() - }; - for _ in 0..parent_distance { - let last_blockhash = self.last_blockhash(); - while self.last_blockhash() == last_blockhash { - self.register_tick(&Hash::new_unique()) - } + let last_blockhash = self.last_blockhash(); + while self.last_blockhash() == last_blockhash { + self.register_tick(&Hash::new_unique()) } }