diff --git a/tests/ef_tests/eth2.0-spec-tests b/tests/ef_tests/eth2.0-spec-tests index 6fde1e806..746712e8a 160000 --- a/tests/ef_tests/eth2.0-spec-tests +++ b/tests/ef_tests/eth2.0-spec-tests @@ -1 +1 @@ -Subproject commit 6fde1e806b340d946839d6261c63c779f0cadd81 +Subproject commit 746712e8a5c5b97d1bbc7724e5ccd09920c50a30 diff --git a/tests/ef_tests/src/cases.rs b/tests/ef_tests/src/cases.rs index 44be18756..4fa082ec9 100644 --- a/tests/ef_tests/src/cases.rs +++ b/tests/ef_tests/src/cases.rs @@ -9,6 +9,7 @@ mod bls_priv_to_pub; mod bls_sign_msg; mod operations_deposit; mod operations_exit; +mod operations_proposer_slashing; mod operations_transfer; mod shuffling; mod ssz_generic; @@ -22,6 +23,7 @@ pub use bls_priv_to_pub::*; pub use bls_sign_msg::*; pub use operations_deposit::*; pub use operations_exit::*; +pub use operations_proposer_slashing::*; pub use operations_transfer::*; pub use shuffling::*; pub use ssz_generic::*; diff --git a/tests/ef_tests/src/cases/operations_proposer_slashing.rs b/tests/ef_tests/src/cases/operations_proposer_slashing.rs new file mode 100644 index 000000000..416a6f7c3 --- /dev/null +++ b/tests/ef_tests/src/cases/operations_proposer_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_proposer_slashings; +use types::{BeaconState, EthSpec, ProposerSlashing}; + +#[derive(Debug, Clone, Deserialize)] +pub struct OperationsProposerSlashing { + pub description: String, + #[serde(bound = "E: EthSpec")] + pub pre: BeaconState, + pub proposer_slashing: ProposerSlashing, + #[serde(bound = "E: EthSpec")] + pub post: Option>, +} + +impl YamlDecode for OperationsProposerSlashing { + fn yaml_decode(yaml: &String) -> Result { + Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + } +} + +impl Case for OperationsProposerSlashing { + fn description(&self) -> String { + self.description.clone() + } + + fn result(&self, _case_index: usize) -> Result<(), Error> { + let mut state = self.pre.clone(); + let proposer_slashing = self.proposer_slashing.clone(); + let mut expected = self.post.clone(); + + // Processing requires the epoch cache. + state.build_all_caches(&E::spec()).unwrap(); + + let result = process_proposer_slashings(&mut state, &[proposer_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 b0854451a..3947d81bf 100644 --- a/tests/ef_tests/src/doc.rs +++ b/tests/ef_tests/src/doc.rs @@ -71,6 +71,12 @@ impl Doc { ("operations", "voluntary_exit", "minimal") => { run_test::>(self) } + ("operations", "proposer_slashing", "mainnet") => { + run_test::>(self) + } + ("operations", "proposer_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 86f188671..1cb12321b 100644 --- a/tests/ef_tests/tests/tests.rs +++ b/tests/ef_tests/tests/tests.rs @@ -100,6 +100,16 @@ fn operations_exit() { }); } +#[test] +#[cfg(not(feature = "fake_crypto"))] +fn operations_proposer_slashing() { + yaml_files_in_test_dir(&Path::new("operations").join("proposer_slashing")) + .into_par_iter() + .for_each(|file| { + Doc::assert_tests_pass(file); + }); +} + #[test] #[cfg(not(feature = "fake_crypto"))] fn bls() {