Test runners for basic progressive containers and bitlists

This commit is contained in:
Michael Sproul
2025-12-10 16:48:12 +11:00
parent d7ebdeb450
commit 9e15231ba2
7 changed files with 65 additions and 19 deletions

View File

@@ -19,6 +19,7 @@ compare_fields = { workspace = true }
context_deserialize = { workspace = true }
educe = { workspace = true }
eth2_network_config = { workspace = true }
ethereum_hashing = { workspace = true } # FIXME(sproul): remove
ethereum_ssz = { workspace = true }
ethereum_ssz_derive = { workspace = true }
execution_layer = { workspace = true }

View File

@@ -8,9 +8,13 @@ use context_deserialize::{ContextDeserialize, context_deserialize};
use serde::{Deserialize, Deserializer, de::Error as SerdeError};
use ssz_derive::{Decode, Encode};
use tree_hash::TreeHash;
use tree_hash::{PackedEncoding, ProgressiveMerkleHasher, TreeHashType};
use tree_hash_derive::TreeHash;
use types::typenum::*;
use types::{BitList, BitVector, FixedVector, ForkName, ProgressiveList, VariableList, Vector};
use types::{
BitList, BitVector, FixedVector, ForkName, Hash256, ProgressiveBitList, ProgressiveList,
VariableList, Vector,
};
#[derive(Debug, Clone, Deserialize)]
#[context_deserialize(ForkName)]
@@ -111,8 +115,7 @@ macro_rules! type_dispatch {
"VarTestStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* VarTestStruct>, $($rest)*),
"ComplexTestStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* ComplexTestStruct>, $($rest)*),
"BitsStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* BitsStruct>, $($rest)*),
// EIP-7916 is still in draft and hasn't been implemented yet https://eips.ethereum.org/EIPS/eip-7916
"ProgressiveTestStruct" | "ProgressiveBitsStruct" => Err(Error::SkippedKnownFailure),
"ProgressiveSingleFieldContainerTestStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* ProgressiveSingleFieldContainerTestStruct>, $($rest)*),
_ => Err(Error::FailedToParseTest(format!("unsupported: {}", $value))),
}
};
@@ -195,6 +198,14 @@ impl Case for SszGeneric {
[length => typenum]
)?;
}
"progressive_bitlist" => {
type_dispatch!(
ssz_generic_test,
(&self.path, fork_name),
ProgressiveBitList,
<>,
)?;
}
"boolean" => {
ssz_generic_test::<bool>(&self.path, fork_name)?;
}
@@ -220,6 +231,22 @@ impl Case for SszGeneric {
[type_name => test_container]
)?;
}
"progressive_containers" => {
let type_name = parts[0];
// FIXME(sproul): delete
if type_name != "ProgressiveSingleFieldContainerTestStruct" {
return Ok(());
}
type_dispatch!(
ssz_generic_test,
(&self.path, fork_name),
_,
<>,
[type_name => test_container]
)?;
}
_ => panic!("unsupported handler: {}", self.handler_name),
}
Ok(())
@@ -321,6 +348,20 @@ struct BitsStruct {
E: BitVector<U8>,
}
#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)]
#[tree_hash(struct_behaviour = "progressive_container", active_fields(1))]
#[context_deserialize(ForkName)]
struct ProgressiveSingleFieldContainerTestStruct {
A: u8,
}
#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)]
#[tree_hash(struct_behaviour = "progressive_container", active_fields(1))]
#[context_deserialize(ForkName)]
struct ProgressiveSingleListContainerTestStruct {
C: ProgressiveBitList,
}
fn byte_list_from_hex_str<'de, D, N: Unsigned>(
deserializer: D,
) -> Result<VariableList<u8, N>, D::Error>

View File

@@ -1141,9 +1141,13 @@ pub struct Bitlist;
type_name!(Bitlist, "bitlist");
pub struct Bitvector;
type_name!(Bitvector, "bitvector");
pub struct ProgressiveBitlist;
type_name!(ProgressiveBitlist, "progressive_bitlist");
pub struct Boolean;
type_name!(Boolean, "boolean");
pub struct Uints;
type_name!(Uints, "uints");
pub struct Containers;
type_name!(Containers, "containers");
pub struct ProgressiveContainers;
type_name!(ProgressiveContainers, "progressive_containers");

View File

@@ -736,6 +736,8 @@ fn ssz_generic() {
#[test]
fn ssz_generic_progressive() {
SszGenericHandler::<BasicProgressiveList>::default().run();
SszGenericHandler::<ProgressiveBitlist>::default().run();
SszGenericHandler::<ProgressiveContainers>::default().run();
}
#[test]