From 6f1a521ca733f7167f3947a90b3ad139306822dd Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Mon, 18 Feb 2019 10:33:00 +0300 Subject: [PATCH 1/2] do not try to convert nils in logs --- .../lib/ethereum_jsonrpc/log.ex | 6 ++++- .../test/ethereum_jsonrpc/log_test.exs | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/log.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/log.ex index 55b327ee0e..c9a6fd08e6 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/log.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/log.ex @@ -171,7 +171,11 @@ defmodule EthereumJSONRPC.Log do do: entry 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 defp put_topics(params, topics) when is_map(params) and is_list(topics) do diff --git a/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/log_test.exs b/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/log_test.exs index a2c43064cf..1ea07960da 100644 --- a/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/log_test.exs +++ b/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/log_test.exs @@ -2,4 +2,29 @@ defmodule EthereumJSONRPC.LogTest do use ExUnit.Case, async: true 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 From d1ec793889de9d3cb1867aba7b6a03e7f293bcd7 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Mon, 18 Feb 2019 10:39:28 +0300 Subject: [PATCH 2/2] mix format --- apps/ethereum_jsonrpc/test/ethereum_jsonrpc/log_test.exs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/log_test.exs b/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/log_test.exs index 1ea07960da..3237ea8303 100644 --- a/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/log_test.exs +++ b/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/log_test.exs @@ -14,9 +14,11 @@ defmodule EthereumJSONRPC.LogTest do "data" => "0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563", "logIndex" => "0x0", "removed" => false, - "topics" => ["0xadc1e8a294f8415511303acc4a8c0c5906c7eb0bf2a71043d7f4b03b46a39130", - "0x000000000000000000000000c15bf627accd3b054075c7880425f903106be72a", - "0x000000000000000000000000a59eb37750f9c8f2e11aac6700e62ef89187e4ed"], + "topics" => [ + "0xadc1e8a294f8415511303acc4a8c0c5906c7eb0bf2a71043d7f4b03b46a39130", + "0x000000000000000000000000c15bf627accd3b054075c7880425f903106be72a", + "0x000000000000000000000000a59eb37750f9c8f2e11aac6700e62ef89187e4ed" + ], "transactionHash" => "0xf9b663b4e9b1fdc94eb27b5cfba04eb03d2f7b3fa0b24eb2e1af34f823f2b89e", "transactionIndex" => "0x0" }