Skip to content

Commit

Permalink
SC: add get_calls/0
Browse files Browse the repository at this point in the history
  • Loading branch information
bchamagne authored and Neylix committed Jan 25, 2023
1 parent 33c654c commit 3165208
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/archethic/contracts/interpreter/action.ex
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,24 @@ defmodule Archethic.Contracts.ActionInterpreter do
end
end

# expand get_calls() to get_calls(contract.address)
defp postwalk(
node = {{:atom, "get_calls"}, _, []},
test
{{:atom, "get_calls"}, meta, []},
acc
) do
IO.inspect(test)
node = {
{:atom, "get_calls"},
meta,
[
{:get_in, meta,
[
{:scope, meta, nil},
["contract", "address"]
]}
]
}

# see condition.build_conditions (return ast modified (contract address = subject of get_calls))
# return {node, _}
{node, acc}
end

defp postwalk(node, acc) do
Expand Down
25 changes: 25 additions & 0 deletions test/archethic/contracts/interpreter/action_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,31 @@ defmodule Archethic.Contracts.ActionInterpreterTest do
|> ActionInterpreter.execute()
end

test "get_calls() should be expanded to get_calls(contract.address)" do
{:ok, :transaction, ast} =
~S"""
actions triggered_by: transaction do
get_calls()
end
"""
|> Interpreter.sanitize_code()
|> elem(1)
|> ActionInterpreter.parse()

assert {{:., [line: 2],
[
{:__aliases__, [alias: Archethic.Contracts.Interpreter.Library], [:Library]},
:get_calls
]}, [line: 2],
[
{:get_in, meta,
[
{:scope, meta, nil},
["contract", "address"]
]}
]} = ast
end

test "shall use get_genesis_address/1 in actions" do
key = <<0::16, :crypto.strong_rand_bytes(32)::binary>>

Expand Down

0 comments on commit 3165208

Please sign in to comment.