Skip to content

Commit

Permalink
Catch condition execution error
Browse files Browse the repository at this point in the history
  • Loading branch information
Neylix committed Jul 26, 2023
1 parent 3fbdec7 commit 2e88853
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/archethic/contracts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ defmodule Archethic.Contracts do
constants = get_condition_constants(condition_type, contract, transaction, datetime)
Interpreter.valid_conditions?(version, condition, constants)
end
rescue
_ ->
false
end

defp validate_trigger({:datetime, datetime}, validation_datetime, _contract_address) do
Expand Down
34 changes: 34 additions & 0 deletions test/archethic/contracts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,40 @@ defmodule Archethic.ContractsTest do
DateTime.utc_now()
)
end

test "should return false if condition execution raise an error" do
code = """
@version 1
condition transaction: [
type: 1 + "one"
]
actions triggered_by: transaction do
Contract.set_content "hello"
end
"""

contract_tx = %Transaction{
address: random_address(),
data: %TransactionData{
code: code
}
}

trigger_tx = %Transaction{
type: :transfer,
address: random_address(),
data: %TransactionData{},
validation_stamp: ValidationStamp.generate_dummy()
}

refute Contracts.valid_condition?(
:transaction,
Contract.from_transaction!(contract_tx),
trigger_tx,
DateTime.utc_now()
)
end
end

describe "valid_condition?/4 (oracle)" do
Expand Down

0 comments on commit 2e88853

Please sign in to comment.