Skip to content

Commit

Permalink
fix contract validation
Browse files Browse the repository at this point in the history
fix tx_to_json, now encodes content as expected
  • Loading branch information
bchamagne committed Jul 18, 2023
1 parent 942667f commit 7fff561
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions lib/archethic/contracts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ defmodule Archethic.Contracts do
when code != "" do
# only contract without triggers (with only conditions) are allowed to NOT have a Contract.Context
case from_transaction(prev_tx) do
{:ok, %Contract{triggers: %{}}} -> true
_ -> false
{:ok, %Contract{triggers: triggers}} when map_size(triggers) == 0 ->
true

_ ->
false
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/archethic/utils/regression/playbook.ex
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ defmodule Archethic.Utils.Regression.Playbook do
}
},
"code" => code,
"content" => content,
"content" => Base.encode16(content),
"recipients" => Enum.map(recipients, &Base.encode16(&1)),
"ownerships" =>
Enum.map(ownerships, fn %Ownership{
Expand Down
8 changes: 4 additions & 4 deletions test/archethic/contracts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ defmodule Archethic.ContractsTest do
"""

prev_tx = %Transaction{
address: ArchethicCase.random_address(),
address: random_address(),
type: :contract,
data: %TransactionData{
code: code
Expand All @@ -235,7 +235,7 @@ defmodule Archethic.ContractsTest do
}
}

assert Contracts.valid_execution?(prev_tx, next_tx, nil)
refute Contracts.valid_execution?(prev_tx, next_tx, nil)
end

test "should return true if there is no context and there is no trigger" do
Expand All @@ -245,7 +245,7 @@ defmodule Archethic.ContractsTest do
"""

prev_tx = %Transaction{
address: ArchethicCase.random_address(),
address: random_address(),
type: :oracle,
data: %TransactionData{
code: code
Expand Down Expand Up @@ -275,7 +275,7 @@ defmodule Archethic.ContractsTest do
"""

prev_tx = %Transaction{
address: ArchethicCase.random_address(),
address: random_address(),
type: :contract,
data: %TransactionData{
code: code
Expand Down

0 comments on commit 7fff561

Please sign in to comment.