Skip to content

Commit

Permalink
Fix case typo in nonpayable state mutability (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisinabh authored Oct 10, 2022
1 parent ad6ad9e commit 39ea3f7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/abi.ex
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ defmodule ABI do
...> |> Jason.decode!
...> |> ABI.parse_specification
...> |> ABI.find_and_decode("b85d0bd200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001" |> Base.decode16!(case: :lower))
{%ABI.FunctionSelector{type: :function, function: "bark", input_names: ["at", "loudly"], method_id: <<184, 93, 11, 210>>, returns: [], types: [:address, :bool]}, [<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1>>, true]}
{%ABI.FunctionSelector{type: :function, function: "bark", input_names: ["at", "loudly"], method_id: <<184, 93, 11, 210>>, returns: [], types: [:address, :bool], state_mutability: :non_payable}, [<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1>>, true]}
"""
def find_and_decode(function_selectors, data, data_type \\ :input) do
with {:ok, method_id, _rest} <- Util.split_method_id(data),
Expand All @@ -145,8 +145,8 @@ defmodule ABI do
iex> File.read!("priv/dog.abi.json")
...> |> Jason.decode!
...> |> ABI.parse_specification
[%ABI.FunctionSelector{type: :function, function: "bark", input_names: ["at", "loudly"], method_id: <<184, 93, 11, 210>>, returns: [], types: [:address, :bool]},
%ABI.FunctionSelector{type: :function, function: "rollover", method_id: <<176, 86, 180, 154>>, returns: [:bool], types: []}]
[%ABI.FunctionSelector{type: :function, function: "bark", input_names: ["at", "loudly"], method_id: <<184, 93, 11, 210>>, returns: [], types: [:address, :bool], state_mutability: :non_payable},
%ABI.FunctionSelector{type: :function, function: "rollover", method_id: <<176, 86, 180, 154>>, returns: [:bool], types: [], state_mutability: :non_payable}]
iex> [%{
...> "constant" => true,
Expand All @@ -161,7 +161,7 @@ defmodule ABI do
...> "type" => "function"
...> }]
...> |> ABI.parse_specification
[%ABI.FunctionSelector{type: :function, function: "bark", method_id: <<184, 93, 11, 210>>, input_names: ["at", "loudly"], returns: [], types: [:address, :bool]}]
[%ABI.FunctionSelector{type: :function, function: "bark", method_id: <<184, 93, 11, 210>>, input_names: ["at", "loudly"], returns: [], types: [:address, :bool], state_mutability: :non_payable}]
iex> [%{
...> "inputs" => [
Expand Down
6 changes: 3 additions & 3 deletions lib/abi/function_selector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ defmodule ABI.FunctionSelector do
"tuple"
]

@state_mutability %{
@state_mutabilities %{
"pure" => :pure,
"view" => :view,
"nonPayable" => :non_payable,
"nonpayable" => :non_payable,
"payable" => :payable
}

Expand Down Expand Up @@ -190,7 +190,7 @@ defmodule ABI.FunctionSelector do
types: input_types,
returns: output_types,
input_names: input_names,
state_mutability: @state_mutability[item["stateMutability"]],
state_mutability: @state_mutabilities[item["stateMutability"]],
type: :function
}

Expand Down
2 changes: 1 addition & 1 deletion test/abi/function_selector_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ defmodule ABI.FunctionSelectorTest do
end

test "with stateMutability set" do
~w(pure view nonPayable payable)
~w(pure view nonpayable payable)
|> Enum.zip(~w(pure view non_payable payable)a)
|> Enum.each(fn {state_mutability, state_mutability_atom} ->
function = %{
Expand Down

0 comments on commit 39ea3f7

Please sign in to comment.