From 966098ea747b2d4b1ea74706d3748902aac97379 Mon Sep 17 00:00:00 2001 From: Samuel Manzanera Date: Wed, 18 Dec 2024 15:49:25 +0100 Subject: [PATCH] fix lint --- lib/archethic/contracts.ex | 2 +- lib/archethic/contracts/interpreter.ex | 4 ++-- lib/archethic/contracts/interpreter/action_interpreter.ex | 2 +- lib/archethic/contracts/interpreter/contract.ex | 2 +- lib/archethic/contracts/interpreter/legacy.ex | 2 +- .../contracts/interpreter/legacy/action_interpreter.ex | 2 +- lib/archethic/contracts/wasm/contract.ex | 6 +++--- lib/archethic/contracts/worker.ex | 2 +- lib/archethic/crypto.ex | 4 ++-- lib/archethic/mining/proof_of_work.ex | 2 +- lib/archethic/mining/smart_contract_validation.ex | 2 +- .../contracts/{ => interpreter}/constants_test.exs | 0 .../archethic/contracts/{ => interpreter}/contract_test.exs | 4 ++-- .../contracts/interpreter/library/common/crypto_test.exs | 2 +- .../contracts/interpreter/library/common/http_impl_test.exs | 5 +++-- .../contracts/interpreter/library/common/time_test.exs | 2 +- test/archethic/contracts/interpreter_test.exs | 2 +- test/archethic/contracts/loader_test.exs | 2 +- test/archethic/contracts/worker_test.exs | 2 +- test/archethic/contracts_test.exs | 2 +- .../mining/pending_transaction_validation_test.exs | 2 +- 21 files changed, 27 insertions(+), 26 deletions(-) rename test/archethic/contracts/{ => interpreter}/constants_test.exs (100%) rename test/archethic/contracts/{ => interpreter}/contract_test.exs (98%) diff --git a/lib/archethic/contracts.ex b/lib/archethic/contracts.ex index 092f8eda60..d17d265ba4 100644 --- a/lib/archethic/contracts.ex +++ b/lib/archethic/contracts.ex @@ -4,7 +4,6 @@ defmodule Archethic.Contracts do Each smart contract is register and supervised as long running process to interact with later on. """ - alias __MODULE__.InterpretedContract alias __MODULE__.Interpreter.Conditions, as: ConditionsInterpreter alias __MODULE__.Interpreter.Constants, as: ConstantsInterpreter alias __MODULE__.Contract.ActionWithoutTransaction @@ -14,6 +13,7 @@ defmodule Archethic.Contracts do alias __MODULE__.Contract.State alias __MODULE__.Interpreter alias __MODULE__.Interpreter.Library + alias __MODULE__.Interpreter.Contract, as: InterpretedContract alias __MODULE__.Loader alias __MODULE__.WasmContract diff --git a/lib/archethic/contracts/interpreter.ex b/lib/archethic/contracts/interpreter.ex index a86040b737..8d50a9361b 100644 --- a/lib/archethic/contracts/interpreter.ex +++ b/lib/archethic/contracts/interpreter.ex @@ -11,9 +11,9 @@ defmodule Archethic.Contracts.Interpreter do alias __MODULE__.Legacy alias __MODULE__.Scope alias Archethic.Contracts - alias Archethic.Contracts.Intepreter.Conditions.Subjects, as: ConditionsSubjects + alias Archethic.Contracts.Interpreter.Conditions.Subjects, as: ConditionsSubjects alias Archethic.Contracts.Interpreter.Constants - alias Archethic.Contracts.InterpretedContract, as: Contract + alias Archethic.Contracts.Interpreter.Contract alias Archethic.Contracts.Contract.State alias Archethic.TransactionChain.Transaction alias Archethic.TransactionChain.TransactionData.Recipient diff --git a/lib/archethic/contracts/interpreter/action_interpreter.ex b/lib/archethic/contracts/interpreter/action_interpreter.ex index e4ab45677b..408bd840d5 100644 --- a/lib/archethic/contracts/interpreter/action_interpreter.ex +++ b/lib/archethic/contracts/interpreter/action_interpreter.ex @@ -1,8 +1,8 @@ defmodule Archethic.Contracts.Interpreter.ActionInterpreter do @moduledoc false - alias Archethic.Contracts.Contract alias Archethic.Contracts.Contract.State + alias Archethic.Contracts.Interpreter.Contract alias Archethic.Contracts.Interpreter.ASTHelper, as: AST alias Archethic.Contracts.Interpreter.CommonInterpreter alias Archethic.Contracts.Interpreter.FunctionKeys diff --git a/lib/archethic/contracts/interpreter/contract.ex b/lib/archethic/contracts/interpreter/contract.ex index 489d28353b..e965d6aab3 100644 --- a/lib/archethic/contracts/interpreter/contract.ex +++ b/lib/archethic/contracts/interpreter/contract.ex @@ -1,4 +1,4 @@ -defmodule Archethic.Contracts.InterpretedContract do +defmodule Archethic.Contracts.Interpreter.Contract do @moduledoc """ Represents a smart contract """ diff --git a/lib/archethic/contracts/interpreter/legacy.ex b/lib/archethic/contracts/interpreter/legacy.ex index 215492ff76..9192652fde 100644 --- a/lib/archethic/contracts/interpreter/legacy.ex +++ b/lib/archethic/contracts/interpreter/legacy.ex @@ -7,7 +7,7 @@ defmodule Archethic.Contracts.Interpreter.Legacy do alias __MODULE__.ConditionInterpreter alias Archethic.Contracts - alias Archethic.Contracts.InterpretedContract, as: Contract + alias Archethic.Contracts.Interpreter.Contract alias Archethic.Contracts.Interpreter.Conditions.Subjects, as: ConditionsSubjects alias Archethic.Contracts.Interpreter diff --git a/lib/archethic/contracts/interpreter/legacy/action_interpreter.ex b/lib/archethic/contracts/interpreter/legacy/action_interpreter.ex index b4747ac3f4..5bb9860e02 100644 --- a/lib/archethic/contracts/interpreter/legacy/action_interpreter.ex +++ b/lib/archethic/contracts/interpreter/legacy/action_interpreter.ex @@ -1,7 +1,7 @@ defmodule Archethic.Contracts.Interpreter.Legacy.ActionInterpreter do @moduledoc false - alias Archethic.Contracts.Contract alias Archethic.Contracts.Interpreter + alias Archethic.Contracts.Interpreter.Contract alias Archethic.Contracts.Interpreter.Legacy.TransactionStatements alias Archethic.Contracts.Interpreter.Legacy.UtilsInterpreter diff --git a/lib/archethic/contracts/wasm/contract.ex b/lib/archethic/contracts/wasm/contract.ex index 7d5e383698..f1a27c36d4 100644 --- a/lib/archethic/contracts/wasm/contract.ex +++ b/lib/archethic/contracts/wasm/contract.ex @@ -35,7 +35,7 @@ defmodule Archethic.Contracts.WasmContract do @type t() :: %__MODULE__{ version: integer(), - module: WasmModule.t(), + module: nil | WasmModule.t(), state: State.t(), transaction: Transaction.t() } @@ -79,8 +79,8 @@ defmodule Archethic.Contracts.WasmContract do def from_transaction(tx = %Transaction{data: %TransactionData{contract: contract}}) when contract != nil do case parse(contract) do - {:ok, contract} -> - {:ok, %{contract | state: get_state_from_tx(tx), transaction: tx}} + {:ok, module} -> + {:ok, %{module | state: get_state_from_tx(tx), transaction: tx}} {:error, _} = e -> e diff --git a/lib/archethic/contracts/worker.ex b/lib/archethic/contracts/worker.ex index 33c2709c29..221bef944f 100644 --- a/lib/archethic/contracts/worker.ex +++ b/lib/archethic/contracts/worker.ex @@ -3,7 +3,7 @@ defmodule Archethic.Contracts.Worker do alias Archethic.ContractRegistry alias Archethic.Contracts - alias Archethic.Contracts.InterpretedContract + alias Archethic.Contracts.Interpreter.Contract, as: InterpretedContract alias Archethic.Contracts.WasmSpec alias Archethic.Contracts.WasmContract alias Archethic.Contracts.WasmModule diff --git a/lib/archethic/crypto.ex b/lib/archethic/crypto.ex index 658b32e8ca..4c058bfea0 100755 --- a/lib/archethic/crypto.ex +++ b/lib/archethic/crypto.ex @@ -1438,7 +1438,7 @@ defmodule Archethic.Crypto do """ @spec aggregate_signatures(signatures :: list(binary()), public_keys :: list(key())) :: binary() def aggregate_signatures(signatures, public_keys) do - BlsEx.aggregate_signatures( + BlsEx.aggregate_signatures!( signatures, Enum.map(public_keys, fn <<_::8, _::8, public_key::binary>> -> public_key end) ) @@ -1451,7 +1451,7 @@ defmodule Archethic.Crypto do def aggregate_mining_public_keys(public_keys) do public_keys |> Enum.map(fn <<_::8, _::8, public_key::binary>> -> public_key end) - |> BlsEx.aggregate_public_keys() + |> BlsEx.aggregate_public_keys!() |> ID.prepend_key(:bls) end end diff --git a/lib/archethic/mining/proof_of_work.ex b/lib/archethic/mining/proof_of_work.ex index da9232cd7d..e300c2e5d3 100644 --- a/lib/archethic/mining/proof_of_work.ex +++ b/lib/archethic/mining/proof_of_work.ex @@ -11,7 +11,7 @@ defmodule Archethic.Mining.ProofOfWork do alias Archethic.Contracts alias Archethic.Contracts.Interpreter - alias Archethic.Contracts.InterpretedContract + alias Archethic.Contracts.Interpreter.Contract, as: InterpretedContract alias Archethic.Crypto diff --git a/lib/archethic/mining/smart_contract_validation.ex b/lib/archethic/mining/smart_contract_validation.ex index 082e3f9deb..238de91e0d 100644 --- a/lib/archethic/mining/smart_contract_validation.ex +++ b/lib/archethic/mining/smart_contract_validation.ex @@ -6,7 +6,7 @@ defmodule Archethic.Mining.SmartContractValidation do alias Archethic.Contracts alias Archethic.Contracts.Contract.State alias Archethic.Contracts.Contract.Context - alias Archethic.Contracts.InterpretedContract + alias Archethic.Contracts.Interpreter.Contract, as: InterpretedContract alias Archethic.Contracts.WasmContract alias Archethic.Contracts.WasmModule alias Archethic.Contracts.Wasm.ReadResult diff --git a/test/archethic/contracts/constants_test.exs b/test/archethic/contracts/interpreter/constants_test.exs similarity index 100% rename from test/archethic/contracts/constants_test.exs rename to test/archethic/contracts/interpreter/constants_test.exs diff --git a/test/archethic/contracts/contract_test.exs b/test/archethic/contracts/interpreter/contract_test.exs similarity index 98% rename from test/archethic/contracts/contract_test.exs rename to test/archethic/contracts/interpreter/contract_test.exs index 04bcbb2501..a919084730 100644 --- a/test/archethic/contracts/contract_test.exs +++ b/test/archethic/contracts/interpreter/contract_test.exs @@ -1,13 +1,13 @@ -defmodule Archethic.Contracts.InterpretedContractTest do +defmodule Archethic.Contracts.Interpreter.ContractTest do use ArchethicCase # import ArchethicCase alias Archethic.ContractFactory alias Archethic.Contracts - alias Archethic.Contracts.InterpretedContract, as: Contract alias Archethic.Contracts.Contract.ActionWithTransaction alias Archethic.Contracts.Contract.State alias Archethic.Contracts.Interpreter + alias Archethic.Contracts.Interpreter.Contract alias Archethic.Crypto alias Archethic.TransactionChain.Transaction alias Archethic.TransactionChain.TransactionData diff --git a/test/archethic/contracts/interpreter/library/common/crypto_test.exs b/test/archethic/contracts/interpreter/library/common/crypto_test.exs index 46a6ac6281..3f40553681 100644 --- a/test/archethic/contracts/interpreter/library/common/crypto_test.exs +++ b/test/archethic/contracts/interpreter/library/common/crypto_test.exs @@ -6,8 +6,8 @@ defmodule Archethic.Contracts.Interpreter.Library.Common.CryptoTest do use ArchethicCase - alias Archethic.Contracts.InterpretedContract, as: Contract alias Archethic.Contracts.Interpreter + alias Archethic.Contracts.Interpreter.Contract alias Archethic.Contracts.Interpreter.Library alias Archethic.Contracts.Interpreter.Library.Common.Crypto diff --git a/test/archethic/contracts/interpreter/library/common/http_impl_test.exs b/test/archethic/contracts/interpreter/library/common/http_impl_test.exs index 8d625414f4..cba3b8e07a 100644 --- a/test/archethic/contracts/interpreter/library/common/http_impl_test.exs +++ b/test/archethic/contracts/interpreter/library/common/http_impl_test.exs @@ -224,8 +224,8 @@ defmodule Archethic.Contracts.Interpreter.Library.Common.HttpImplTest do describe "request_many/2" do test "should return a status -4001 for timeout" do assert [ - %{"status" => 200}, - %{"status" => -4001} + %{"status" => -4001}, + %{"status" => 200} ] = HttpImpl.request_many( [ @@ -234,6 +234,7 @@ defmodule Archethic.Contracts.Interpreter.Library.Common.HttpImplTest do ], false ) + |> Enum.sort_by(fn %{"status" => status} -> status end) end test "should return a status -4004 for non https" do diff --git a/test/archethic/contracts/interpreter/library/common/time_test.exs b/test/archethic/contracts/interpreter/library/common/time_test.exs index 822f3d65ec..b3fd0c1270 100644 --- a/test/archethic/contracts/interpreter/library/common/time_test.exs +++ b/test/archethic/contracts/interpreter/library/common/time_test.exs @@ -3,9 +3,9 @@ defmodule Archethic.Contracts.Interpreter.Library.Common.TimeTest do alias Archethic.ContractFactory alias Archethic.Contracts - alias Archethic.Contracts.InterpretedContract, as: Contract alias Archethic.Contracts.Contract.ActionWithTransaction alias Archethic.Contracts.Contract.ConditionRejected + alias Archethic.Contracts.Interpreter.Contract alias Archethic.Contracts.Interpreter.Library.Common.Time alias Archethic.TransactionChain.Transaction alias Archethic.TransactionChain.TransactionData diff --git a/test/archethic/contracts/interpreter_test.exs b/test/archethic/contracts/interpreter_test.exs index 8b0e16fea5..0edcd4d5fd 100644 --- a/test/archethic/contracts/interpreter_test.exs +++ b/test/archethic/contracts/interpreter_test.exs @@ -6,7 +6,7 @@ defmodule Archethic.Contracts.InterpreterTest do alias Archethic.ContractFactory alias Archethic.Contracts.Interpreter.Conditions alias Archethic.Contracts.Interpreter.Constants - alias Archethic.Contracts.InterpretedContract, as: Contract + alias Archethic.Contracts.Interpreter.Contract alias Archethic.Contracts.Contract.State alias Archethic.Contracts.Interpreter alias Archethic.Contracts.Interpreter.Library diff --git a/test/archethic/contracts/loader_test.exs b/test/archethic/contracts/loader_test.exs index 572f1e5f34..65452ab291 100644 --- a/test/archethic/contracts/loader_test.exs +++ b/test/archethic/contracts/loader_test.exs @@ -5,7 +5,7 @@ defmodule Archethic.Contracts.LoaderTest do alias Archethic.ContractRegistry alias Archethic.ContractSupervisor - alias Archethic.Contracts.InterpretedContract, as: Contract + alias Archethic.Contracts.Interpreter.Contract alias Archethic.Contracts.Loader alias Archethic.Contracts.Worker alias Archethic.Contracts.Contract.Context diff --git a/test/archethic/contracts/worker_test.exs b/test/archethic/contracts/worker_test.exs index ecbdd2c81d..0ad7d8ff26 100644 --- a/test/archethic/contracts/worker_test.exs +++ b/test/archethic/contracts/worker_test.exs @@ -8,7 +8,7 @@ defmodule Archethic.Contracts.WorkerTest do alias Archethic.PubSub alias Archethic.ContractSupervisor - alias Archethic.Contracts.InterpretedContract, as: Contract + alias Archethic.Contracts.Interpreter.Contract alias Archethic.Contracts.Worker alias Archethic.P2P.Message.StartMining diff --git a/test/archethic/contracts_test.exs b/test/archethic/contracts_test.exs index 64f2e19452..a323c278eb 100644 --- a/test/archethic/contracts_test.exs +++ b/test/archethic/contracts_test.exs @@ -2,7 +2,7 @@ defmodule Archethic.ContractsTest do use ArchethicCase alias Archethic.Contracts - alias Archethic.Contracts.InterpretedContract, as: Contract + alias Archethic.Contracts.Interpreter.Contract alias Archethic.Contracts.Contract.ActionWithTransaction alias Archethic.Contracts.Contract.ActionWithoutTransaction alias Archethic.Contracts.Contract.ConditionRejected diff --git a/test/archethic/mining/pending_transaction_validation_test.exs b/test/archethic/mining/pending_transaction_validation_test.exs index 80505be5ce..a9e1fe1cd4 100644 --- a/test/archethic/mining/pending_transaction_validation_test.exs +++ b/test/archethic/mining/pending_transaction_validation_test.exs @@ -151,7 +151,7 @@ defmodule Archethic.Mining.PendingTransactionValidationTest do tx = TransactionFactory.create_non_valided_transaction( type: :data, - content: :crypto.strong_rand_bytes(3_145_711) + content: :crypto.strong_rand_bytes(3_145_700) ) assert :ok = PendingTransactionValidation.validate_size(tx)