Safe Haskell | None |
---|---|
Language | Haskell2010 |
Mirrors Integrational
module in a Lorentz way.
Synopsis
- data TxData = TxData {
- tdSenderAddress :: !Address
- tdParameter :: !Value
- tdAmount :: !Mutez
- genesisAddresses :: NonEmpty Address
- genesisAddress :: Address
- genesisAddress1 :: Address
- genesisAddress2 :: Address
- genesisAddress3 :: Address
- genesisAddress4 :: Address
- genesisAddress5 :: Address
- genesisAddress6 :: Address
- type IntegrationalValidator = Either (InterpreterError -> Bool) SuccessValidator
- type SuccessValidator = InternalState -> GState -> [GStateUpdate] -> Either ValidationError ()
- type IntegrationalScenarioM = StateT InternalState (Except ValidationError)
- type IntegrationalScenario = IntegrationalScenarioM Validated
- data ValidationError
- = UnexpectedInterpreterError IntegrationalInterpreterError
- | UnexpectedTypeCheckError TCError
- | ExpectingInterpreterToFail
- | IncorrectUpdates ValidationError [GStateUpdate]
- | IncorrectStorageUpdate AddressName Text
- | InvalidStorage AddressName ExpectedStorage Text
- | InvalidBalance AddressName ExpectedBalance Text
- | CustomError Text
- integrationalTestExpectation :: IntegrationalScenario -> Expectation
- integrationalTestProperty :: IntegrationalScenario -> Property
- lOriginate :: (SingI (ToT cp), SingI (ToT st), HasNoOp (ToT st), IsoValue st) => Contract cp st -> Text -> st -> Mutez -> IntegrationalScenarioM (ContractAddr cp)
- lOriginateEmpty :: (SingI (ToT cp), SingI (ToT st), HasNoOp (ToT st), IsoValue st, Default st) => Contract cp st -> Text -> IntegrationalScenarioM (ContractAddr cp)
- lTransfer :: (SingI (ToT cp), HasNoOp (ToT cp), IsoValue cp) => ("from" :! Address) -> ("to" :! ContractAddr cp) -> Mutez -> cp -> IntegrationalScenarioM ()
- lCall :: (SingI (ToT cp), HasNoOp (ToT cp), IsoValue cp) => ContractAddr cp -> cp -> IntegrationalScenarioM ()
- validate :: IntegrationalValidator -> IntegrationalScenario
- setMaxSteps :: RemainingSteps -> IntegrationalScenarioM ()
- setNow :: Timestamp -> IntegrationalScenarioM ()
- withSender :: Address -> IntegrationalScenarioM a -> IntegrationalScenarioM a
- composeValidators :: SuccessValidator -> SuccessValidator -> SuccessValidator
- composeValidatorsList :: [SuccessValidator] -> SuccessValidator
- expectAnySuccess :: SuccessValidator
- lExpectStorageUpdate :: (IsoValue st, Each [Typeable, SingI, HasNoOp] '[ToT st], HasCallStack) => ContractAddr cp -> (st -> Either ValidationError ()) -> SuccessValidator
- lExpectBalance :: ContractAddr cp -> Mutez -> SuccessValidator
- lExpectStorageConst :: (IsoValue st, Each '[SingI, HasNoOp] '[ToT st]) => ContractAddr cp -> st -> SuccessValidator
- lExpectMichelsonFailed :: (MichelsonFailed -> Bool) -> ContractAddr cp -> InterpreterError -> Bool
- lExpectFailWith :: forall e. (Typeable (ToT e), IsoValue e) => (e -> Bool) -> InterpreterError -> Bool
- lExpectUserError :: forall e. (Typeable (ToT e), IsoValue e) => (e -> Bool) -> InterpreterError -> Bool
- lExpectConsumerStorage :: (st ~ [cp], IsoValue st, Each [Typeable, SingI, HasNoOp] '[ToT st]) => ContractAddr cp -> (st -> Either ValidationError ()) -> SuccessValidator
- lExpectViewConsumerStorage :: (st ~ [cp], cp ~ (arg, Maybe res), Eq res, Buildable res, IsoValue st, Each [Typeable, SingI, HasNoOp] '[ToT st]) => ContractAddr cp -> [res] -> SuccessValidator
Re-exports
Data associated with a particular transaction.
TxData | |
|
genesisAddresses :: NonEmpty Address Source #
Initially these addresses have a lot of money.
genesisAddress :: Address Source #
One of genesis addresses.
More genesis addresses which can be used in tests
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 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 = InternalState -> GState -> [GStateUpdate] -> Either ValidationError () Source #
Validator for integrational testing that expects successful execution.
type IntegrationalScenarioM = StateT InternalState (Except ValidationError) Source #
A monad inside which integrational tests can be described using do-notation.
type IntegrationalScenario = IntegrationalScenarioM Validated Source #
data ValidationError Source #
UnexpectedInterpreterError IntegrationalInterpreterError | |
UnexpectedTypeCheckError TCError | |
ExpectingInterpreterToFail | |
IncorrectUpdates ValidationError [GStateUpdate] | |
IncorrectStorageUpdate AddressName Text | |
InvalidStorage AddressName ExpectedStorage Text | |
InvalidBalance AddressName ExpectedBalance Text | |
CustomError Text |
Instances
Show ValidationError Source # | |
Defined in Michelson.Test.Integrational showsPrec :: Int -> ValidationError -> ShowS # show :: ValidationError -> String # showList :: [ValidationError] -> ShowS # | |
Exception ValidationError Source # | |
Defined in Michelson.Test.Integrational | |
Buildable ValidationError Source # | |
Defined in Michelson.Test.Integrational build :: ValidationError -> Builder # |
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.
lOriginate :: (SingI (ToT cp), SingI (ToT st), HasNoOp (ToT st), IsoValue st) => Contract cp st -> Text -> st -> Mutez -> IntegrationalScenarioM (ContractAddr cp) Source #
Like originate
, but for Lorentz contracts.
lOriginateEmpty :: (SingI (ToT cp), SingI (ToT st), HasNoOp (ToT st), IsoValue st, Default st) => Contract cp st -> Text -> IntegrationalScenarioM (ContractAddr cp) Source #
Originate a contract with empty balance and default storage.
lTransfer :: (SingI (ToT cp), HasNoOp (ToT cp), IsoValue cp) => ("from" :! Address) -> ("to" :! ContractAddr cp) -> Mutez -> cp -> IntegrationalScenarioM () Source #
Similar to transfer
, for Lorentz values.
lCall :: (SingI (ToT cp), HasNoOp (ToT cp), IsoValue cp) => ContractAddr cp -> cp -> IntegrationalScenarioM () Source #
Call a contract without caring about source address and money.
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.
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).
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.
lExpectStorageUpdate :: (IsoValue st, Each [Typeable, SingI, HasNoOp] '[ToT st], HasCallStack) => ContractAddr cp -> (st -> Either ValidationError ()) -> SuccessValidator Source #
Similar to expectStorageUpdate
, for Lorentz values.
lExpectBalance :: ContractAddr cp -> Mutez -> SuccessValidator Source #
Like expectBalance
, for Lorentz values.
lExpectStorageConst :: (IsoValue st, Each '[SingI, HasNoOp] '[ToT st]) => ContractAddr cp -> st -> SuccessValidator Source #
Similar to expectStorageConst
, for Lorentz values.
lExpectMichelsonFailed :: (MichelsonFailed -> Bool) -> ContractAddr cp -> InterpreterError -> Bool Source #
Expect that interpretation of contract with given address ended with [FAILED].
lExpectFailWith :: forall e. (Typeable (ToT e), IsoValue e) => (e -> Bool) -> InterpreterError -> Bool Source #
Expect contract to fail with FAILWITH instruction and provided value to match against the given predicate.
lExpectUserError :: forall e. (Typeable (ToT e), IsoValue e) => (e -> Bool) -> InterpreterError -> Bool Source #
Expect contract to fail with given LorentzUserError
error.
lExpectConsumerStorage :: (st ~ [cp], IsoValue st, Each [Typeable, SingI, HasNoOp] '[ToT st]) => ContractAddr cp -> (st -> Either ValidationError ()) -> SuccessValidator Source #
Version of lExpectStorageUpdate
specialized to "consumer" contract
(see contractConsumer
).
lExpectViewConsumerStorage :: (st ~ [cp], cp ~ (arg, Maybe res), Eq res, Buildable res, IsoValue st, Each [Typeable, SingI, HasNoOp] '[ToT st]) => ContractAddr cp -> [res] -> SuccessValidator Source #
Assuming that "consumer" contract receives a value from View
, expect
this view return value to be the given one.
Despite consumer stores parameters it was called with in reversed order, this function cares about it, so you should provide a list of expected values in the same order in which the corresponding events were happenning.