From ecf084e659e39aceda5d6e16ae40fe18f32d37b3 Mon Sep 17 00:00:00 2001 From: Godspower Eze Date: Tue, 12 Dec 2023 14:06:48 +0100 Subject: [PATCH] fix: tests pass --- lib/spec/runners/ssz_generic.ex | 6 ++++-- lib/ssz_ex.ex | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/spec/runners/ssz_generic.ex b/lib/spec/runners/ssz_generic.ex index da0963341..28cb8a00b 100644 --- a/lib/spec/runners/ssz_generic.ex +++ b/lib/spec/runners/ssz_generic.ex @@ -78,7 +78,7 @@ defmodule SszGenericTestRunner do assert serialized == real_serialized end - defp assert_ssz("valid", schema, real_serialized, real_deserialized, hash_tree_root) do + defp assert_ssz("valid", schema, real_serialized, real_deserialized, expected_hash_tree_root) do {:ok, deserialized} = SszEx.decode(real_serialized, schema) assert deserialized == real_deserialized @@ -86,7 +86,9 @@ defmodule SszGenericTestRunner do assert serialized == real_serialized - assert hash_tree_root == SszEx.hash_tree_root!(real_deserialized, schema) + actual_hash_tree_root = SszEx.hash_tree_root!(real_deserialized, schema) + + assert actual_hash_tree_root == expected_hash_tree_root end defp assert_ssz("invalid", schema, real_serialized) do diff --git a/lib/ssz_ex.ex b/lib/ssz_ex.ex index 536385ace..7ea566ce9 100644 --- a/lib/ssz_ex.ex +++ b/lib/ssz_ex.ex @@ -392,7 +392,8 @@ defmodule LambdaEthereumConsensus.SszEx do defp variable_size?({:bytes, _}), do: false defp pack(value, size) when is_integer(value) and value >= 0 do - <> |> String.pad_trailing(32, <<0>>) + pad = 256 - size + <> end defp pack(value) when is_boolean(value) do