Skip to content

Commit

Permalink
feat: add Eth1block container (#899)
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaRedHand authored Mar 20, 2024
1 parent a1a45a0 commit 35151c1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
30 changes: 30 additions & 0 deletions lib/types/beacon_chain/eth1_block.ex
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions lib/types/beacon_chain/eth1_data.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 8 additions & 7 deletions test/spec/runners/ssz_static.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule SszStaticTestRunner do
"LightClientBootstrap",
"LightClientOptimisticUpdate",
"LightClientUpdate",
"Eth1Block",
# "Eth1Block",
"PowBlock",
"SignedContributionAndProof",
"SignedData",
Expand All @@ -81,7 +81,6 @@ defmodule SszStaticTestRunner do
end

def skip?(%SpecTestCase{fork: "deneb", handler: handler}) do
# TODO: fix types
Enum.member?(@disabled, handler)
end

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 35151c1

Please sign in to comment.