Add FewValidatorsBeaconState for testing

This commit is contained in:
Paul Hauner 2019-05-08 13:26:19 +10:00
parent 5ba069c774
commit 7a67d34293
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
5 changed files with 17 additions and 6 deletions

View File

@ -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;

View File

@ -13,3 +13,12 @@ impl BeaconStateTypes for FoundationStateParams {
}
pub type FoundationBeaconState = BeaconState<FoundationStateParams>;
#[derive(Clone, PartialEq, Debug)]
pub struct FewValidatorsStateParams;
impl BeaconStateTypes for FewValidatorsStateParams {
type NumLatestRandaoMixes = U8192;
}
pub type FewValidatorsBeaconState = BeaconState<FewValidatorsStateParams>;

View File

@ -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(),

View File

@ -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<Keypair>) =
let (mut state, _keypairs): (FewValidatorsBeaconState, Vec<Keypair>) =
TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(16, &spec).build();
state.slot = (spec.genesis_epoch + 1).start_slot(spec.slots_per_epoch);

View File

@ -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;