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

Smart Contract: is_function_call? bug #987

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion lib/archethic/contracts/interpreter/ast_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ defmodule Archethic.Contracts.Interpreter.ASTHelper do
"""
@spec is_function_call?(Macro.t()) :: boolean()
def is_function_call?({{:atom, _}, _, list}) when is_list(list), do: true
def is_function_call?({{:., _, [{:__aliases__, _, [_]}, _]}, _, _}), do: true
def is_function_call?({{:., _, [{:__aliases__, _, _}, _]}, _, _}), do: true
def is_function_call?(_), do: false

@doc """
Expand Down
15 changes: 15 additions & 0 deletions test/archethic/contracts/interpreter/action_interpreter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,21 @@ defmodule Archethic.Contracts.Interpreter.ActionInterpreterTest do
|> ActionInterpreter.parse()
end

test "should be able to use a function call as a parameter to a lib function" do
code = ~S"""
actions triggered_by: transaction do
count = List.size(Contract.get_calls())
Contract.set_content(count)
end
"""

assert {:ok, :transaction, _} =
code
|> Interpreter.sanitize_code()
|> elem(1)
|> ActionInterpreter.parse()
end

test "should not be able to use wrong types in contract functions" do
code = ~S"""
actions triggered_by: transaction do
Expand Down