From 7a67d34293b1121d2aa49b3eb1e446f80913ff13 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Wed, 8 May 2019 13:26:19 +1000 Subject: [PATCH] Add `FewValidatorsBeaconState` for testing --- eth2/types/src/beacon_state.rs | 2 +- eth2/types/src/beacon_state/beacon_state_types.rs | 9 +++++++++ eth2/types/src/beacon_state/epoch_cache/tests.rs | 8 +++++--- eth2/types/src/beacon_state/tests.rs | 3 ++- eth2/types/src/lib.rs | 1 - 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/eth2/types/src/beacon_state.rs b/eth2/types/src/beacon_state.rs index 46c4ae87d..02210443f 100644 --- a/eth2/types/src/beacon_state.rs +++ b/eth2/types/src/beacon_state.rs @@ -13,7 +13,7 @@ use test_random_derive::TestRandom; use tree_hash::TreeHash; use tree_hash_derive::{CachedTreeHash, TreeHash}; -pub use beacon_state_types::{BeaconStateTypes, FoundationBeaconState}; +pub use beacon_state_types::{BeaconStateTypes, FewValidatorsBeaconState, FoundationBeaconState}; mod beacon_state_types; mod epoch_cache; diff --git a/eth2/types/src/beacon_state/beacon_state_types.rs b/eth2/types/src/beacon_state/beacon_state_types.rs index 63c038575..887e10c84 100644 --- a/eth2/types/src/beacon_state/beacon_state_types.rs +++ b/eth2/types/src/beacon_state/beacon_state_types.rs @@ -13,3 +13,12 @@ impl BeaconStateTypes for FoundationStateParams { } pub type FoundationBeaconState = BeaconState; + +#[derive(Clone, PartialEq, Debug)] +pub struct FewValidatorsStateParams; + +impl BeaconStateTypes for FewValidatorsStateParams { + type NumLatestRandaoMixes = U8192; +} + +pub type FewValidatorsBeaconState = BeaconState; diff --git a/eth2/types/src/beacon_state/epoch_cache/tests.rs b/eth2/types/src/beacon_state/epoch_cache/tests.rs index e196560a3..182817bf6 100644 --- a/eth2/types/src/beacon_state/epoch_cache/tests.rs +++ b/eth2/types/src/beacon_state/epoch_cache/tests.rs @@ -1,6 +1,7 @@ #![cfg(test)] use super::*; +use crate::beacon_state::FewValidatorsBeaconState; use crate::test_utils::*; use swap_or_not_shuffle::shuffle_list; @@ -104,7 +105,7 @@ fn builds_sane_current_epoch_cache() { let mut spec = ChainSpec::few_validators(); spec.shard_count = 4; let validator_count = (spec.shard_count * spec.target_committee_size) + 1; - let state: FoundationBeaconState = setup_sane_cache_test(validator_count as usize, &spec); + let state: FewValidatorsBeaconState = setup_sane_cache_test(validator_count as usize, &spec); do_sane_cache_test( state.clone(), state.current_epoch(&spec), @@ -121,7 +122,7 @@ fn builds_sane_previous_epoch_cache() { let mut spec = ChainSpec::few_validators(); spec.shard_count = 2; let validator_count = (spec.shard_count * spec.target_committee_size) + 1; - let state: FoundationBeaconState = setup_sane_cache_test(validator_count as usize, &spec); + let state: FewValidatorsBeaconState = setup_sane_cache_test(validator_count as usize, &spec); do_sane_cache_test( state.clone(), state.previous_epoch(&spec), @@ -138,7 +139,8 @@ fn builds_sane_next_without_update_epoch_cache() { let mut spec = ChainSpec::few_validators(); spec.shard_count = 2; let validator_count = (spec.shard_count * spec.target_committee_size) + 1; - let mut state: FoundationBeaconState = setup_sane_cache_test(validator_count as usize, &spec); + let mut state: FewValidatorsBeaconState = + setup_sane_cache_test(validator_count as usize, &spec); state.validator_registry_update_epoch = state.slot.epoch(spec.slots_per_epoch); do_sane_cache_test( state.clone(), diff --git a/eth2/types/src/beacon_state/tests.rs b/eth2/types/src/beacon_state/tests.rs index 759061498..b840663f0 100644 --- a/eth2/types/src/beacon_state/tests.rs +++ b/eth2/types/src/beacon_state/tests.rs @@ -1,5 +1,6 @@ #![cfg(test)] use super::*; +use crate::beacon_state::{FewValidatorsBeaconState, FoundationBeaconState}; use crate::test_utils::*; ssz_tests!(FoundationBeaconState); @@ -46,7 +47,7 @@ fn test_cache_initialization<'a, T: BeaconStateTypes>( #[test] fn cache_initialization() { let spec = ChainSpec::few_validators(); - let (mut state, _keypairs): (FoundationBeaconState, Vec) = + let (mut state, _keypairs): (FewValidatorsBeaconState, Vec) = TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(16, &spec).build(); state.slot = (spec.genesis_epoch + 1).start_slot(spec.slots_per_epoch); diff --git a/eth2/types/src/lib.rs b/eth2/types/src/lib.rs index efe7f2327..1b8ca7453 100644 --- a/eth2/types/src/lib.rs +++ b/eth2/types/src/lib.rs @@ -36,7 +36,6 @@ pub mod slot_epoch; pub mod slot_height; pub mod validator; -use beacon_state::FoundationBeaconState; use ethereum_types::{H160, H256, U256}; use std::collections::HashMap;