Skip to content

Commit

Permalink
Use a function to determine the minimum granularity of trigger 'inter…
Browse files Browse the repository at this point in the history
…val'
  • Loading branch information
bchamagne committed Apr 27, 2023
1 parent f2aa663 commit b6ea2b1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
13 changes: 13 additions & 0 deletions lib/archethic/contracts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ defmodule Archethic.Contracts do

@extended_mode? Mix.env() != :prod

@doc """
Return the minimum interval in milliseconds.
Depends on the env
"""
@spec minimum_interval() :: pos_integer()
def minimum_interval() do
if @extended_mode? do
1000
else
60_000
end
end

@doc """
Parse a smart contract code and return a contract struct
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule Archethic.Utils.Regression.Playbook.SmartContract.Faucet do
with some UCOs to all callers
"""

alias Archethic.Contracts
alias Archethic.TransactionChain.TransactionData
alias Archethic.Utils
alias Archethic.Utils.Regression.Playbook.SmartContract
Expand Down Expand Up @@ -44,9 +45,10 @@ defmodule Archethic.Utils.Regression.Playbook.SmartContract.Faucet do
trigger2_tx = SmartContract.trigger(trigger2_seed, contract_address, host, port)
trigger3_tx = SmartContract.trigger(trigger3_seed, contract_address, host, port)

# wait for the tick (5s + delta)
Logger.debug("Sleeping for 1 tick (5 seconds)")
Process.sleep(200 + 5000)
# wait for the tick (+ delta)
sleep_time = 200 + Contracts.minimum_interval()
Logger.debug("Sleeping for 1 tick (#{div(sleep_time, 1000)} seconds)")
Process.sleep(sleep_time)

expected_balance = Utils.to_bigint(5)
balance1 = SmartContract.get_balance(trigger1_tx, host, port)
Expand Down Expand Up @@ -74,7 +76,7 @@ defmodule Archethic.Utils.Regression.Playbook.SmartContract.Faucet do
content: true
]
actions triggered_by: interval, at: "*/5 * * * *" do
actions triggered_by: interval, at: "* * * * *" do
now = Time.now()
faucet_delay = 60 * 60
calls = Contract.get_calls()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule Archethic.Utils.Regression.Playbook.SmartContract.Legacy do
It should send 0.1 UCO to the recipient chain every tick
"""

alias Archethic.Contracts
alias Archethic.TransactionChain.TransactionData
alias Archethic.Utils.Regression.Playbook.SmartContract

Expand All @@ -28,8 +29,9 @@ defmodule Archethic.Utils.Regression.Playbook.SmartContract.Legacy do
)

# wait some ticks (+ a little delta)
Logger.debug("Sleeping for #{ticks_count} ticks (#{ticks_count} seconds)")
Process.sleep(200 + ticks_count * 1000)
sleep_time = 200 + ticks_count * Contracts.minimum_interval()
Logger.debug("Sleeping for #{ticks_count} ticks (#{div(sleep_time, 1000)} seconds)")
Process.sleep(sleep_time)

balance = SmartContract.get_balance(recipient_address, host, port)
expected_balance = ticks_count * amount_to_send
Expand Down

0 comments on commit b6ea2b1

Please sign in to comment.