Skip to content

Commit

Permalink
fix: change file
Browse files Browse the repository at this point in the history
  • Loading branch information
Godspower-Eze committed Dec 11, 2023
1 parent d65a76c commit 0aeffa3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
8 changes: 6 additions & 2 deletions lib/spec/runners/ssz_generic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ defmodule SszGenericTestRunner do
defp handle_case("valid", schema, real_serialized, testcase) do
case_dir = SpecTestCase.dir(testcase)

expected =
expected_value =
YamlElixir.read_from_file!(case_dir <> "/value.yaml")
|> SpecTestUtils.sanitize_yaml()

assert_ssz("valid", schema, real_serialized, expected)
expected_root =

Check warning on line 56 in lib/spec/runners/ssz_generic.ex

View workflow job for this annotation

GitHub Actions / Test

variable "expected_root" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 56 in lib/spec/runners/ssz_generic.ex

View workflow job for this annotation

GitHub Actions / Build project

variable "expected_root" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 56 in lib/spec/runners/ssz_generic.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (general)

variable "expected_root" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 56 in lib/spec/runners/ssz_generic.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (general)

variable "expected_root" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 56 in lib/spec/runners/ssz_generic.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (minimal)

variable "expected_root" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 56 in lib/spec/runners/ssz_generic.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (minimal)

variable "expected_root" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 56 in lib/spec/runners/ssz_generic.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (mainnet)

variable "expected_root" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 56 in lib/spec/runners/ssz_generic.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (mainnet)

variable "expected_root" is unused (if the variable is not meant to be used, prefix it with an underscore)
YamlElixir.read_from_file!(case_dir <> "/meta.yaml")
|> SpecTestUtils.sanitize_yaml()

assert_ssz("valid", schema, real_serialized, expected_value)
end

defp handle_case("invalid", schema, real_serialized, _testcase) do
Expand Down
23 changes: 0 additions & 23 deletions lib/ssz.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ defmodule Ssz do
"""
use Rustler, otp_app: :lambda_ethereum_consensus, crate: "ssz_nif"

alias LambdaEthereumConsensus.SszEx

##### Functional wrappers
@spec to_ssz(struct | list(struct)) :: {:ok, binary} | {:error, String.t()}
def to_ssz(map)
Expand Down Expand Up @@ -42,16 +40,6 @@ defmodule Ssz do
end
end

@spec hash_tree_root!(boolean) :: SszTypes.root()
def hash_tree_root!(value) when is_boolean(value) do
pack(value) |> SszEx.hash()
end

@spec hash_tree_root!(non_neg_integer) :: SszTypes.root()
def hash_tree_root!(value) when is_integer(value) and value >= 0 do
pack(value) |> SszEx.hash()
end

@spec hash_tree_root!(struct) :: SszTypes.root()
def hash_tree_root!(map) do
{:ok, root} = hash_tree_root(map)
Expand Down Expand Up @@ -183,15 +171,4 @@ defmodule Ssz do

@spec decode_u256(binary) :: non_neg_integer
def decode_u256(num), do: :binary.decode_unsigned(num, :little)

defp pack(value) when is_integer(value) and value >= 0 do
value |> :binary.encode_unsigned(:little) |> String.pad_trailing(32, <<0>>)
end

defp pack(value) when is_boolean(value) do
case value do
true -> <<1>> |> String.pad_trailing(32, <<0>>)
false -> <<0>> |> String.pad_trailing(32, <<0>>)
end
end
end
21 changes: 21 additions & 0 deletions lib/ssz_ex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ defmodule LambdaEthereumConsensus.SszEx do

def decode(binary, module) when is_atom(module), do: decode_container(binary, module)

@spec hash_tree_root!(boolean) :: SszTypes.root()
def hash_tree_root!(value) when is_boolean(value) do
pack(value) |> hash()
end

@spec hash_tree_root!(non_neg_integer) :: SszTypes.root()
def hash_tree_root!(value) when is_integer(value) and value >= 0 do
pack(value) |> hash()
end

#################
### Private functions
#################
Expand Down Expand Up @@ -384,4 +394,15 @@ defmodule LambdaEthereumConsensus.SszEx do
defp variable_size?(:bool), do: false
defp variable_size?({:int, _}), do: false
defp variable_size?({:bytes, _}), do: false

defp pack(value) when is_integer(value) and value >= 0 do
value |> :binary.encode_unsigned(:little) |> String.pad_trailing(32, <<0>>)
end

defp pack(value) when is_boolean(value) do
case value do
true -> <<1>> |> String.pad_trailing(32, <<0>>)
false -> <<0>> |> String.pad_trailing(32, <<0>>)
end
end
end

0 comments on commit 0aeffa3

Please sign in to comment.