ef_tests: sanity slot tests + block headers

This commit is contained in:
Michael Sproul 2019-06-04 16:35:33 +10:00
parent cf62ea090b
commit c05cf6c256
No known key found for this signature in database
GPG Key ID: 77B1309D2E54E914
6 changed files with 124 additions and 1 deletions

View File

@ -11,10 +11,12 @@ mod epoch_processing_crosslinks;
mod epoch_processing_registry_updates;
mod operations_attestation;
mod operations_attester_slashing;
mod operations_block_header;
mod operations_deposit;
mod operations_exit;
mod operations_proposer_slashing;
mod operations_transfer;
mod sanity_slots;
mod shuffling;
mod ssz_generic;
mod ssz_static;
@ -29,10 +31,12 @@ pub use epoch_processing_crosslinks::*;
pub use epoch_processing_registry_updates::*;
pub use operations_attestation::*;
pub use operations_attester_slashing::*;
pub use operations_block_header::*;
pub use operations_deposit::*;
pub use operations_exit::*;
pub use operations_proposer_slashing::*;
pub use operations_transfer::*;
pub use sanity_slots::*;
pub use shuffling::*;
pub use ssz_generic::*;
pub use ssz_static::*;

View File

@ -0,0 +1,40 @@
use super::*;
use crate::case_result::compare_beacon_state_results_without_caches;
use serde_derive::Deserialize;
use state_processing::per_block_processing::process_block_header;
use types::{BeaconBlock, BeaconState, EthSpec};
#[derive(Debug, Clone, Deserialize)]
pub struct OperationsBlockHeader<E: EthSpec> {
pub description: String,
#[serde(bound = "E: EthSpec")]
pub pre: BeaconState<E>,
pub block: BeaconBlock,
#[serde(bound = "E: EthSpec")]
pub post: Option<BeaconState<E>>,
}
impl<E: EthSpec> YamlDecode for OperationsBlockHeader<E> {
fn yaml_decode(yaml: &String) -> Result<Self, Error> {
Ok(serde_yaml::from_str(&yaml.as_str()).unwrap())
}
}
impl<E: EthSpec> Case for OperationsBlockHeader<E> {
fn description(&self) -> String {
self.description.clone()
}
fn result(&self, _case_index: usize) -> Result<(), Error> {
let mut state = self.pre.clone();
let mut expected = self.post.clone();
// Processing requires the epoch cache.
state.build_all_caches(&E::spec()).unwrap();
let mut result =
process_block_header(&mut state, &self.block, &E::spec(), true).map(|_| state);
compare_beacon_state_results_without_caches(&mut result, &mut expected)
}
}

View File

@ -0,0 +1,42 @@
use super::*;
use crate::case_result::compare_beacon_state_results_without_caches;
use serde_derive::Deserialize;
use state_processing::per_slot_processing;
use types::{BeaconState, EthSpec};
#[derive(Debug, Clone, Deserialize)]
pub struct SanitySlots<E: EthSpec> {
pub description: String,
#[serde(bound = "E: EthSpec")]
pub pre: BeaconState<E>,
pub slots: usize,
#[serde(bound = "E: EthSpec")]
pub post: Option<BeaconState<E>>,
}
impl<E: EthSpec> YamlDecode for SanitySlots<E> {
fn yaml_decode(yaml: &String) -> Result<Self, Error> {
Ok(serde_yaml::from_str(&yaml.as_str()).unwrap())
}
}
impl<E: EthSpec> Case for SanitySlots<E> {
fn description(&self) -> String {
self.description.clone()
}
fn result(&self, _case_index: usize) -> Result<(), Error> {
let mut state = self.pre.clone();
let mut expected = self.post.clone();
let spec = &E::spec();
// Processing requires the epoch cache.
state.build_all_caches(&E::spec()).unwrap();
let mut result = (0..self.slots)
.try_for_each(|_| per_slot_processing(&mut state, spec))
.map(|_| state);
compare_beacon_state_results_without_caches(&mut result, &mut expected)
}
}

View File

@ -41,6 +41,8 @@ impl Doc {
("ssz", "uint", _) => run_test::<SszGeneric>(self),
("ssz", "static", "minimal") => run_test::<SszStatic<MinimalEthSpec>>(self),
("ssz", "static", "mainnet") => run_test::<SszStatic<MainnetEthSpec>>(self),
("sanity", "slots", "minimal") => run_test::<SanitySlots<MinimalEthSpec>>(self),
("sanity", "slots", "mainnet") => run_test::<SanitySlots<MainnetEthSpec>>(self),
("shuffling", "core", "minimal") => run_test::<Shuffling<MinimalEthSpec>>(self),
("shuffling", "core", "mainnet") => run_test::<Shuffling<MainnetEthSpec>>(self),
("bls", "aggregate_pubkeys", "mainnet") => run_test::<BlsAggregatePubkeys>(self),
@ -89,6 +91,12 @@ impl Doc {
("operations", "attestation", "minimal") => {
run_test::<OperationsAttestation<MinimalEthSpec>>(self)
}
("operations", "block_header", "mainnet") => {
run_test::<OperationsBlockHeader<MainnetEthSpec>>(self)
}
("operations", "block_header", "minimal") => {
run_test::<OperationsBlockHeader<MinimalEthSpec>>(self)
}
("epoch_processing", "crosslinks", "minimal") => {
run_test::<EpochProcessingCrosslinks<MinimalEthSpec>>(self)
}

View File

@ -20,10 +20,12 @@ impl EthSpec for MinimalEthSpec {
type LatestSlashedExitLength = U64;
fn spec() -> ChainSpec {
// TODO: this spec is likely incorrect!
let mut spec = FewValidatorsEthSpec::spec();
spec.target_committee_size = 4;
spec.shuffle_round_count = 10;
spec.min_attestation_inclusion_delay = 2;
spec.slots_per_epoch = 8;
spec.slots_per_eth1_voting_period = 16;
spec
}
}

View File

@ -124,6 +124,33 @@ fn operations_attestation() {
});
}
#[test]
fn operations_block_header() {
yaml_files_in_test_dir(&Path::new("operations").join("block_header"))
.into_par_iter()
.for_each(|file| {
Doc::assert_tests_pass(file);
});
}
#[test]
fn sanity_blocks() {
yaml_files_in_test_dir(&Path::new("sanity").join("blocks"))
.into_par_iter()
.for_each(|file| {
Doc::assert_tests_pass(file);
});
}
#[test]
fn sanity_slots() {
yaml_files_in_test_dir(&Path::new("sanity").join("slots"))
.into_par_iter()
.for_each(|file| {
Doc::assert_tests_pass(file);
});
}
#[test]
#[cfg(not(feature = "fake_crypto"))]
fn bls() {