From 219865765740ad3db896faacd51a02a1c73f17f4 Mon Sep 17 00:00:00 2001 From: nikitosing Date: Fri, 7 Jan 2022 15:08:00 +0700 Subject: [PATCH] Add regression tests --- .../lib/explorer/smart_contract/reader.ex | 2 +- .../explorer/smart_contract/reader_test.exs | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) 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,