diff --git a/tests/ef_tests/src/cases.rs b/tests/ef_tests/src/cases.rs index 4fa082ec9..9b15248f5 100644 --- a/tests/ef_tests/src/cases.rs +++ b/tests/ef_tests/src/cases.rs @@ -7,6 +7,7 @@ mod bls_g2_compressed; mod bls_g2_uncompressed; mod bls_priv_to_pub; mod bls_sign_msg; +mod operations_attester_slashing; mod operations_deposit; mod operations_exit; mod operations_proposer_slashing; @@ -21,6 +22,7 @@ pub use bls_g2_compressed::*; pub use bls_g2_uncompressed::*; pub use bls_priv_to_pub::*; pub use bls_sign_msg::*; +pub use operations_attester_slashing::*; pub use operations_deposit::*; pub use operations_exit::*; pub use operations_proposer_slashing::*; diff --git a/tests/ef_tests/src/cases/operations_attester_slashing.rs b/tests/ef_tests/src/cases/operations_attester_slashing.rs new file mode 100644 index 000000000..d8f1f06dc --- /dev/null +++ b/tests/ef_tests/src/cases/operations_attester_slashing.rs @@ -0,0 +1,42 @@ +use super::*; +use crate::case_result::compare_beacon_state_results_without_caches; +use serde_derive::Deserialize; +use state_processing::per_block_processing::process_attester_slashings; +use types::{AttesterSlashing, BeaconState, EthSpec}; + +#[derive(Debug, Clone, Deserialize)] +pub struct OperationsAttesterSlashing { + pub description: String, + #[serde(bound = "E: EthSpec")] + pub pre: BeaconState, + pub attester_slashing: AttesterSlashing, + #[serde(bound = "E: EthSpec")] + pub post: Option>, +} + +impl YamlDecode for OperationsAttesterSlashing { + fn yaml_decode(yaml: &String) -> Result { + Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + } +} + +impl Case for OperationsAttesterSlashing { + fn description(&self) -> String { + self.description.clone() + } + + fn result(&self, _case_index: usize) -> Result<(), Error> { + let mut state = self.pre.clone(); + let attester_slashing = self.attester_slashing.clone(); + let mut expected = self.post.clone(); + + // Processing requires the epoch cache. + state.build_all_caches(&E::spec()).unwrap(); + + let result = process_attester_slashings(&mut state, &[attester_slashing], &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 3947d81bf..5a9df0c21 100644 --- a/tests/ef_tests/src/doc.rs +++ b/tests/ef_tests/src/doc.rs @@ -77,6 +77,12 @@ impl Doc { ("operations", "proposer_slashing", "minimal") => { run_test::>(self) } + ("operations", "attester_slashing", "mainnet") => { + run_test::>(self) + } + ("operations", "attester_slashing", "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 1cb12321b..15b98e804 100644 --- a/tests/ef_tests/tests/tests.rs +++ b/tests/ef_tests/tests/tests.rs @@ -110,6 +110,16 @@ fn operations_proposer_slashing() { }); } +#[test] +#[cfg(not(feature = "fake_crypto"))] +fn operations_attester_slashing() { + yaml_files_in_test_dir(&Path::new("operations").join("attester_slashing")) + .into_par_iter() + .for_each(|file| { + Doc::assert_tests_pass(file); + }); +} + #[test] #[cfg(not(feature = "fake_crypto"))] fn bls() {