Fulu EF tests v1.6.0-alpha.0 (#7540)

Update to EF tests v1.6.0-alpha.0
This commit is contained in:
ethDreamer
2025-06-04 01:34:12 -05:00
committed by GitHub
parent 357a8ccbb9
commit 2d9fc34d43
21 changed files with 494 additions and 167 deletions

View File

@@ -1,10 +1,12 @@
use super::*;
use crate::case_result::compare_result;
use crate::decode::{snappy_decode_file, yaml_decode_file};
use crate::cases::common::DataColumnsByRootIdentifierWrapper;
use crate::decode::{context_yaml_decode_file, snappy_decode_file, yaml_decode_file};
use context_deserialize::ContextDeserialize;
use serde::Deserialize;
use ssz::Decode;
use tree_hash::TreeHash;
use types::{BeaconBlock, BeaconState, Hash256, SignedBeaconBlock};
use types::{BeaconBlock, BeaconState, DataColumnsByRootIdentifier, Hash256, SignedBeaconBlock};
#[derive(Debug, Clone, Deserialize)]
struct SszStaticRoots {
@@ -37,18 +39,28 @@ pub struct SszStaticWithSpec<T> {
value: T,
}
fn load_from_dir<T: SszStaticType>(path: &Path) -> Result<(SszStaticRoots, Vec<u8>, T), Error> {
fn load_from_dir<T: SszStaticType + for<'de> ContextDeserialize<'de, ForkName>>(
path: &Path,
fork_name: ForkName,
) -> Result<(SszStaticRoots, Vec<u8>, T), Error> {
load_from_dir_with_context(path, fork_name)
}
fn load_from_dir_with_context<T: SszStaticType + for<'de> ContextDeserialize<'de, C>, C>(
path: &Path,
context: C,
) -> Result<(SszStaticRoots, Vec<u8>, T), Error> {
let roots = yaml_decode_file(&path.join("roots.yaml"))?;
let serialized = snappy_decode_file(&path.join("serialized.ssz_snappy"))
.expect("serialized.ssz_snappy exists");
let value = yaml_decode_file(&path.join("value.yaml"))?;
let value = context_yaml_decode_file(&path.join("value.yaml"), context)?;
Ok((roots, serialized, value))
}
impl<T: SszStaticType> LoadCase for SszStatic<T> {
fn load_from_dir(path: &Path, _fork_name: ForkName) -> Result<Self, Error> {
load_from_dir(path).map(|(roots, serialized, value)| Self {
impl<T: SszStaticType + for<'de> ContextDeserialize<'de, ForkName>> LoadCase for SszStatic<T> {
fn load_from_dir(path: &Path, fork_name: ForkName) -> Result<Self, Error> {
load_from_dir(path, fork_name).map(|(roots, serialized, value)| Self {
roots,
serialized,
value,
@@ -56,19 +68,9 @@ impl<T: SszStaticType> LoadCase for SszStatic<T> {
}
}
impl<T: SszStaticType> LoadCase for SszStaticTHC<T> {
fn load_from_dir(path: &Path, _fork_name: ForkName) -> Result<Self, Error> {
load_from_dir(path).map(|(roots, serialized, value)| Self {
roots,
serialized,
value,
})
}
}
impl<T: SszStaticType> LoadCase for SszStaticWithSpec<T> {
fn load_from_dir(path: &Path, _fork_name: ForkName) -> Result<Self, Error> {
load_from_dir(path).map(|(roots, serialized, value)| Self {
impl<T: SszStaticType + for<'de> ContextDeserialize<'de, ForkName>> LoadCase for SszStaticTHC<T> {
fn load_from_dir(path: &Path, fork_name: ForkName) -> Result<Self, Error> {
load_from_dir(path, fork_name).map(|(roots, serialized, value)| Self {
roots,
serialized,
value,
@@ -124,6 +126,16 @@ impl<E: EthSpec> Case for SszStaticTHC<BeaconState<E>> {
}
}
impl<E: EthSpec> LoadCase for SszStaticWithSpec<BeaconBlock<E>> {
fn load_from_dir(path: &Path, fork_name: ForkName) -> Result<Self, Error> {
load_from_dir(path, fork_name).map(|(roots, serialized, value)| Self {
roots,
serialized,
value,
})
}
}
impl<E: EthSpec> Case for SszStaticWithSpec<BeaconBlock<E>> {
fn result(&self, _case_index: usize, fork_name: ForkName) -> Result<(), Error> {
let spec = &testing_spec::<E>(fork_name);
@@ -135,6 +147,16 @@ impl<E: EthSpec> Case for SszStaticWithSpec<BeaconBlock<E>> {
}
}
impl<E: EthSpec> LoadCase for SszStaticWithSpec<SignedBeaconBlock<E>> {
fn load_from_dir(path: &Path, fork_name: ForkName) -> Result<Self, Error> {
load_from_dir(path, fork_name).map(|(roots, serialized, value)| Self {
roots,
serialized,
value,
})
}
}
impl<E: EthSpec> Case for SszStaticWithSpec<SignedBeaconBlock<E>> {
fn result(&self, _case_index: usize, fork_name: ForkName) -> Result<(), Error> {
let spec = &testing_spec::<E>(fork_name);
@@ -145,3 +167,27 @@ impl<E: EthSpec> Case for SszStaticWithSpec<SignedBeaconBlock<E>> {
Ok(())
}
}
impl<E: EthSpec> LoadCase for SszStaticWithSpec<DataColumnsByRootIdentifierWrapper<E>> {
fn load_from_dir(path: &Path, fork_name: ForkName) -> Result<Self, Error> {
let spec = &testing_spec::<E>(fork_name);
let context = (fork_name, spec.number_of_columns as usize);
load_from_dir_with_context(path, context).map(|(roots, serialized, value)| Self {
roots,
serialized,
value,
})
}
}
impl<E: EthSpec> Case for SszStaticWithSpec<DataColumnsByRootIdentifierWrapper<E>> {
fn result(&self, _case_index: usize, fork_name: ForkName) -> Result<(), Error> {
let spec = &testing_spec::<E>(fork_name);
check_serialization(&self.value, &self.serialized, |bytes| {
DataColumnsByRootIdentifier::from_ssz_bytes(bytes, spec.number_of_columns as usize)
.map(Into::into)
})?;
check_tree_hash(&self.roots.root, self.value.tree_hash_root().as_slice())?;
Ok(())
}
}