diff --git a/tests/ef_tests/src/cases.rs b/tests/ef_tests/src/cases.rs index 8e57e6f87..46a1578d1 100644 --- a/tests/ef_tests/src/cases.rs +++ b/tests/ef_tests/src/cases.rs @@ -16,6 +16,7 @@ mod operations_deposit; mod operations_exit; mod operations_proposer_slashing; mod operations_transfer; +mod sanity_blocks; mod sanity_slots; mod shuffling; mod ssz_generic; @@ -36,6 +37,7 @@ pub use operations_deposit::*; pub use operations_exit::*; pub use operations_proposer_slashing::*; pub use operations_transfer::*; +pub use sanity_blocks::*; pub use sanity_slots::*; pub use shuffling::*; pub use ssz_generic::*; diff --git a/tests/ef_tests/src/cases/sanity_blocks.rs b/tests/ef_tests/src/cases/sanity_blocks.rs new file mode 100644 index 000000000..a6581cf41 --- /dev/null +++ b/tests/ef_tests/src/cases/sanity_blocks.rs @@ -0,0 +1,53 @@ +use super::*; +use crate::bls_setting::BlsSetting; +use crate::case_result::compare_beacon_state_results_without_caches; +use serde_derive::Deserialize; +use state_processing::{per_block_processing, per_slot_processing}; +use types::{BeaconBlock, BeaconState, EthSpec}; + +#[derive(Debug, Clone, Deserialize)] +pub struct SanityBlocks { + pub description: String, + pub bls_setting: Option, + #[serde(bound = "E: EthSpec")] + pub pre: BeaconState, + pub blocks: Vec, + #[serde(bound = "E: EthSpec")] + pub post: Option>, +} + +impl YamlDecode for SanityBlocks { + fn yaml_decode(yaml: &String) -> Result { + Ok(serde_yaml::from_str(&yaml.as_str()).unwrap()) + } +} + +impl Case for SanityBlocks { + fn description(&self) -> String { + self.description.clone() + } + + fn result(&self, case_index: usize) -> Result<(), Error> { + self.bls_setting.unwrap_or_default().check()?; + + 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(&E::spec()).unwrap(); + + let mut result = self + .blocks + .iter() + .try_for_each(|block| { + while state.slot < block.slot { + per_slot_processing(&mut state, spec).unwrap(); + } + per_block_processing(&mut state, block, 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 522b094d5..48d46e2b7 100644 --- a/tests/ef_tests/src/doc.rs +++ b/tests/ef_tests/src/doc.rs @@ -43,6 +43,8 @@ impl Doc { ("ssz", "static", "mainnet") => run_test::>(self), ("sanity", "slots", "minimal") => run_test::>(self), ("sanity", "slots", "mainnet") => run_test::>(self), + ("sanity", "blocks", "minimal") => run_test::>(self), + ("sanity", "blocks", "mainnet") => run_test::>(self), ("shuffling", "core", "minimal") => run_test::>(self), ("shuffling", "core", "mainnet") => run_test::>(self), ("bls", "aggregate_pubkeys", "mainnet") => run_test::(self),