From 706f850c9e754e4c8dc29e35aaf67e281960a230 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Tue, 28 May 2019 16:03:26 +1000 Subject: [PATCH] ef_tests: runners for epoch processing tests --- tests/ef_tests/src/cases.rs | 4 ++ .../src/cases/epoch_processing_crosslinks.rs | 38 ++++++++++++++ .../epoch_processing_registry_updates.rs | 49 +++++++++++++++++++ tests/ef_tests/src/doc.rs | 9 ++++ tests/ef_tests/tests/tests.rs | 18 +++++++ 5 files changed, 118 insertions(+) create mode 100644 tests/ef_tests/src/cases/epoch_processing_crosslinks.rs create mode 100644 tests/ef_tests/src/cases/epoch_processing_registry_updates.rs diff --git a/tests/ef_tests/src/cases.rs b/tests/ef_tests/src/cases.rs index 9b15248f5..df1a9428b 100644 --- a/tests/ef_tests/src/cases.rs +++ b/tests/ef_tests/src/cases.rs @@ -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::*; diff --git a/tests/ef_tests/src/cases/epoch_processing_crosslinks.rs b/tests/ef_tests/src/cases/epoch_processing_crosslinks.rs new file mode 100644 index 000000000..fa530f9ad --- /dev/null +++ b/tests/ef_tests/src/cases/epoch_processing_crosslinks.rs @@ -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 { + pub description: String, + #[serde(bound = "E: EthSpec")] + pub pre: BeaconState, + #[serde(bound = "E: EthSpec")] + pub post: Option>, +} + +impl YamlDecode for EpochProcessingCrosslinks { + fn yaml_decode(yaml: &String) -> Result { + Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + } +} + +impl Case for EpochProcessingCrosslinks { + 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) + } +} diff --git a/tests/ef_tests/src/cases/epoch_processing_registry_updates.rs b/tests/ef_tests/src/cases/epoch_processing_registry_updates.rs new file mode 100644 index 000000000..17c2e8da7 --- /dev/null +++ b/tests/ef_tests/src/cases/epoch_processing_registry_updates.rs @@ -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 { + pub description: String, + #[serde(bound = "E: EthSpec")] + pub pre: BeaconState, + pub trigger_block: BeaconBlock, + #[serde(bound = "E: EthSpec")] + pub post: Option>, +} + +impl YamlDecode for EpochProcessingRegistryUpdates { + fn yaml_decode(yaml: &String) -> Result { + Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + } +} + +impl Case for EpochProcessingRegistryUpdates { + 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) + } +} diff --git a/tests/ef_tests/src/doc.rs b/tests/ef_tests/src/doc.rs index 5a9df0c21..67888fc84 100644 --- a/tests/ef_tests/src/doc.rs +++ b/tests/ef_tests/src/doc.rs @@ -83,6 +83,15 @@ impl Doc { ("operations", "attester_slashing", "minimal") => { run_test::>(self) } + ("epoch_processing", "crosslinks", "minimal") => { + run_test::>(self) + } + ("epoch_processing", "registry_updates", "minimal") => { + run_test::>(self) + } + ("epoch_processing", "registry_updates", "mainnet") => { + run_test::>(self) + } (runner, handler, config) => panic!( "No implementation for runner: \"{}\", handler: \"{}\", config: \"{}\"", runner, handler, config diff --git a/tests/ef_tests/tests/tests.rs b/tests/ef_tests/tests/tests.rs index 15b98e804..4735a8b18 100644 --- a/tests/ef_tests/tests/tests.rs +++ b/tests/ef_tests/tests/tests.rs @@ -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); + }); +}