Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing when function ABI is missing the outputs field #163

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/abi/function_selector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ defmodule ABI.FunctionSelector do
"name" => function_name,
"inputs" => named_inputs,
"outputs" => named_outputs
} <- item,
} <-
item
# Workaround for missing "outputs" field.
# This is a fix for https://github.com/poanetwork/ex_abi/issues/162
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's write a full description here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, please check the new commit

|> Map.put_new("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
36 changes: 36 additions & 0 deletions test/abi/function_selector_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,42 @@ defmodule ABI.FunctionSelectorTest do
}
] == ABI.parse_specification([abi])
end

@doc """
Regression test for issue #162 (https://github.com/poanetwork/ex_abi/issues/162).
"""
test "with the missing outputs field" do
abi = [
%{
"type" => "function",
"stateMutability" => "view",
"name" => "assumeLastTokenIdMatches",
"inputs" => [
%{
"type" => "uint256",
"name" => "lastTokenId",
"internalType" => "uint256"
}
]
}
]

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

assert ABI.parse_specification(abi) == expected
end
end

describe "parse_specification_item/1" do
Expand Down