Skip to content

Commit

Permalink
Scenario: Test ArithemticError (#9757)
Browse files Browse the repository at this point in the history
Two integration-type tests:

- An uncaught arithmetic error
- A caught arithmetic error

This is part of #8020

CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
remyhaemmerle-da authored May 25, 2021
1 parent ad529e9 commit 8ef9361
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 77 deletions.
4 changes: 2 additions & 2 deletions compiler/damlc/tests/daml-test-files/AuthEvalOrder.daml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ template TheContract
-- In the well-authorized t1, execution reaches the `error` function
-- In the badly-authorized t2, the auth failure prevent the error from being reached.

-- @ERROR Aborted: t1 finished with no authorization failure
-- @ERROR t1 finished with no authorization failure
t1_create_success = scenario do
ivy <- getParty "Ivy-t1"
submit ivy $ do
Expand Down Expand Up @@ -44,7 +44,7 @@ template TheContractBuilder
-- It is the 2nd submit which is of interest here, where mach exercises the `builder` contract created in the first submit, to contract signed by Ivy. This is possible in t3 because `builder` is signed by Ivy, but it is not well authorized in t4.
-- Only in the well-authorized case will execution reach the `error` function.

-- @ERROR Aborted: t3 finished with no authorization failure
-- @ERROR t3 finished with no authorization failure
t3_createViaExerice_success = scenario do
ivy <- getParty "Ivy-t3"
mach <- getParty "Mach-t3"
Expand Down
2 changes: 1 addition & 1 deletion compiler/damlc/tests/daml-test-files/CallStack.daml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- @ERROR Aborted: CallStack (from HasCallStack):
-- @ERROR CallStack (from HasCallStack):
module CallStack where

-- Main test case is in the Shake test suite. This just makes sure
Expand Down
45 changes: 41 additions & 4 deletions compiler/damlc/tests/daml-test-files/ExceptionSemantics.daml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
-- SPDX-License-Identifier: Apache-2.0

-- @SINCE-LF-FEATURE DAML_EXCEPTIONS
-- @ERROR range=145:1-145:11; Attempt to exercise a consumed contract
-- @ERROR range=130:1-130:23; Unhandled exception: ExceptionSemantics:E
-- @ERROR range=145:1-145:25; Unhandled exception: ArithmeticError while evaluating (DIV_INT64 1 0).
-- @ERROR range=182:1-182:11; Attempt to exercise a consumed contract
module ExceptionSemantics where

import DA.Exception (throw)
import DA.Exception
import DA.Assert ((===))

exception E
where
Expand Down Expand Up @@ -34,6 +37,15 @@ template T
catch
E -> pure ()

nonconsuming choice ThrowArithmeticError : Int
controller p
do pure (1/0)
nonconsuming choice CatchArithmeticError : Int
controller p
do try (exercise self ThrowArithmeticError)
catch
(_: ArithmeticError) -> pure 42

nonconsuming choice UncatchableTry : ()
with
cid : ContractId K
Expand Down Expand Up @@ -110,11 +122,36 @@ template Fetcher
catch
E -> pure ()

unhandledException = scenario do
uncaughtUserException = scenario do
p <- getParty "p"
_ <- submitMustFail p $ createAndExercise (T p) Throw
pure ()

unhandledUserException = scenario do
p <- getParty "p"
_ <- submit p $ createAndExercise (T p) Throw
pure ()

handledUserException = scenario do
p <- getParty "p"
submitMustFail p $ createAndExercise (T p) Throw
_ <- submit p $ createAndExercise (T p) Catch
pure ()

uncaughtArithmeticError = scenario do
p <- getParty "p"
_ <- submitMustFail p $ createAndExercise (T p) ThrowArithmeticError
pure ()

unhandledArithmeticError = scenario do
p <- getParty "p"
_ <- submit p $ createAndExercise (T p) ThrowArithmeticError
pure ()

handledArithmeticError = scenario do
p <- getParty "p"
r <- submit p $ createAndExercise (T p) CatchArithmeticError
r === 42

duplicateKey = scenario do
p <- getParty "p"
-- transient duplicate key in rollback
Expand Down
Loading

0 comments on commit 8ef9361

Please sign in to comment.