Compatible union tests

This commit is contained in:
Michael Sproul
2026-01-12 16:11:46 +11:00
parent 30289cd750
commit 6b5d87869b
2 changed files with 57 additions and 12 deletions

24
Cargo.lock generated
View File

@@ -1953,7 +1953,7 @@ version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fde0e0ec90c9dfb3b4b1a0891a7dcd0e2bffde2f7efed5fe7c9bb00e5bfb915e"
dependencies = [
"windows-sys 0.59.0",
"windows-sys 0.48.0",
]
[[package]]
@@ -3119,7 +3119,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
"windows-sys 0.61.2",
"windows-sys 0.59.0",
]
[[package]]
@@ -3284,7 +3284,7 @@ dependencies = [
[[package]]
name = "ethereum_ssz"
version = "0.10.0"
source = "git+https://github.com/sigp/ethereum_ssz?branch=progressive#952eb175cf463ec92d3abaf232e42fb72af7314e"
source = "git+https://github.com/sigp/ethereum_ssz?branch=progressive#ed6332b0572f18bf285d2acdfc6932e1b9d274ef"
dependencies = [
"alloy-primitives",
"arbitrary",
@@ -3300,7 +3300,7 @@ dependencies = [
[[package]]
name = "ethereum_ssz_derive"
version = "0.10.0"
source = "git+https://github.com/sigp/ethereum_ssz?branch=progressive#952eb175cf463ec92d3abaf232e42fb72af7314e"
source = "git+https://github.com/sigp/ethereum_ssz?branch=progressive#ed6332b0572f18bf285d2acdfc6932e1b9d274ef"
dependencies = [
"darling 0.20.11",
"proc-macro2",
@@ -4758,7 +4758,7 @@ checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46"
dependencies = [
"hermit-abi 0.5.2",
"libc",
"windows-sys 0.61.2",
"windows-sys 0.59.0",
]
[[package]]
@@ -6343,7 +6343,7 @@ version = "0.50.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
dependencies = [
"windows-sys 0.61.2",
"windows-sys 0.59.0",
]
[[package]]
@@ -7263,7 +7263,7 @@ dependencies = [
"once_cell",
"socket2 0.6.1",
"tracing",
"windows-sys 0.60.2",
"windows-sys 0.59.0",
]
[[package]]
@@ -7785,7 +7785,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys 0.11.0",
"windows-sys 0.61.2",
"windows-sys 0.59.0",
]
[[package]]
@@ -8872,7 +8872,7 @@ dependencies = [
"getrandom 0.3.4",
"once_cell",
"rustix 1.1.2",
"windows-sys 0.61.2",
"windows-sys 0.59.0",
]
[[package]]
@@ -9445,7 +9445,7 @@ dependencies = [
[[package]]
name = "tree_hash"
version = "0.12.0"
source = "git+https://github.com/sigp/tree_hash?branch=progressive#7400510546840a3985474380d934d33f9ba0d417"
source = "git+https://github.com/sigp/tree_hash?branch=progressive#2fd80712e4d85e5f61dc574d8f5837a5c9b355b8"
dependencies = [
"alloy-primitives",
"ethereum_hashing",
@@ -9457,7 +9457,7 @@ dependencies = [
[[package]]
name = "tree_hash_derive"
version = "0.12.0"
source = "git+https://github.com/sigp/tree_hash?branch=progressive#7400510546840a3985474380d934d33f9ba0d417"
source = "git+https://github.com/sigp/tree_hash?branch=progressive#2fd80712e4d85e5f61dc574d8f5837a5c9b355b8"
dependencies = [
"darling 0.21.3",
"proc-macro2",
@@ -10206,7 +10206,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
"windows-sys 0.61.2",
"windows-sys 0.48.0",
]
[[package]]

View File

@@ -123,6 +123,9 @@ macro_rules! type_dispatch {
"ProgressiveVarTestStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* ProgressiveVarTestStruct>, $($rest)*),
"ProgressiveComplexTestStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* ProgressiveComplexTestStruct>, $($rest)*),
"ProgressiveTestStruct" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* ProgressiveTestStruct>, $($rest)*),
"CompatibleUnionA" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* CompatibleUnionA>, $($rest)*),
"CompatibleUnionBC" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* CompatibleUnionBC>, $($rest)*),
"CompatibleUnionABCA" => type_dispatch!($function, ($($arg),*), $base_ty, <$($param_ty,)* CompatibleUnionABCA>, $($rest)*),
_ => Err(Error::FailedToParseTest(format!("unsupported: {}", $value))),
}
};
@@ -422,6 +425,48 @@ struct ProgressiveComplexTestStruct {
H: ProgressiveList<ProgressiveVarTestStruct>,
}
#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)]
#[ssz(enum_behaviour = "compatible_union")]
#[tree_hash(enum_behaviour = "compatible_union")]
#[context_deserialize(ForkName)]
enum CompatibleUnionA {
#[ssz(selector = "1")]
#[tree_hash(selector = "1")]
ProgressiveSingleFieldContainerTestStruct(ProgressiveSingleFieldContainerTestStruct),
}
#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)]
#[ssz(enum_behaviour = "compatible_union")]
#[tree_hash(enum_behaviour = "compatible_union")]
#[context_deserialize(ForkName)]
enum CompatibleUnionBC {
#[ssz(selector = "2")]
#[tree_hash(selector = "2")]
ProgressiveSingleListContainerTestStruct(ProgressiveSingleListContainerTestStruct),
#[ssz(selector = "3")]
#[tree_hash(selector = "3")]
ProgressiveVarTestStruct(ProgressiveVarTestStruct),
}
#[derive(Debug, Clone, PartialEq, Decode, Encode, TreeHash, Deserialize)]
#[ssz(enum_behaviour = "compatible_union")]
#[tree_hash(enum_behaviour = "compatible_union")]
#[context_deserialize(ForkName)]
enum CompatibleUnionABCA {
#[ssz(selector = "1")]
#[tree_hash(selector = "1")]
A1(ProgressiveSingleFieldContainerTestStruct),
#[ssz(selector = "2")]
#[tree_hash(selector = "2")]
B1(ProgressiveSingleListContainerTestStruct),
#[ssz(selector = "3")]
#[tree_hash(selector = "3")]
C1(ProgressiveVarTestStruct),
#[ssz(selector = "4")]
#[tree_hash(selector = "4")]
A2(ProgressiveSingleFieldContainerTestStruct),
}
fn byte_list_from_hex_str<'de, D, N: Unsigned>(
deserializer: D,
) -> Result<VariableList<u8, N>, D::Error>