Skip to content

Commit

Permalink
Rename Contract.from_contract function
Browse files Browse the repository at this point in the history
  • Loading branch information
Neylix committed Sep 13, 2023
1 parent f598e24 commit b4fc4e0
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 33 deletions.
8 changes: 4 additions & 4 deletions lib/archethic/contracts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ defmodule Archethic.Contracts do
case get_function_from_contract(contract, function_name, args) do
{:ok, function} ->
constants = %{
"contract" => Constants.from_contract(contract_tx, contract_version),
"contract" => Constants.from_contract_transaction(contract_tx, contract_version),
:time_now => DateTime.utc_now() |> DateTime.to_unix()
}

Expand Down Expand Up @@ -359,8 +359,8 @@ defmodule Archethic.Contracts do
datetime
) do
%{
"previous" => Constants.from_contract(contract_tx, contract_version),
"next" => Constants.from_contract(transaction, contract_version),
"previous" => Constants.from_contract_transaction(contract_tx, contract_version),
"next" => Constants.from_contract_transaction(transaction, contract_version),
:time_now => DateTime.to_unix(datetime),
:functions => functions
}
Expand All @@ -374,7 +374,7 @@ defmodule Archethic.Contracts do
) do
%{
"transaction" => Constants.from_transaction(transaction, contract_version),
"contract" => Constants.from_contract(contract_tx, contract_version),
"contract" => Constants.from_contract_transaction(contract_tx, contract_version),
:time_now => DateTime.to_unix(datetime),
:functions => functions
}
Expand Down
7 changes: 5 additions & 2 deletions lib/archethic/contracts/contract/constants.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ defmodule Archethic.Contracts.ContractConstants do
@doc """
Same as from_transaction but remove the contract_seed from ownerships
"""
@spec from_contract(contract_tx :: Transaction.t(), contract_version :: non_neg_integer()) ::
@spec from_contract_transaction(
contract_tx :: Transaction.t(),
contract_version :: non_neg_integer()
) ::
map()
def from_contract(contract_tx, contract_version \\ 1),
def from_contract_transaction(contract_tx, contract_version \\ 1),
do: contract_tx |> Contract.remove_seed_ownership() |> from_transaction(contract_version)

@doc """
Expand Down
2 changes: 1 addition & 1 deletion lib/archethic/contracts/interpreter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ defmodule Archethic.Contracts.Interpreter do
trigger_tx -> Constants.from_transaction(trigger_tx, version)
end

contract_constants = Constants.from_contract(contract_tx, version)
contract_constants = Constants.from_contract_transaction(contract_tx, version)

constants =
named_action_constants
Expand Down
3 changes: 2 additions & 1 deletion test/archethic/contracts/contract/constants_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ defmodule Archethic.Contracts.ContractConstantsTest do

assert length(contract_tx.data.ownerships) == 2

assert %{"ownerships" => [^ownership_hex]} = ContractConstants.from_contract(contract_tx)
assert %{"ownerships" => [^ownership_hex]} =
ContractConstants.from_contract_transaction(contract_tx)
end
end
end
48 changes: 24 additions & 24 deletions test/archethic/contracts/interpreter/condition_validator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ defmodule Archethic.Contracts.Interpreter.ConditionValidatorTest do
|> ConditionInterpreter.parse([])
|> elem(2)
|> ConditionValidator.valid_conditions?(%{
"previous" => Constants.from_contract(previous_tx),
"next" => Constants.from_contract(next_tx)
"previous" => Constants.from_contract_transaction(previous_tx),
"next" => Constants.from_contract_transaction(next_tx)
})
end

Expand Down Expand Up @@ -91,8 +91,8 @@ defmodule Archethic.Contracts.Interpreter.ConditionValidatorTest do
|> ConditionInterpreter.parse([])
|> elem(2)
|> ConditionValidator.valid_conditions?(%{
"previous" => Constants.from_contract(previous_tx),
"next" => Constants.from_contract(next_tx)
"previous" => Constants.from_contract_transaction(previous_tx),
"next" => Constants.from_contract_transaction(next_tx)
})
end

Expand All @@ -110,8 +110,8 @@ defmodule Archethic.Contracts.Interpreter.ConditionValidatorTest do
|> ConditionInterpreter.parse([])
|> elem(2)
|> ConditionValidator.valid_conditions?(%{
"previous" => Constants.from_contract(previous_tx),
"next" => Constants.from_contract(next_tx)
"previous" => Constants.from_contract_transaction(previous_tx),
"next" => Constants.from_contract_transaction(next_tx)
})
end

Expand Down Expand Up @@ -140,8 +140,8 @@ defmodule Archethic.Contracts.Interpreter.ConditionValidatorTest do
|> ConditionInterpreter.parse([])
|> elem(2)
|> ConditionValidator.valid_conditions?(%{
"previous" => Constants.from_contract(previous_tx),
"next" => Constants.from_contract(next_tx)
"previous" => Constants.from_contract_transaction(previous_tx),
"next" => Constants.from_contract_transaction(next_tx)
})

code = ~s"""
Expand All @@ -156,8 +156,8 @@ defmodule Archethic.Contracts.Interpreter.ConditionValidatorTest do
|> ConditionInterpreter.parse([])
|> elem(2)
|> ConditionValidator.valid_conditions?(%{
"previous" => Constants.from_contract(previous_tx),
"next" => Constants.from_contract(next_tx)
"previous" => Constants.from_contract_transaction(previous_tx),
"next" => Constants.from_contract_transaction(next_tx)
})
end

Expand Down Expand Up @@ -294,8 +294,8 @@ defmodule Archethic.Contracts.Interpreter.ConditionValidatorTest do
|> ConditionInterpreter.parse([])
|> elem(2)
|> ConditionValidator.valid_conditions?(%{
"previous" => Constants.from_contract(previous_tx),
"next" => Constants.from_contract(next_tx)
"previous" => Constants.from_contract_transaction(previous_tx),
"next" => Constants.from_contract_transaction(next_tx)
})

code = ~s"""
Expand All @@ -313,8 +313,8 @@ defmodule Archethic.Contracts.Interpreter.ConditionValidatorTest do
|> ConditionInterpreter.parse([])
|> elem(2)
|> ConditionValidator.valid_conditions?(%{
"previous" => Constants.from_contract(previous_tx),
"next" => Constants.from_contract(next_tx)
"previous" => Constants.from_contract_transaction(previous_tx),
"next" => Constants.from_contract_transaction(next_tx)
})
end

Expand All @@ -334,8 +334,8 @@ defmodule Archethic.Contracts.Interpreter.ConditionValidatorTest do
|> ConditionInterpreter.parse([])
|> elem(2)
|> ConditionValidator.valid_conditions?(%{
"previous" => Constants.from_contract(previous_tx),
"next" => Constants.from_contract(next_tx)
"previous" => Constants.from_contract_transaction(previous_tx),
"next" => Constants.from_contract_transaction(next_tx)
})

code = ~s"""
Expand All @@ -353,8 +353,8 @@ defmodule Archethic.Contracts.Interpreter.ConditionValidatorTest do
|> ConditionInterpreter.parse([])
|> elem(2)
|> ConditionValidator.valid_conditions?(%{
"previous" => Constants.from_contract(previous_tx),
"next" => Constants.from_contract(next_tx)
"previous" => Constants.from_contract_transaction(previous_tx),
"next" => Constants.from_contract_transaction(next_tx)
})

code = ~s"""
Expand All @@ -372,8 +372,8 @@ defmodule Archethic.Contracts.Interpreter.ConditionValidatorTest do
|> ConditionInterpreter.parse([])
|> elem(2)
|> ConditionValidator.valid_conditions?(%{
"previous" => Constants.from_contract(previous_tx),
"next" => Constants.from_contract(next_tx)
"previous" => Constants.from_contract_transaction(previous_tx),
"next" => Constants.from_contract_transaction(next_tx)
})
end

Expand All @@ -396,8 +396,8 @@ defmodule Archethic.Contracts.Interpreter.ConditionValidatorTest do
|> ConditionInterpreter.parse([])
|> elem(2)
|> ConditionValidator.valid_conditions?(%{
"previous" => Constants.from_contract(previous_tx),
"next" => Constants.from_contract(next_tx)
"previous" => Constants.from_contract_transaction(previous_tx),
"next" => Constants.from_contract_transaction(next_tx)
})
end

Expand Down Expand Up @@ -439,8 +439,8 @@ defmodule Archethic.Contracts.Interpreter.ConditionValidatorTest do
|> ConditionInterpreter.parse([])
|> elem(2)
|> ConditionValidator.valid_conditions?(%{
"previous" => Constants.from_contract(previous_tx),
"next" => Constants.from_contract(next_tx)
"previous" => Constants.from_contract_transaction(previous_tx),
"next" => Constants.from_contract_transaction(next_tx)
})
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/support/contract_factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ defmodule Archethic.ContractFactory do
if Map.has_key?(constants, "contract") do
constants
else
Map.put(constants, "contract", Constants.from_contract(contract_tx))
Map.put(constants, "contract", Constants.from_contract_transaction(contract_tx))
end
end
end

0 comments on commit b4fc4e0

Please sign in to comment.