Safe Haskell | None |
---|---|
Language | Haskell2010 |
Utilities for integrational testing. Example tests can be found in the 'morley-test' test suite.
Synopsis
- data TxData = TxData {}
- genesisAddress :: Address
- genesisAddress1 :: Address
- genesisAddress2 :: Address
- genesisAddress3 :: Address
- genesisAddress4 :: Address
- genesisAddress5 :: Address
- genesisAddress6 :: Address
- type IntegrationalScenarioM = StateT InternalState (Except ScenarioError)
- type IntegrationalScenario = IntegrationalScenarioM ()
- data TestError
- = InterpreterError IntegrationalExecutorError
- | UnexpectedInterpreterError Text IntegrationalExecutorError
- | UnexpectedTypeCheckError TCError
- | ExpectingInterpreterToFail
- | IncorrectUpdates TestError [GStateUpdate]
- | IncorrectStorageUpdate AddressName Text
- | InvalidStorage AddressName ExpectedStorage Text
- | StoragePredicateMismatch AddressName Text
- | InvalidBalance AddressName ExpectedBalance Text
- | UnexpectedUpdates (NonEmpty GStateUpdate)
- | ValidatingEmptyScenario
- | CustomTestError Text
- integrationalTestExpectation :: HasCallStack => IntegrationalScenario -> Expectation
- integrationalTestProp :: MonadTest m => IntegrationalScenario -> m ()
- originate :: Contract -> Text -> Value -> Mutez -> IntegrationalScenarioM Address
- tOriginate :: (ParameterScope cp, StorageScope st) => Contract cp st -> Text -> Value st -> Mutez -> IntegrationalScenarioM Address
- transfer :: TxData -> Address -> IntegrationalScenarioM ()
- tTransfer :: forall arg. ParameterScope arg => ("from" :! Address) -> ("to" :! Address) -> Mutez -> EpName -> Value arg -> IntegrationalScenarioM ()
- integrationalFail :: TestError -> IntegrationalScenarioM anything
- unexpectedInterpreterError :: ExecutorError -> Text -> IntegrationalScenarioM a
- setMaxSteps :: RemainingSteps -> IntegrationalScenarioM ()
- modifyNow :: (Timestamp -> Timestamp) -> IntegrationalScenarioM ()
- setNow :: Timestamp -> IntegrationalScenarioM ()
- rewindTime :: Integer -> IntegrationalScenarioM ()
- withSender :: Address -> IntegrationalScenarioM a -> IntegrationalScenarioM a
- setChainId :: ChainId -> IntegrationalScenarioM ()
- branchout :: HasCallStack => [(Text, IntegrationalScenario)] -> IntegrationalScenario
- (?-) :: Text -> a -> (Text, a)
- offshoot :: Text -> IntegrationalScenario -> IntegrationalScenario
- expectNoUpdates :: IntegrationalScenario
- expectNoStorageUpdates :: IntegrationalScenario
- expectStorageUpdate :: Address -> (Value -> Either TestError ()) -> IntegrationalScenario
- expectStorageUpdateConst :: Address -> Value -> IntegrationalScenario
- expectBalance :: Address -> Mutez -> IntegrationalScenario
- expectStorage :: Address -> (Value -> Either TestError ()) -> IntegrationalScenario
- expectStorageConst :: Address -> Value -> IntegrationalScenario
- tExpectStorageConst :: forall st. StorageScope st => Address -> Value st -> IntegrationalScenario
- attempt :: IntegrationalScenarioM a -> IntegrationalScenarioM (Either ExecutorError a)
- expectError :: IntegrationalScenarioM a -> IntegrationalScenarioM ExecutorError
- catchExpectedError :: IntegrationalScenarioM a -> (ExecutorError -> IntegrationalScenarioM b) -> IntegrationalScenarioM b
- expectGasExhaustion :: ExecutorError -> IntegrationalScenario
- expectMichelsonFailed :: (MichelsonFailed -> Bool) -> Address -> ExecutorError -> IntegrationalScenario
- isGState :: Lens' InternalState GState
- integrationalTestProperty :: IntegrationalScenario -> Property
Re-exports
Data associated with a particular transaction.
TxData | |
|
More genesis addresses which can be used in tests
genesisAddress :: Address Source #
One of genesis addresses.
genesisAddress1 :: Address Source #
More genesis addresses
We know size of genesisAddresses
, so it is safe to use !!
genesisAddress2 :: Address Source #
More genesis addresses
We know size of genesisAddresses
, so it is safe to use !!
genesisAddress3 :: Address Source #
More genesis addresses
We know size of genesisAddresses
, so it is safe to use !!
Testing engine
type IntegrationalScenarioM = StateT InternalState (Except ScenarioError) Source #
A monad inside which integrational tests can be described using do-notation.
type IntegrationalScenario = IntegrationalScenarioM () Source #
InterpreterError IntegrationalExecutorError | |
UnexpectedInterpreterError Text IntegrationalExecutorError | |
UnexpectedTypeCheckError TCError | |
ExpectingInterpreterToFail | |
IncorrectUpdates TestError [GStateUpdate] | |
IncorrectStorageUpdate AddressName Text | |
InvalidStorage AddressName ExpectedStorage Text | |
StoragePredicateMismatch AddressName Text | |
InvalidBalance AddressName ExpectedBalance Text | |
UnexpectedUpdates (NonEmpty GStateUpdate) | |
ValidatingEmptyScenario | |
CustomTestError Text |
Instances
Show TestError Source # | |
Exception TestError Source # | |
Defined in Michelson.Test.Integrational toException :: TestError -> SomeException # fromException :: SomeException -> Maybe TestError # displayException :: TestError -> String # | |
Buildable TestError Source # | |
Defined in Michelson.Test.Integrational |
integrationalTestExpectation :: HasCallStack => IntegrationalScenario -> Expectation Source #
Integrational test that executes given operations and validates
them. It can fail using Expectation
capability.
It starts with initGState
and some reasonable dummy values for
gas limit and current timestamp. You can update blockchain state
by performing some operations.
integrationalTestProp :: MonadTest m => IntegrationalScenario -> m () Source #
Integrational test similar to integrationalTestExpectation
.
It can fail using Property
capability.
It can be used with Hedgehog's forAll
to make a
property-based test with arbitrary data.
originate :: Contract -> Text -> Value -> Mutez -> IntegrationalScenarioM Address Source #
Originate a contract with given initial storage and balance. Its address is returned.
tOriginate :: (ParameterScope cp, StorageScope st) => Contract cp st -> Text -> Value st -> Mutez -> IntegrationalScenarioM Address Source #
Like originate
, but for typed contract and value.
transfer :: TxData -> Address -> IntegrationalScenarioM () Source #
Transfer tokens to a given address.
tTransfer :: forall arg. ParameterScope arg => ("from" :! Address) -> ("to" :! Address) -> Mutez -> EpName -> Value arg -> IntegrationalScenarioM () Source #
Similar to transfer
, for typed values.
Note that it works with untyped Address
and does not check that
entrypoint with given name is present and has the expected type.
Passed value must correspond to the entrypoint argument type, not
the parameter type of the contract (and must be unit for implicit
accounts).
integrationalFail :: TestError -> IntegrationalScenarioM anything Source #
Just fail with given error.
unexpectedInterpreterError :: ExecutorError -> Text -> IntegrationalScenarioM a Source #
Fail a test because an interpreter error happened unexpectedly, with the given reason.
setMaxSteps :: RemainingSteps -> IntegrationalScenarioM () Source #
Make all further interpreter calls use the given gas limit.
modifyNow :: (Timestamp -> Timestamp) -> IntegrationalScenarioM () Source #
Make all further interpreter calls use the modified timestamp as the current one.
setNow :: Timestamp -> IntegrationalScenarioM () Source #
Make all further interpreter calls use the given timestamp as the current one.
rewindTime :: Integer -> IntegrationalScenarioM () Source #
Increase current time by the given number of seconds.
withSender :: Address -> IntegrationalScenarioM a -> IntegrationalScenarioM a Source #
Pretend that given address initiates all the transfers within the
code block (i.e. SENDER
instruction will return this address).
setChainId :: ChainId -> IntegrationalScenarioM () Source #
Make all further interpreter calls use the given chain id.
branchout :: HasCallStack => [(Text, IntegrationalScenario)] -> IntegrationalScenario Source #
Execute multiple testing scenarios independently, basing them on scenario built till this point.
The following property holds for this function:
pre >> branchout [a, b, c] = branchout [pre >> a, pre >> b, pre >> c]
.
In case of property failure in one of the branches no following branch is executed.
Providing empty list of scenarios to this function causes error;
we do not require NonEmpty
here though for convenience.
(?-) :: Text -> a -> (Text, a) infixr 0 Source #
Make a tuple with name without extra syntactic noise.
offshoot :: Text -> IntegrationalScenario -> IntegrationalScenario Source #
Test given scenario with the state gathered till this moment; if this scenario passes, go on as if it never happened.
Validators
expectNoUpdates :: IntegrationalScenario Source #
Check that there were no updates.
expectNoStorageUpdates :: IntegrationalScenario Source #
Check that there were no storage updates.
expectStorageUpdate :: Address -> (Value -> Either TestError ()) -> IntegrationalScenario Source #
Check that storage value is updated for given address. Takes a predicate that is used to check the value.
It works even if updates are not filtered (i. e. a value can be updated more than once).
expectStorageUpdateConst :: Address -> Value -> IntegrationalScenario Source #
Like expectStorageUpdate
, but expects a constant.
expectBalance :: Address -> Mutez -> IntegrationalScenario Source #
Check that eventually address has some particular balance.
expectStorage :: Address -> (Value -> Either TestError ()) -> IntegrationalScenario Source #
Check that storage value satisfies the given predicate.
expectStorageConst :: Address -> Value -> IntegrationalScenario Source #
Check that eventually address has some particular storage value.
tExpectStorageConst :: forall st. StorageScope st => Address -> Value st -> IntegrationalScenario Source #
Similar to expectStorageConst
, for typed stuff.
Errors
attempt :: IntegrationalScenarioM a -> IntegrationalScenarioM (Either ExecutorError a) Source #
Attempt to run an action and return its result or, if interpretation fails, an error.
expectError :: IntegrationalScenarioM a -> IntegrationalScenarioM ExecutorError Source #
Run an action that is expected to fail. If the action fails, the test succeeds and the error is returned. If the action succeeds, the test fails.
catchExpectedError :: IntegrationalScenarioM a -> (ExecutorError -> IntegrationalScenarioM b) -> IntegrationalScenarioM b Source #
Run an action that is expected to fail.
In action
:
If the action fails, catchExpectedError
ff
is applied to the error.
If the action succeeds, the test fails.
expectGasExhaustion :: ExecutorError -> IntegrationalScenario Source #
Check that interpreter failed due to gas exhaustion.
expectMichelsonFailed :: (MichelsonFailed -> Bool) -> Address -> ExecutorError -> IntegrationalScenario Source #
Expect that interpretation of contract with given address ended with [FAILED].
Lenses
Deprecated
integrationalTestProperty :: IntegrationalScenario -> Property Source #
Deprecated: Use integrationalTestProp
instead.
Integrational test similar to integrationalTestExpectation
.
It can fail using Property
capability.
It can be used with QuickCheck's forAll
to make a
property-based test with arbitrary data.