ef_tests: runners for epoch processing tests

This commit is contained in:
Michael Sproul 2019-05-28 16:03:26 +10:00
parent 01039546cb
commit 706f850c9e
No known key found for this signature in database
GPG Key ID: 77B1309D2E54E914
5 changed files with 118 additions and 0 deletions

View File

@ -7,6 +7,8 @@ mod bls_g2_compressed;
mod bls_g2_uncompressed;
mod bls_priv_to_pub;
mod bls_sign_msg;
mod epoch_processing_crosslinks;
mod epoch_processing_registry_updates;
mod operations_attester_slashing;
mod operations_deposit;
mod operations_exit;
@ -22,6 +24,8 @@ pub use bls_g2_compressed::*;
pub use bls_g2_uncompressed::*;
pub use bls_priv_to_pub::*;
pub use bls_sign_msg::*;
pub use epoch_processing_crosslinks::*;
pub use epoch_processing_registry_updates::*;
pub use operations_attester_slashing::*;
pub use operations_deposit::*;
pub use operations_exit::*;

View File

@ -0,0 +1,38 @@
use super::*;
use crate::case_result::compare_beacon_state_results_without_caches;
use serde_derive::Deserialize;
use state_processing::per_epoch_processing::process_crosslinks;
use types::{BeaconState, EthSpec};
#[derive(Debug, Clone, Deserialize)]
pub struct EpochProcessingCrosslinks<E: EthSpec> {
pub description: String,
#[serde(bound = "E: EthSpec")]
pub pre: BeaconState<E>,
#[serde(bound = "E: EthSpec")]
pub post: Option<BeaconState<E>>,
}
impl<E: EthSpec> YamlDecode for EpochProcessingCrosslinks<E> {
fn yaml_decode(yaml: &String) -> Result<Self, Error> {
Ok(serde_yaml::from_str(&yaml.as_str()).unwrap())
}
}
impl<E: EthSpec> Case for EpochProcessingCrosslinks<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_crosslinks(&mut state, &E::spec()).map(|_| state);
compare_beacon_state_results_without_caches(&mut result, &mut expected)
}
}

View File

@ -0,0 +1,49 @@
use super::*;
use crate::case_result::compare_beacon_state_results_without_caches;
use serde_derive::Deserialize;
use state_processing::per_block_processing::per_block_processing;
use state_processing::per_epoch_processing::registry_updates::process_registry_updates;
use state_processing::per_slot_processing;
use types::{BeaconBlock, BeaconState, EthSpec};
#[derive(Debug, Clone, Deserialize)]
pub struct EpochProcessingRegistryUpdates<E: EthSpec> {
pub description: String,
#[serde(bound = "E: EthSpec")]
pub pre: BeaconState<E>,
pub trigger_block: BeaconBlock,
#[serde(bound = "E: EthSpec")]
pub post: Option<BeaconState<E>>,
}
impl<E: EthSpec> YamlDecode for EpochProcessingRegistryUpdates<E> {
fn yaml_decode(yaml: &String) -> Result<Self, Error> {
Ok(serde_yaml::from_str(&yaml.as_str()).unwrap())
}
}
impl<E: EthSpec> Case for EpochProcessingRegistryUpdates<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(spec).unwrap();
// Apply the trigger block.
// FIXME: trigger block gets applied to state after per-epoch processing (test bug)
while state.slot < self.trigger_block.slot {
per_slot_processing(&mut state, spec).expect("slot processing failed");
}
per_block_processing(&mut state, &self.trigger_block, spec).expect("process block");
let mut result = process_registry_updates(&mut state, spec).map(|_| state);
compare_beacon_state_results_without_caches(&mut result, &mut expected)
}
}

View File

@ -83,6 +83,15 @@ impl Doc {
("operations", "attester_slashing", "minimal") => {
run_test::<OperationsAttesterSlashing<MinimalEthSpec>>(self)
}
("epoch_processing", "crosslinks", "minimal") => {
run_test::<EpochProcessingCrosslinks<MinimalEthSpec>>(self)
}
("epoch_processing", "registry_updates", "minimal") => {
run_test::<EpochProcessingRegistryUpdates<MinimalEthSpec>>(self)
}
("epoch_processing", "registry_updates", "mainnet") => {
run_test::<EpochProcessingRegistryUpdates<MainnetEthSpec>>(self)
}
(runner, handler, config) => panic!(
"No implementation for runner: \"{}\", handler: \"{}\", config: \"{}\"",
runner, handler, config

View File

@ -129,3 +129,21 @@ fn bls() {
Doc::assert_tests_pass(file);
});
}
#[test]
fn epoch_processing_crosslinks() {
yaml_files_in_test_dir(&Path::new("epoch_processing").join("crosslinks"))
.into_par_iter()
.for_each(|file| {
Doc::assert_tests_pass(file);
});
}
#[test]
fn epoch_processing_registry_updates() {
yaml_files_in_test_dir(&Path::new("epoch_processing").join("registry_updates"))
.into_par_iter()
.for_each(|file| {
Doc::assert_tests_pass(file);
});
}