morley-0.3.0: Developer tools for the Michelson Language

Safe HaskellNone
LanguageHaskell2010

Lorentz.Test.Integrational

Contents

Description

Mirrors Integrational module in a Lorentz way.

Synopsis

Re-exports

data TxData Source #

Data associated with a particular transaction.

Constructors

TxData 
Instances
Eq TxData Source # 
Instance details

Defined in Michelson.Runtime.TxData

Methods

(==) :: TxData -> TxData -> Bool #

(/=) :: TxData -> TxData -> Bool #

Show TxData Source # 
Instance details

Defined in Michelson.Runtime.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.

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.

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.