Add regression tests

pull/5066/head
nikitosing 3 years ago
parent 92628a1389
commit 2198657657
  1. 2
      apps/explorer/lib/explorer/smart_contract/reader.ex
  2. 35
      apps/explorer/test/explorer/smart_contract/reader_test.exs

@ -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),

@ -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,

Loading…
Cancel
Save