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

Scope assignation returns assigned value #1386

Merged
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
4 changes: 2 additions & 2 deletions lib/archethic/contracts/interpreter/scope.ex
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ defmodule Archethic.Contracts.Interpreter.Scope do
)
)

:ok
value
end

@doc """
Expand All @@ -157,7 +157,7 @@ defmodule Archethic.Contracts.Interpreter.Scope do
)
)

:ok
value
end

@doc """
Expand Down
29 changes: 29 additions & 0 deletions test/archethic/contracts/interpreter/scope_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,21 @@ defmodule Archethic.Contracts.Interpreter.ScopeTest do
end

describe "write_at/2" do
test "should return assigned value" do
# Setup with a single context and a single scope
scope = %{
"current_context" => %{
"only_scope" => %{},
scope_hierarchy: ["only_scope"]
},
context_list: ["current_context"]
}

Process.put(:scope, scope)

assert 42 == Scope.write_at("my_var", 42)
end

test "should write a variable in the current scope of the current context" do
# Setup with a single context and a single scope
scope = %{
Expand Down Expand Up @@ -312,6 +327,20 @@ defmodule Archethic.Contracts.Interpreter.ScopeTest do
end

describe "write_cascade/2" do
test "should return assigned value" do
scope = %{
"current_context" => %{
"only_scope" => %{},
scope_hierarchy: ["only_scope"]
},
context_list: ["current_context"]
}

Process.put(:scope, scope)

assert 42 == Scope.write_cascade("my_var", 42)
end

test "should write the variable in the current scope if it doesn't exist anywhere" do
scope = %{
"current_context" => %{
Expand Down