Disable use of system time in tests

This commit is contained in:
Emilia Hane
2023-02-14 13:33:38 +01:00
parent 148385eb70
commit 73c7ad73b8
29 changed files with 485 additions and 559 deletions

View File

@@ -5,7 +5,7 @@ use std::sync::Mutex;
use std::time::Duration;
use beacon_chain::test_utils::{
AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralTestingSlotClockHarnessType,
AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType,
};
use beacon_chain::{
BeaconChain, BeaconChainError, BeaconForkChoiceStore, ChainConfig, ForkChoiceError,
@@ -35,7 +35,7 @@ pub enum MutationDelay {
/// A helper struct to make testing fork choice more ergonomic and less repetitive.
struct ForkChoiceTest {
harness: BeaconChainHarness<EphemeralTestingSlotClockHarnessType<E>>,
harness: BeaconChainHarness<EphemeralHarnessType<E>>,
}
/// Allows us to use `unwrap` in some cases.
@@ -397,7 +397,7 @@ impl ForkChoiceTest {
mut comparison_func: G,
) -> Self
where
F: FnMut(&mut IndexedAttestation<E>, &BeaconChain<EphemeralTestingSlotClockHarnessType<E>>),
F: FnMut(&mut IndexedAttestation<E>, &BeaconChain<EphemeralHarnessType<E>>),
G: FnMut(Result<(), BeaconChainError>),
{
let head = self.harness.chain.head_snapshot();

View File

@@ -10,9 +10,7 @@ use crate::{
per_block_processing::{process_operations, verify_exit::verify_exit},
BlockSignatureStrategy, ConsensusContext, VerifyBlockRoot, VerifySignatures,
};
use beacon_chain::test_utils::{
BeaconChainHarness, EphemeralTestingSlotClockHarnessType as HarnessType,
};
use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType};
use lazy_static::lazy_static;
use ssz_types::Bitfield;
use test_utils::generate_deterministic_keypairs;
@@ -32,11 +30,11 @@ lazy_static! {
async fn get_harness<E: EthSpec>(
epoch_offset: u64,
num_validators: usize,
) -> BeaconChainHarness<HarnessType<E>> {
) -> BeaconChainHarness<EphemeralHarnessType<E>> {
// Set the state and block to be in the last slot of the `epoch_offset`th epoch.
let last_slot_of_epoch =
(MainnetEthSpec::genesis_epoch() + epoch_offset).end_slot(E::slots_per_epoch());
let harness = BeaconChainHarness::<HarnessType<E>>::builder(E::default())
let harness = BeaconChainHarness::<EphemeralHarnessType<E>>::builder(E::default())
.default_spec()
.keypairs(KEYPAIRS[0..num_validators].to_vec())
.fresh_ephemeral_store()

View File

@@ -1,10 +1,10 @@
use beacon_chain::test_utils::{BeaconChainHarness, EphemeralTestingSlotClockHarnessType};
use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType};
use types::{BeaconState, EthSpec, MainnetEthSpec};
const TREE_HASH_LOOPS: usize = 1_000;
const VALIDATOR_COUNT: usize = 1_000;
fn get_harness<T: EthSpec>() -> BeaconChainHarness<EphemeralTestingSlotClockHarnessType<T>> {
fn get_harness<T: EthSpec>() -> BeaconChainHarness<EphemeralHarnessType<T>> {
let harness = BeaconChainHarness::builder(T::default())
.default_spec()
.deterministic_keypairs(VALIDATOR_COUNT)

View File

@@ -1,8 +1,6 @@
#![cfg(test)]
use crate::test_utils::*;
use beacon_chain::test_utils::{
BeaconChainHarness, EphemeralTestingSlotClockHarnessType as HarnessType,
};
use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType};
use beacon_chain::types::*;
use swap_or_not_shuffle::shuffle_list;
@@ -13,7 +11,7 @@ lazy_static! {
static ref KEYPAIRS: Vec<Keypair> = generate_deterministic_keypairs(VALIDATOR_COUNT);
}
fn get_harness<E: EthSpec>(validator_count: usize) -> BeaconChainHarness<HarnessType<E>> {
fn get_harness<E: EthSpec>(validator_count: usize) -> BeaconChainHarness<EphemeralHarnessType<E>> {
let harness = BeaconChainHarness::builder(E::default())
.default_spec()
.keypairs(KEYPAIRS[0..validator_count].to_vec())

View File

@@ -2,8 +2,8 @@
use crate::test_utils::*;
use crate::test_utils::{SeedableRng, XorShiftRng};
use beacon_chain::test_utils::{
interop_genesis_state_with_eth1, test_spec, BeaconChainHarness,
EphemeralTestingSlotClockHarnessType as HarnessType, DEFAULT_ETH1_BLOCK_HASH,
interop_genesis_state_with_eth1, test_spec, BeaconChainHarness, EphemeralHarnessType,
DEFAULT_ETH1_BLOCK_HASH,
};
use beacon_chain::types::{
test_utils::TestRandom, BeaconState, BeaconStateAltair, BeaconStateBase, BeaconStateError,
@@ -28,7 +28,7 @@ lazy_static! {
async fn get_harness<E: EthSpec>(
validator_count: usize,
slot: Slot,
) -> BeaconChainHarness<HarnessType<E>> {
) -> BeaconChainHarness<EphemeralHarnessType<E>> {
let harness = BeaconChainHarness::builder(E::default())
.default_spec()
.keypairs(KEYPAIRS[0..validator_count].to_vec())