Add FewValidatorsBeaconState
for testing
This commit is contained in:
parent
5ba069c774
commit
7a67d34293
@ -13,7 +13,7 @@ use test_random_derive::TestRandom;
|
|||||||
use tree_hash::TreeHash;
|
use tree_hash::TreeHash;
|
||||||
use tree_hash_derive::{CachedTreeHash, 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 beacon_state_types;
|
||||||
mod epoch_cache;
|
mod epoch_cache;
|
||||||
|
@ -13,3 +13,12 @@ impl BeaconStateTypes for FoundationStateParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub type FoundationBeaconState = BeaconState<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>;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#![cfg(test)]
|
#![cfg(test)]
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::beacon_state::FewValidatorsBeaconState;
|
||||||
use crate::test_utils::*;
|
use crate::test_utils::*;
|
||||||
use swap_or_not_shuffle::shuffle_list;
|
use swap_or_not_shuffle::shuffle_list;
|
||||||
|
|
||||||
@ -104,7 +105,7 @@ fn builds_sane_current_epoch_cache() {
|
|||||||
let mut spec = ChainSpec::few_validators();
|
let mut spec = ChainSpec::few_validators();
|
||||||
spec.shard_count = 4;
|
spec.shard_count = 4;
|
||||||
let validator_count = (spec.shard_count * spec.target_committee_size) + 1;
|
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(
|
do_sane_cache_test(
|
||||||
state.clone(),
|
state.clone(),
|
||||||
state.current_epoch(&spec),
|
state.current_epoch(&spec),
|
||||||
@ -121,7 +122,7 @@ fn builds_sane_previous_epoch_cache() {
|
|||||||
let mut spec = ChainSpec::few_validators();
|
let mut spec = ChainSpec::few_validators();
|
||||||
spec.shard_count = 2;
|
spec.shard_count = 2;
|
||||||
let validator_count = (spec.shard_count * spec.target_committee_size) + 1;
|
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(
|
do_sane_cache_test(
|
||||||
state.clone(),
|
state.clone(),
|
||||||
state.previous_epoch(&spec),
|
state.previous_epoch(&spec),
|
||||||
@ -138,7 +139,8 @@ fn builds_sane_next_without_update_epoch_cache() {
|
|||||||
let mut spec = ChainSpec::few_validators();
|
let mut spec = ChainSpec::few_validators();
|
||||||
spec.shard_count = 2;
|
spec.shard_count = 2;
|
||||||
let validator_count = (spec.shard_count * spec.target_committee_size) + 1;
|
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);
|
state.validator_registry_update_epoch = state.slot.epoch(spec.slots_per_epoch);
|
||||||
do_sane_cache_test(
|
do_sane_cache_test(
|
||||||
state.clone(),
|
state.clone(),
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#![cfg(test)]
|
#![cfg(test)]
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::beacon_state::{FewValidatorsBeaconState, FoundationBeaconState};
|
||||||
use crate::test_utils::*;
|
use crate::test_utils::*;
|
||||||
|
|
||||||
ssz_tests!(FoundationBeaconState);
|
ssz_tests!(FoundationBeaconState);
|
||||||
@ -46,7 +47,7 @@ fn test_cache_initialization<'a, T: BeaconStateTypes>(
|
|||||||
#[test]
|
#[test]
|
||||||
fn cache_initialization() {
|
fn cache_initialization() {
|
||||||
let spec = ChainSpec::few_validators();
|
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();
|
TestingBeaconStateBuilder::from_default_keypairs_file_if_exists(16, &spec).build();
|
||||||
|
|
||||||
state.slot = (spec.genesis_epoch + 1).start_slot(spec.slots_per_epoch);
|
state.slot = (spec.genesis_epoch + 1).start_slot(spec.slots_per_epoch);
|
||||||
|
@ -36,7 +36,6 @@ pub mod slot_epoch;
|
|||||||
pub mod slot_height;
|
pub mod slot_height;
|
||||||
pub mod validator;
|
pub mod validator;
|
||||||
|
|
||||||
use beacon_state::FoundationBeaconState;
|
|
||||||
use ethereum_types::{H160, H256, U256};
|
use ethereum_types::{H160, H256, U256};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user