From 83d526d83a5c8c7b50e3e5cb97c81a2371e824ba Mon Sep 17 00:00:00 2001 From: Alisina Bahadori Date: Mon, 29 Jan 2024 12:12:32 -0500 Subject: [PATCH] Fix raise on missing values --- lib/ethers/transaction.ex | 2 ++ test/ethers/transaction_test.exs | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/ethers/transaction.ex b/lib/ethers/transaction.ex index c82d798..04ae4e4 100644 --- a/lib/ethers/transaction.ex +++ b/lib/ethers/transaction.ex @@ -200,6 +200,8 @@ defmodule Ethers.Transaction do tx |> Map.from_struct() |> Map.new(fn + {k, nil} -> {k, nil} + {k, ""} -> {k, nil} {k, v} when k in @integer_type_values -> {k, Utils.hex_to_integer!(v)} {k, v} when k in @binary_type_values -> {k, Utils.hex_decode!(v)} {k, v} -> {k, v} diff --git a/test/ethers/transaction_test.exs b/test/ethers/transaction_test.exs index e2cbfde..1384cb9 100644 --- a/test/ethers/transaction_test.exs +++ b/test/ethers/transaction_test.exs @@ -55,5 +55,13 @@ defmodule Ethers.TransactionTest do assert is_binary(decoded.signature_r) assert is_binary(decoded.signature_s) end + + test "does not fail with missing values" do + assert %{signature_recovery_id: nil} = + Transaction.decode_values(%{@transaction_fixture | signature_recovery_id: nil}) + + assert %{signature_recovery_id: nil} = + Transaction.decode_values(%{@transaction_fixture | signature_recovery_id: ""}) + end end end