cleveland-0.2.1: test/TestSuite/Cleveland/Emulated.hs
-- SPDX-FileCopyrightText: 2021 Oxhead Alpha
-- SPDX-License-Identifier: LicenseRef-MIT-OA
module TestSuite.Cleveland.Emulated
( test_Emulated
) where
import Test.Tasty (TestTree, testGroup)
import Morley.Tezos.Address
import Test.Cleveland
import TestSuite.Util (shouldFailWithMessage)
test_Emulated :: [TestTree]
test_Emulated =
[ testGroup "branchout"
[ testScenarioOnEmulator "passes if all branches pass" $ scenarioEmulated $
branchout
[ "a" ?- pass
, "b" ?- pass
]
, testScenarioOnEmulator "fails if any branch fails" $ scenarioEmulated do
addr <- newAddress auto
let branchA = "a" ?- transfer addr [tz|0u|]
let branchB = "b" ?- pass
branchout [branchA, branchB] & expectTransferFailure emptyTransaction
branchout [branchB, branchA] & expectTransferFailure emptyTransaction
, testScenarioOnEmulator "a branch's effects do not leak into another branch" $ scenarioEmulated do
test <- newAddress auto
initialBalance <- getBalance test
branchout
[ "a" ?- do
transfer test [tz|2u|]
getBalance test @@== initialBalance + 2
, "b" ?- do
transfer test [tz|3u|]
getBalance test @@== initialBalance + 3
]
, testScenarioOnEmulator "branchout's effects are discarded" $ scenarioEmulated do
test <- newAddress auto
initialBalance <- getBalance test
branchout
[ "a" ?- transfer test [tz|3u|] ]
getBalance test @@== initialBalance
, testScenarioOnEmulator "adds branch name to error" $ scenarioEmulated do
branchout
[ "<branch name>" ?- void $
signBytes "" [ta|tz1Zpj6cNhkVkvksGtRTwTrgfCG3WP9eA5BM|]
]
& shouldFailWithMessage "<branch name>"
]
, testGroup "offshoot"
[ testScenarioOnEmulator "fails if inner scenario fails" $ scenarioEmulated do
addr <- newAddress auto
offshoot "a" (transfer addr [tz|0u|])
& expectTransferFailure emptyTransaction
, testScenarioOnEmulator "offshoot's effects are discarded" $ scenarioEmulated do
test <- newAddress auto
initialBalance <- getBalance test
offshoot "a" $ transfer test [tz|1u|]
getBalance test @@== initialBalance
]
]