mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-16 12:28:24 +00:00
ef_tests: sanity slot tests + block headers
This commit is contained in:
40
tests/ef_tests/src/cases/operations_block_header.rs
Normal file
40
tests/ef_tests/src/cases/operations_block_header.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
use super::*;
|
||||
use crate::case_result::compare_beacon_state_results_without_caches;
|
||||
use serde_derive::Deserialize;
|
||||
use state_processing::per_block_processing::process_block_header;
|
||||
use types::{BeaconBlock, BeaconState, EthSpec};
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct OperationsBlockHeader<E: EthSpec> {
|
||||
pub description: String,
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
pub pre: BeaconState<E>,
|
||||
pub block: BeaconBlock,
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
pub post: Option<BeaconState<E>>,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> YamlDecode for OperationsBlockHeader<E> {
|
||||
fn yaml_decode(yaml: &String) -> Result<Self, Error> {
|
||||
Ok(serde_yaml::from_str(&yaml.as_str()).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> Case for OperationsBlockHeader<E> {
|
||||
fn description(&self) -> String {
|
||||
self.description.clone()
|
||||
}
|
||||
|
||||
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
||||
let mut state = self.pre.clone();
|
||||
let mut expected = self.post.clone();
|
||||
|
||||
// Processing requires the epoch cache.
|
||||
state.build_all_caches(&E::spec()).unwrap();
|
||||
|
||||
let mut result =
|
||||
process_block_header(&mut state, &self.block, &E::spec(), true).map(|_| state);
|
||||
|
||||
compare_beacon_state_results_without_caches(&mut result, &mut expected)
|
||||
}
|
||||
}
|
||||
42
tests/ef_tests/src/cases/sanity_slots.rs
Normal file
42
tests/ef_tests/src/cases/sanity_slots.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use super::*;
|
||||
use crate::case_result::compare_beacon_state_results_without_caches;
|
||||
use serde_derive::Deserialize;
|
||||
use state_processing::per_slot_processing;
|
||||
use types::{BeaconState, EthSpec};
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct SanitySlots<E: EthSpec> {
|
||||
pub description: String,
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
pub pre: BeaconState<E>,
|
||||
pub slots: usize,
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
pub post: Option<BeaconState<E>>,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> YamlDecode for SanitySlots<E> {
|
||||
fn yaml_decode(yaml: &String) -> Result<Self, Error> {
|
||||
Ok(serde_yaml::from_str(&yaml.as_str()).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> Case for SanitySlots<E> {
|
||||
fn description(&self) -> String {
|
||||
self.description.clone()
|
||||
}
|
||||
|
||||
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
||||
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 = (0..self.slots)
|
||||
.try_for_each(|_| per_slot_processing(&mut state, spec))
|
||||
.map(|_| state);
|
||||
|
||||
compare_beacon_state_results_without_caches(&mut result, &mut expected)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user