diff --git a/apps/explorer/lib/explorer/smart_contract/reader.ex b/apps/explorer/lib/explorer/smart_contract/reader.ex index fd07294a00..16e03cd48b 100644 --- a/apps/explorer/lib/explorer/smart_contract/reader.ex +++ b/apps/explorer/lib/explorer/smart_contract/reader.ex @@ -295,7 +295,7 @@ defmodule Explorer.SmartContract.Reader do end end - defp get_abi_with_method_id(abi) do + def get_abi_with_method_id(abi) do abi |> Enum.map(fn method -> with parsed_method <- [method] |> ABI.parse_specification() |> Enum.at(0), diff --git a/apps/explorer/test/explorer/smart_contract/reader_test.exs b/apps/explorer/test/explorer/smart_contract/reader_test.exs index befc365095..87ba283eb4 100644 --- a/apps/explorer/test/explorer/smart_contract/reader_test.exs +++ b/apps/explorer/test/explorer/smart_contract/reader_test.exs @@ -366,6 +366,41 @@ defmodule Explorer.SmartContract.ReaderTest do end end + describe "get_abi_with_method_id" do + test "add method_id to the ABI method" do + method = %{ + "constant" => true, + "inputs" => [%{"name" => "_message", "type" => "bytes32"}], + "name" => "numMessagesSigned", + "outputs" => [%{"name" => "", "type" => "uint256"}], + "payable" => false, + "stateMutability" => "view", + "type" => "function" + } + + abi = [method] + method_with_id = Map.put(method, "method_id", "0cbf0601") + assert [method_with_id] = Reader.get_abi_with_method_id(abi) + end + + test "do not crash in some corner cases" do + abi = [ + %{"payable" => true, "stateMutability" => "payable", "type" => "fallback"}, + %{ + "anonymous" => false, + "inputs" => [ + %{"indexed" => false, "name" => "recipient", "type" => "address"}, + %{"indexed" => false, "name" => "value", "type" => "uint256"} + ], + "name" => "UserRequestForSignature", + "type" => "event" + } + ] + + assert abi = Reader.get_abi_with_method_id(abi) + end + end + defp blockchain_get_function_mock do expect( EthereumJSONRPC.Mox,