diff --git a/tests/ef_tests/src/cases.rs b/tests/ef_tests/src/cases.rs index 9061e385c..f3432bc1b 100644 --- a/tests/ef_tests/src/cases.rs +++ b/tests/ef_tests/src/cases.rs @@ -8,6 +8,7 @@ mod bls_g2_uncompressed; mod bls_priv_to_pub; mod bls_sign_msg; mod operations_deposit; +mod operations_exit; mod operations_transfer; mod ssz_generic; mod ssz_static; @@ -19,6 +20,7 @@ pub use bls_g2_uncompressed::*; pub use bls_priv_to_pub::*; pub use bls_sign_msg::*; pub use operations_deposit::*; +pub use operations_exit::*; pub use operations_transfer::*; pub use ssz_generic::*; pub use ssz_static::*; diff --git a/tests/ef_tests/src/cases/operations_exit.rs b/tests/ef_tests/src/cases/operations_exit.rs new file mode 100644 index 000000000..8df5343fa --- /dev/null +++ b/tests/ef_tests/src/cases/operations_exit.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_block_processing::process_exits; +use types::{BeaconState, EthSpec, VoluntaryExit}; + +#[derive(Debug, Clone, Deserialize)] +pub struct OperationsExit { + pub description: String, + #[serde(bound = "E: EthSpec")] + pub pre: BeaconState, + pub voluntary_exit: VoluntaryExit, + #[serde(bound = "E: EthSpec")] + pub post: Option>, +} + +impl YamlDecode for OperationsExit { + fn yaml_decode(yaml: &String) -> Result { + Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + } +} + +impl Case for OperationsExit { + fn result(&self, _case_index: usize) -> Result<(), Error> { + let mut state = self.pre.clone(); + let exit = self.voluntary_exit.clone(); + let mut expected = self.post.clone(); + + // Epoch processing requires the epoch cache. + state.build_all_caches(&E::spec()).unwrap(); + + let result = process_exits(&mut state, &[exit], &E::spec()); + + let mut result = result.and_then(|_| Ok(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 f2e26c1f4..543a120a0 100644 --- a/tests/ef_tests/src/doc.rs +++ b/tests/ef_tests/src/doc.rs @@ -63,6 +63,12 @@ impl Doc { ("operations", "transfer", "minimal") => { run_test::>(self) } + ("operations", "voluntary_exit", "mainnet") => { + run_test::>(self) + } + ("operations", "voluntary_exit", "minimal") => { + 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 52fd8b5c9..c1722d731 100644 --- a/tests/ef_tests/tests/tests.rs +++ b/tests/ef_tests/tests/tests.rs @@ -11,7 +11,10 @@ fn yaml_files_in_test_dir(dir: &Path) -> Vec { assert!( base_path.exists(), - "Unable to locate test files. Did you init git submoules?" + format!( + "Unable to locate {:?}. Did you init git submoules?", + base_path + ) ); let mut paths: Vec = WalkDir::new(base_path) @@ -70,7 +73,6 @@ fn operations_deposit() { // No transfers are permitted in phase 0. /* #[test] -#[should_panic] #[cfg(not(feature = "fake_crypto"))] fn operations_transfer() { yaml_files_in_test_dir(&Path::new("operations").join("transfer")) @@ -83,6 +85,16 @@ fn operations_transfer() { } */ +#[test] +#[cfg(not(feature = "fake_crypto"))] +fn operations_exit() { + yaml_files_in_test_dir(&Path::new("operations").join("voluntary_exit")) + .into_par_iter() + .for_each(|file| { + Doc::assert_tests_pass(file); + }); +} + #[test] #[cfg(not(feature = "fake_crypto"))] fn bls() {