Safe Haskell | None |
---|---|
Language | Haskell2010 |
Utilities for integrational testing. Example tests can be found in the 'morley-test' test suite.
Synopsis
- data TxData = TxData {
- tdSenderAddress :: !Address
- tdParameter :: !UntypedValue
- tdAmount :: !Mutez
- type IntegrationalValidator = Either (InterpreterError -> Bool) SuccessValidator
- type SuccessValidator = GState -> [GStateUpdate] -> Either Text ()
- type IntegrationalScenario = IntegrationalScenarioM Validated
- integrationalTestExpectation :: IntegrationalScenario -> Expectation
- integrationalTestProperty :: IntegrationalScenario -> Property
- originate :: UntypedContract -> UntypedValue -> Mutez -> IntegrationalScenarioM Address
- transfer :: TxData -> Address -> IntegrationalScenarioM ()
- validate :: IntegrationalValidator -> IntegrationalScenario
- setMaxSteps :: RemainingSteps -> IntegrationalScenarioM ()
- setNow :: Timestamp -> IntegrationalScenarioM ()
- composeValidators :: SuccessValidator -> SuccessValidator -> SuccessValidator
- composeValidatorsList :: [SuccessValidator] -> SuccessValidator
- expectAnySuccess :: SuccessValidator
- expectStorageUpdate :: Address -> (UntypedValue -> Either Text ()) -> SuccessValidator
- expectStorageUpdateConst :: Address -> UntypedValue -> SuccessValidator
- expectBalance :: Address -> Mutez -> SuccessValidator
- expectStorageConst :: Address -> UntypedValue -> SuccessValidator
- expectGasExhaustion :: InterpreterError -> Bool
- expectMichelsonFailed :: Address -> InterpreterError -> Bool
Re-exports
Data associated with a particular transaction.
TxData | |
|
Testing engine
type IntegrationalValidator = Either (InterpreterError -> Bool) SuccessValidator Source #
Validator for integrational testing.
If an error is expected, it should be Left
with validator for errors.
Otherwise it should check final global state and its updates.
type SuccessValidator = GState -> [GStateUpdate] -> Either Text () Source #
Validator for integrational testing that expects successful execution.
type IntegrationalScenario = IntegrationalScenarioM Validated Source #
integrationalTestExpectation :: IntegrationalScenario -> Expectation Source #
Integrational test that executes given operations and validates
them using given validator. 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.
integrationalTestProperty :: IntegrationalScenario -> Property Source #
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.
originate :: UntypedContract -> UntypedValue -> Mutez -> IntegrationalScenarioM Address Source #
Originate a contract with given initial storage and balance. Its address is returned.
transfer :: TxData -> Address -> IntegrationalScenarioM () Source #
Transfer tokens to given address.
validate :: IntegrationalValidator -> IntegrationalScenario Source #
Execute all operations that were added to the scenarion since
last validate
call. If validator fails, the execution will be aborted.
setMaxSteps :: RemainingSteps -> IntegrationalScenarioM () Source #
Make all further interpreter calls (which are triggered by the
validate
function) use given gas limit.
setNow :: Timestamp -> IntegrationalScenarioM () Source #
Make all further interpreter calls (which are triggered by the
validate
function) use given timestamp as the current one.
Validators
composeValidators :: SuccessValidator -> SuccessValidator -> SuccessValidator Source #
Compose two success validators.
For example:
expectBalance bal addr composeValidators
expectStorageUpdateConst addr2 ValueUnit
composeValidatorsList :: [SuccessValidator] -> SuccessValidator Source #
Compose a list of success validators.
expectAnySuccess :: SuccessValidator Source #
SuccessValidator
that always passes.
expectStorageUpdate :: Address -> (UntypedValue -> Either Text ()) -> SuccessValidator 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 -> UntypedValue -> SuccessValidator Source #
Like expectStorageUpdate
, but expects a constant.
expectBalance :: Address -> Mutez -> SuccessValidator Source #
Check that eventually address has some particular balance.
expectStorageConst :: Address -> UntypedValue -> SuccessValidator Source #
Check that eventually address has some particular storage value.
expectGasExhaustion :: InterpreterError -> Bool Source #
Check that interpreter failed due to gas exhaustion.
expectMichelsonFailed :: Address -> InterpreterError -> Bool Source #
Expect that interpretation of contract with given address ended with [FAILED].