ef_tests: sanity block tests
This commit is contained in:
parent
6bf6ba337d
commit
4024a400c8
@ -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::*;
|
||||
|
53
tests/ef_tests/src/cases/sanity_blocks.rs
Normal file
53
tests/ef_tests/src/cases/sanity_blocks.rs
Normal file
@ -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<E: EthSpec> {
|
||||
pub description: String,
|
||||
pub bls_setting: Option<BlsSetting>,
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
pub pre: BeaconState<E>,
|
||||
pub blocks: Vec<BeaconBlock>,
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
pub post: Option<BeaconState<E>>,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> YamlDecode for SanityBlocks<E> {
|
||||
fn yaml_decode(yaml: &String) -> Result<Self, Error> {
|
||||
Ok(serde_yaml::from_str(&yaml.as_str()).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> Case for SanityBlocks<E> {
|
||||
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)
|
||||
}
|
||||
}
|
@ -43,6 +43,8 @@ impl Doc {
|
||||
("ssz", "static", "mainnet") => run_test::<SszStatic<MainnetEthSpec>>(self),
|
||||
("sanity", "slots", "minimal") => run_test::<SanitySlots<MinimalEthSpec>>(self),
|
||||
("sanity", "slots", "mainnet") => run_test::<SanitySlots<MainnetEthSpec>>(self),
|
||||
("sanity", "blocks", "minimal") => run_test::<SanityBlocks<MinimalEthSpec>>(self),
|
||||
("sanity", "blocks", "mainnet") => run_test::<SanityBlocks<MainnetEthSpec>>(self),
|
||||
("shuffling", "core", "minimal") => run_test::<Shuffling<MinimalEthSpec>>(self),
|
||||
("shuffling", "core", "mainnet") => run_test::<Shuffling<MainnetEthSpec>>(self),
|
||||
("bls", "aggregate_pubkeys", "mainnet") => run_test::<BlsAggregatePubkeys>(self),
|
||||
|
Loading…
Reference in New Issue
Block a user