From 9cbcaaf30c9b0f88103eb6b9c3c5eb6b2a01e17e Mon Sep 17 00:00:00 2001 From: Bastien Chamagne Date: Tue, 18 Jul 2023 10:21:38 +0200 Subject: [PATCH] fix contract validation fix tx_to_json, now encodes content as expected --- lib/archethic/contracts.ex | 7 +++++-- lib/archethic/utils/regression/playbook.ex | 2 +- test/archethic/contracts_test.exs | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/archethic/contracts.ex b/lib/archethic/contracts.ex index 390a85b0c..7be94c43c 100644 --- a/lib/archethic/contracts.ex +++ b/lib/archethic/contracts.ex @@ -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 diff --git a/lib/archethic/utils/regression/playbook.ex b/lib/archethic/utils/regression/playbook.ex index 4bc328895..7d0c20486 100644 --- a/lib/archethic/utils/regression/playbook.ex +++ b/lib/archethic/utils/regression/playbook.ex @@ -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{ diff --git a/test/archethic/contracts_test.exs b/test/archethic/contracts_test.exs index 746db01a6..4f5059a80 100644 --- a/test/archethic/contracts_test.exs +++ b/test/archethic/contracts_test.exs @@ -219,7 +219,7 @@ defmodule Archethic.ContractsTest do """ prev_tx = %Transaction{ - address: ArchethicCase.random_address(), + address: random_address(), type: :contract, data: %TransactionData{ code: code @@ -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 @@ -245,7 +245,7 @@ defmodule Archethic.ContractsTest do """ prev_tx = %Transaction{ - address: ArchethicCase.random_address(), + address: random_address(), type: :oracle, data: %TransactionData{ code: code @@ -275,7 +275,7 @@ defmodule Archethic.ContractsTest do """ prev_tx = %Transaction{ - address: ArchethicCase.random_address(), + address: random_address(), type: :contract, data: %TransactionData{ code: code