lorentz-0.4.0: EDSL for the Michelson Language
Safe HaskellNone
LanguageHaskell2010

Lorentz.Test.Integrational

Description

Mirrors Integrational module in a Lorentz way.

Synopsis

Re-exports

data TxData #

Data associated with a particular transaction.

Instances

Instances details
Eq TxData 
Instance details

Defined in Michelson.Runtime.TxData

Methods

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

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

Show TxData 
Instance details

Defined in Michelson.Runtime.TxData

ToJSON TxData 
Instance details

Defined in Michelson.Runtime.TxData

FromJSON TxData 
Instance details

Defined in Michelson.Runtime.TxData

genesisAddresses :: NonEmpty Address #

Initially these addresses have a lot of money.

genesisAddress :: Address #

One of genesis addresses.

More genesis addresses which can be used in tests

genesisAddress1 :: Address #

More genesis addresses

We know size of genesisAddresses, so it is safe to use !!

genesisAddress2 :: Address #

More genesis addresses

We know size of genesisAddresses, so it is safe to use !!

genesisAddress3 :: Address #

More genesis addresses

We know size of genesisAddresses, so it is safe to use !!

Testing engine for bare Typed primitives

tOriginate :: forall (cp :: T) (st :: T). (ParameterScope cp, StorageScope st) => Contract cp st -> Text -> Value st -> Mutez -> IntegrationalScenarioM Address #

Like originate, but for typed contract and value.

tTransfer :: forall (arg :: T). ParameterScope arg => ("from" :! Address) -> ("to" :! Address) -> Mutez -> EpName -> Value arg -> IntegrationalScenarioM () #

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).

tExpectStorageConst :: forall (st :: T). StorageScope st => Address -> Value st -> IntegrationalScenario #

Similar to expectStorageConst, for typed stuff.

Testing engine

type IntegrationalScenarioM = StateT InternalState (Except ScenarioError) #

A monad inside which integrational tests can be described using do-notation.

integrationalTestExpectation :: HasCallStack => IntegrationalScenario -> Expectation #

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 () #

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.

lOriginate :: forall cp st. (NiceParameterFull cp, NiceStorage st) => Contract cp st -> Text -> st -> Mutez -> IntegrationalScenarioM (TAddress cp) Source #

Like originate, but for Lorentz contracts.

lOriginateEmpty :: (NiceParameterFull cp, NiceStorage st, Default st) => Contract cp st -> Text -> IntegrationalScenarioM (TAddress cp) Source #

Originate a contract with empty balance and default storage.

lTransfer :: forall cp epRef epArg addr. (HasEntryPointArg cp epRef epArg, IsoValue epArg, ToTAddress cp addr) => ("from" :! Address) -> ("to" :! addr) -> Mutez -> epRef -> epArg -> IntegrationalScenarioM () Source #

Similar to transfer, for Lorentz values.

lCall :: forall cp defEpName addr. (HasDefEntryPointArg cp defEpName cp, IsoValue cp, ToTAddress cp addr) => addr -> cp -> IntegrationalScenarioM () Source #

Deprecated: lCall will likely be replaced with lCallEP in future version

Legacy version of lCallEP function. Calls default entrypoint of a contract assuming its argument is the same as contract parameter (which is equivalent to absence of explicit default entrypoint).

This function is DEPRECATED and exists only for backwards compatibility.

lCallEP :: forall cp epRef epArg addr. (HasEntryPointArg cp epRef epArg, IsoValue epArg, ToTAddress cp addr) => addr -> epRef -> epArg -> IntegrationalScenarioM () Source #

Call an entrypoint of a contract without caring about the source address. Transfers 0 mutez.

data EntryPointRef (mname :: Maybe Symbol) where Source #

Which entrypoint to call.

We intentionally distinguish default and non-default cases because this makes API more details-agnostic.

Constructors

CallDefault :: EntryPointRef 'Nothing

Call the default entrypoint, or root if no explicit default is assigned.

Call :: NiceEntryPointName name => EntryPointRef ('Just name)

Call the given entrypoint; calling default is not treated specially. You have to provide entrypoint name via passing it as type argument.

Unfortunatelly, here we cannot accept a label because in most cases our entrypoints begin from capital letter (being derived from constructor name), while labels must start from a lower-case letter, and there is no way to make a conversion at type-level.

Instances

Instances details
(GetEntryPointArgCustom cp mname ~ arg, ParameterDeclaresEntryPoints cp) => HasEntryPointArg (cp :: Type) (EntryPointRef mname) arg Source # 
Instance details

Defined in Lorentz.EntryPoints.Core

lCallDef :: forall cp defEpName defArg addr. (HasDefEntryPointArg cp defEpName defArg, IsoValue defArg, ToTAddress cp addr) => addr -> defArg -> IntegrationalScenarioM () Source #

lCallEP for default entrypoint.

integrationalFail :: TestError -> IntegrationalScenarioM anything #

Just fail with given error.

unexpectedInterpreterError :: ExecutorError -> Text -> IntegrationalScenarioM a #

Fail a test because an interpreter error happened unexpectedly, with the given reason.

setMaxSteps :: RemainingSteps -> IntegrationalScenarioM () #

Make all further interpreter calls use the given gas limit.

setNow :: Timestamp -> IntegrationalScenarioM () #

Make all further interpreter calls use the given timestamp as the current one.

rewindTime :: Integer -> IntegrationalScenarioM () #

Increase current time by the given number of seconds.

withSender :: Address -> IntegrationalScenarioM a -> IntegrationalScenarioM a #

Pretend that given address initiates all the transfers within the code block (i.e. SENDER instruction will return this address).

setChainId :: ChainId -> IntegrationalScenarioM () #

Make all further interpreter calls use the given chain id.

branchout :: HasCallStack => [(Text, IntegrationalScenario)] -> IntegrationalScenario #

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 #

Make a tuple with name without extra syntactic noise.

offshoot :: Text -> IntegrationalScenario -> IntegrationalScenario #

Test given scenario with the state gathered till this moment; if this scenario passes, go on as if it never happened.

Validators

expectNoUpdates :: IntegrationalScenario #

Check that there were no updates.

expectNoStorageUpdates :: IntegrationalScenario #

Check that there were no storage updates.

lExpectStorageUpdate :: forall st addr. (NiceStorage st, ToAddress addr, HasCallStack) => addr -> (st -> Either TestError ()) -> IntegrationalScenario Source #

Similar to expectStorageUpdate, but for Lorentz values.

lExpectBalance :: ToAddress addr => addr -> Mutez -> IntegrationalScenario Source #

Like expectBalance, for Lorentz values.

lExpectStorage :: forall st addr. (NiceStorage st, ToAddress addr, HasCallStack) => addr -> (st -> Either TestError ()) -> IntegrationalScenario Source #

Similar to expectStorage, but for Lorentz values.

lExpectStorageConst :: forall st addr. (NiceStorage st, ToAddress addr) => addr -> st -> IntegrationalScenario Source #

Similar to expectStorageConst, for Lorentz values.

Errors

attempt :: IntegrationalScenarioM a -> IntegrationalScenarioM (Either ExecutorError a) #

Attempt to run an action and return its result or, if interpretation fails, an error.

expectError :: IntegrationalScenarioM a -> IntegrationalScenarioM ExecutorError #

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 #

Run an action that is expected to fail.

In action catchExpectedError f: If the action fails, f is applied to the error. If the action succeeds, the test fails.

lExpectMichelsonFailed :: forall addr. ToAddress addr => (MichelsonFailed -> Bool) -> addr -> ExecutorError -> IntegrationalScenario Source #

Expect that interpretation of contract with given address ended with [FAILED].

lExpectFailWith :: forall e. IsoValue e => (e -> Bool) -> ExecutorError -> IntegrationalScenario Source #

Expect contract to fail with FAILWITH instruction and provided value to match against the given predicate.

lExpectError :: forall e. IsError e => (e -> Bool) -> ExecutorError -> IntegrationalScenario Source #

Expect contract to fail with given error.

lExpectErrorNumeric :: forall e. IsError e => ErrorTagMap -> (e -> Bool) -> ExecutorError -> IntegrationalScenario Source #

Version of lExpectError for the case when numeric representation of errors is used.

lExpectCustomError :: forall tag arg. (IsError (CustomError tag), arg ~ ErrorArg tag, Eq arg) => Label tag -> arg -> ExecutorError -> IntegrationalScenario Source #

Expect contract to fail with given CustomError.

lExpectCustomErrorNumeric :: forall tag arg. (IsError (CustomError tag), arg ~ ErrorArg tag, Eq arg) => ErrorTagMap -> Label tag -> arg -> ExecutorError -> IntegrationalScenario Source #

Version of lExpectCustomError for the case when numeric representation of errors is used.

lExpectCustomError_ :: forall tag. (IsError (CustomError tag), ErrorArg tag ~ ()) => Label tag -> ExecutorError -> IntegrationalScenario Source #

Specialization of lExpectCustomError for non-arg error case.

lExpectCustomErrorNumeric_ :: forall tag. (IsError (CustomError tag), ErrorArg tag ~ ()) => ErrorTagMap -> Label tag -> ExecutorError -> IntegrationalScenario Source #

Version of lExpectCustomError_ for the case when numeric representation of errors is used.

Consumer

lExpectConsumerStorage :: forall cp st addr. (st ~ [cp], NiceStorage st, ToTAddress cp addr) => addr -> (st -> Either TestError ()) -> IntegrationalScenario Source #

Version of lExpectStorageUpdate specialized to "consumer" contract (see contractConsumer).

lExpectViewConsumerStorage :: (st ~ [cp], Eq cp, Buildable cp, NiceStorage st, ToTAddress cp addr) => addr -> [cp] -> IntegrationalScenario 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.

Deprecated

integrationalTestProperty :: IntegrationalScenario -> Property #

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.