Merge pull request #1451 from poanetwork/ab-do-not-try-to-convert-nil-in-logs

do not try to convert nils in logs
pull/1462/head
Andrew Cravenho 6 years ago committed by GitHub
commit 845f0bddd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/log.ex
  2. 27
      apps/ethereum_jsonrpc/test/ethereum_jsonrpc/log_test.exs

@ -171,7 +171,11 @@ defmodule EthereumJSONRPC.Log do
do: entry do: entry
defp entry_to_elixir({key, quantity}) when key in ~w(blockNumber logIndex transactionIndex transactionLogIndex) do defp entry_to_elixir({key, quantity}) when key in ~w(blockNumber logIndex transactionIndex transactionLogIndex) do
{key, quantity_to_integer(quantity)} if is_nil(quantity) do
{key, nil}
else
{key, quantity_to_integer(quantity)}
end
end end
defp put_topics(params, topics) when is_map(params) and is_list(topics) do defp put_topics(params, topics) when is_map(params) and is_list(topics) do

@ -2,4 +2,31 @@ defmodule EthereumJSONRPC.LogTest do
use ExUnit.Case, async: true use ExUnit.Case, async: true
doctest EthereumJSONRPC.Log doctest EthereumJSONRPC.Log
alias EthereumJSONRPC.Log
describe "to_elixir/1" do
test "does not tries convert nils to integer" do
input = %{
"address" => "0xda8b3276cde6d768a44b9dac659faa339a41ac55",
"blockHash" => nil,
"blockNumber" => nil,
"data" => "0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563",
"logIndex" => "0x0",
"removed" => false,
"topics" => [
"0xadc1e8a294f8415511303acc4a8c0c5906c7eb0bf2a71043d7f4b03b46a39130",
"0x000000000000000000000000c15bf627accd3b054075c7880425f903106be72a",
"0x000000000000000000000000a59eb37750f9c8f2e11aac6700e62ef89187e4ed"
],
"transactionHash" => "0xf9b663b4e9b1fdc94eb27b5cfba04eb03d2f7b3fa0b24eb2e1af34f823f2b89e",
"transactionIndex" => "0x0"
}
result = Log.to_elixir(input)
assert result["blockNumber"] == nil
assert result["blockHash"] == nil
end
end
end end

Loading…
Cancel
Save