From 35151c101d4dbd7d55e386adc4fa9d4448444f00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Wed, 20 Mar 2024 13:54:09 -0300 Subject: [PATCH] feat: add `Eth1block` container (#899) --- lib/types/beacon_chain/eth1_block.ex | 30 ++++++++++++++++++++++++++++ lib/types/beacon_chain/eth1_data.ex | 6 +++--- test/spec/runners/ssz_static.ex | 15 +++++++------- 3 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 lib/types/beacon_chain/eth1_block.ex diff --git a/lib/types/beacon_chain/eth1_block.ex b/lib/types/beacon_chain/eth1_block.ex new file mode 100644 index 000000000..07ff0431a --- /dev/null +++ b/lib/types/beacon_chain/eth1_block.ex @@ -0,0 +1,30 @@ +defmodule Types.Eth1Block do + @moduledoc """ + Struct definition for `Eth1Block`. + """ + use LambdaEthereumConsensus.Container + + fields = [ + :timestamp, + :deposit_root, + :deposit_count + ] + + @enforce_keys fields + defstruct fields + + @type t :: %__MODULE__{ + timestamp: Types.uint64(), + deposit_root: Types.root(), + deposit_count: Types.uint64() + } + + @impl LambdaEthereumConsensus.Container + def schema do + [ + timestamp: TypeAliases.uint64(), + deposit_root: TypeAliases.root(), + deposit_count: TypeAliases.uint64() + ] + end +end diff --git a/lib/types/beacon_chain/eth1_data.ex b/lib/types/beacon_chain/eth1_data.ex index 93978936a..271356c47 100644 --- a/lib/types/beacon_chain/eth1_data.ex +++ b/lib/types/beacon_chain/eth1_data.ex @@ -23,9 +23,9 @@ defmodule Types.Eth1Data do @impl LambdaEthereumConsensus.Container def schema do [ - {:deposit_root, TypeAliases.root()}, - {:deposit_count, TypeAliases.uint64()}, - {:block_hash, TypeAliases.hash32()} + deposit_root: TypeAliases.root(), + deposit_count: TypeAliases.uint64(), + block_hash: TypeAliases.hash32() ] end end diff --git a/test/spec/runners/ssz_static.ex b/test/spec/runners/ssz_static.ex index 559cd3e6e..cf19eb45f 100644 --- a/test/spec/runners/ssz_static.ex +++ b/test/spec/runners/ssz_static.ex @@ -54,7 +54,7 @@ defmodule SszStaticTestRunner do "LightClientBootstrap", "LightClientOptimisticUpdate", "LightClientUpdate", - "Eth1Block", + # "Eth1Block", "PowBlock", "SignedContributionAndProof", "SignedData", @@ -81,7 +81,6 @@ defmodule SszStaticTestRunner do end def skip?(%SpecTestCase{fork: "deneb", handler: handler}) do - # TODO: fix types Enum.member?(@disabled, handler) end @@ -118,14 +117,16 @@ defmodule SszStaticTestRunner do {:ok, deserialized_by_ssz_ex} = SszEx.decode(real_serialized, schema) assert Diff.diff(deserialized_by_ssz_ex, real_deserialized) == :unchanged - {:ok, deserialized_by_nif} = Ssz.from_ssz(real_serialized, schema) - assert Diff.diff(deserialized_by_ssz_ex, deserialized_by_nif) == :unchanged - {:ok, serialized_by_ssz_ex} = SszEx.encode(real_deserialized, schema) assert serialized_by_ssz_ex == real_serialized - {:ok, serialized_by_nif} = Ssz.to_ssz(real_deserialized) - assert Diff.diff(serialized_by_ssz_ex, serialized_by_nif) == :unchanged + if schema not in [Types.Eth1Block] do + {:ok, deserialized_by_nif} = Ssz.from_ssz(real_serialized, schema) + assert Diff.diff(deserialized_by_ssz_ex, deserialized_by_nif) == :unchanged + + {:ok, serialized_by_nif} = Ssz.to_ssz(real_deserialized) + assert serialized_by_ssz_ex == serialized_by_nif + end end defp parse_type(%SpecTestCase{handler: handler}) do