diff --git a/tests/ef_tests/src/cases.rs b/tests/ef_tests/src/cases.rs index df1a9428ba..8bff0cdf85 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 epoch_processing_crosslinks; mod epoch_processing_registry_updates; +mod operations_attestation; mod operations_attester_slashing; mod operations_deposit; mod operations_exit; @@ -26,6 +27,7 @@ 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_attestation::*; pub use operations_attester_slashing::*; pub use operations_deposit::*; pub use operations_exit::*; diff --git a/tests/ef_tests/src/cases/operations_attestation.rs b/tests/ef_tests/src/cases/operations_attestation.rs new file mode 100644 index 0000000000..3289545146 --- /dev/null +++ b/tests/ef_tests/src/cases/operations_attestation.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_attestations; +use types::{Attestation, BeaconState, EthSpec}; + +#[derive(Debug, Clone, Deserialize)] +pub struct OperationsAttestation { + pub description: String, + #[serde(bound = "E: EthSpec")] + pub pre: BeaconState, + pub attestation: Attestation, + #[serde(bound = "E: EthSpec")] + pub post: Option>, +} + +impl YamlDecode for OperationsAttestation { + fn yaml_decode(yaml: &String) -> Result { + Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + } +} + +impl Case for OperationsAttestation { + fn description(&self) -> String { + self.description.clone() + } + + fn result(&self, _case_index: usize) -> Result<(), Error> { + let mut state = self.pre.clone(); + let attestation = self.attestation.clone(); + let mut expected = self.post.clone(); + + // Processing requires the epoch cache. + state.build_all_caches(&E::spec()).unwrap(); + + let result = process_attestations(&mut state, &[attestation], &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 f69d1f998e..38f5e3cb35 100644 --- a/tests/ef_tests/src/doc.rs +++ b/tests/ef_tests/src/doc.rs @@ -83,6 +83,12 @@ impl Doc { ("operations", "attester_slashing", "minimal") => { run_test::>(self) } + ("operations", "attestation", "mainnet") => { + run_test::>(self) + } + ("operations", "attestation", "minimal") => { + run_test::>(self) + } ("epoch_processing", "crosslinks", "minimal") => { run_test::>(self) } diff --git a/tests/ef_tests/src/eth_specs.rs b/tests/ef_tests/src/eth_specs.rs index cdf8b94e8c..1e3f57d419 100644 --- a/tests/ef_tests/src/eth_specs.rs +++ b/tests/ef_tests/src/eth_specs.rs @@ -23,6 +23,7 @@ impl EthSpec for MinimalEthSpec { // TODO: this spec is likely incorrect! let mut spec = FewValidatorsEthSpec::spec(); spec.shuffle_round_count = 10; + spec.min_attestation_inclusion_delay = 2; spec } } diff --git a/tests/ef_tests/tests/tests.rs b/tests/ef_tests/tests/tests.rs index ddf13388f0..4a1618541d 100644 --- a/tests/ef_tests/tests/tests.rs +++ b/tests/ef_tests/tests/tests.rs @@ -115,6 +115,15 @@ fn operations_attester_slashing() { }); } +#[test] +fn operations_attestation() { + yaml_files_in_test_dir(&Path::new("operations").join("attestation")) + .into_par_iter() + .for_each(|file| { + Doc::assert_tests_pass(file); + }); +} + #[test] #[cfg(not(feature = "fake_crypto"))] fn bls() {