Skip to content

Commit

Permalink
fix: parse ABI that is missing the outputs field
Browse files Browse the repository at this point in the history
  • Loading branch information
fedor-ivn committed Jun 21, 2024
1 parent 29dcbbf commit 361f0c1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/abi/function_selector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ defmodule ABI.FunctionSelector do
def parse_specification_item(%{"type" => "function"} = item) do
with %{
"name" => function_name,
"inputs" => named_inputs,
"outputs" => named_outputs
"inputs" => named_inputs
} <- item,
named_outputs = Map.get(item, "outputs", []),
true <- simple_types?(named_inputs, item),
true <- simple_types?(named_outputs, item) do
input_types = Enum.map(named_inputs, &parse_specification_type/1)
Expand Down
33 changes: 33 additions & 0 deletions test/abi_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,39 @@ defmodule ABITest do

assert parse_specification(abi) == expected
end

test "parses an ABI without outputs" do
abi = [
%{
"type" => "function",
"stateMutability" => "view",
"name" => "assumeLastTokenIdMatches",
"inputs" => [
%{
"type" => "uint256",
"name" => "lastTokenId",
"internalType" => "uint256"
}
]
}
]

expected = [
%ABI.FunctionSelector{
function: "assumeLastTokenIdMatches",
method_id: <<231, 40, 120, 180>>,
type: :function,
inputs_indexed: nil,
state_mutability: :view,
input_names: ["lastTokenId"],
types: [uint: 256],
returns: [],
return_names: []
}
]

assert parse_specification(abi) == expected
end
end

describe "find_and_decode/2" do
Expand Down

0 comments on commit 361f0c1

Please sign in to comment.