Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- specWithContract :: (Each [Typeable, SingI] [cp, st], HasCallStack) => FilePath -> ((Contract, Contract cp st) -> Spec) -> Spec
- specWithTypedContract :: (Each [Typeable, SingI] [cp, st], HasCallStack) => FilePath -> (Contract cp st -> Spec) -> Spec
- specWithUntypedContract :: FilePath -> (Contract -> Spec) -> Spec
- type ContractReturn st = (Either MichelsonFailed ([Operation], Value st), InterpreterState)
- type ContractPropValidator st prop = ContractReturn st -> prop
- contractProp :: (IsoValue param, IsoValue storage, ToT param ~ cp, ToT storage ~ st, ParameterScope cp) => Contract cp st -> ContractPropValidator st prop -> ContractEnv -> param -> storage -> prop
- contractPropVal :: ParameterScope cp => Contract cp st -> ContractPropValidator st prop -> ContractEnv -> Value cp -> Value st -> prop
- type IntegrationalValidator = Either (ExecutorError -> Bool) SuccessValidator
- type SuccessValidator = InternalState -> GState -> [GStateUpdate] -> Either ValidationError ()
- type IntegrationalScenario = IntegrationalScenarioM Validated
- type IntegrationalScenarioM = StateT InternalState (Except ScenarioError)
- data ValidationError
- = UnexpectedExecutorError IntegrationalExecutorError
- | UnexpectedTypeCheckError TCError
- | ExpectingInterpreterToFail
- | IncorrectUpdates ValidationError [GStateUpdate]
- | IncorrectStorageUpdate AddressName Text
- | InvalidStorage AddressName ExpectedStorage Text
- | InvalidBalance AddressName ExpectedBalance Text
- | UnexpectedUpdates (NonEmpty GStateUpdate)
- | CustomValidationError Text
- integrationalTestExpectation :: HasCallStack => IntegrationalScenario -> Expectation
- integrationalTestProperty :: IntegrationalScenario -> Property
- lOriginate :: forall cp st. (ParameterDeclaresEntryPoints cp, NiceStorage st) => Contract cp st -> Text -> st -> Mutez -> IntegrationalScenarioM (ContractRef cp)
- lOriginateEmpty :: (ParameterDeclaresEntryPoints cp, NiceStorage st, Default st) => Contract cp st -> Text -> IntegrationalScenarioM (ContractRef cp)
- lTransfer :: forall cp epRef epArg contract. (HasEntryPointArg cp epRef epArg, IsoValue epArg, ToContractRef cp contract) => ("from" :! Address) -> ("to" :! contract) -> Mutez -> epRef -> epArg -> IntegrationalScenarioM ()
- lCall :: forall cp defEpName contract. (HasDefEntryPointArg cp defEpName cp, IsoValue cp, ToContractRef cp contract) => contract -> cp -> IntegrationalScenarioM ()
- lCallEP :: forall cp epRef epArg contract. (HasEntryPointArg cp epRef epArg, IsoValue epArg, ToContractRef cp contract) => contract -> epRef -> epArg -> IntegrationalScenarioM ()
- lCallDef :: forall cp defEpName defArg contract. (HasDefEntryPointArg cp defEpName defArg, IsoValue defArg, ToContractRef cp contract) => contract -> defArg -> IntegrationalScenarioM ()
- validate :: IntegrationalValidator -> IntegrationalScenario
- integrationalFail :: ValidationError -> IntegrationalScenarioM anything
- setMaxSteps :: RemainingSteps -> 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 -> IntegrationalScenarioM ()
- composeValidators :: SuccessValidator -> SuccessValidator -> SuccessValidator
- composeValidatorsList :: [SuccessValidator] -> SuccessValidator
- expectAnySuccess :: SuccessValidator
- expectNoUpdates :: SuccessValidator
- expectNoStorageUpdates :: SuccessValidator
- lExpectStorageUpdate :: forall st addr. (NiceStorage st, ToAddress addr, HasCallStack) => addr -> (st -> Either ValidationError ()) -> SuccessValidator
- lExpectBalance :: ToAddress addr => addr -> Mutez -> SuccessValidator
- lExpectStorageConst :: forall st addr. (NiceStorage st, ToAddress addr) => addr -> st -> SuccessValidator
- lExpectMichelsonFailed :: forall addr. ToAddress addr => (MichelsonFailed -> Bool) -> addr -> ExecutorError -> Bool
- lExpectFailWith :: forall e. (Typeable (ToT e), IsoValue e) => (e -> Bool) -> ExecutorError -> Bool
- lExpectError :: forall e. IsError e => (e -> Bool) -> ExecutorError -> Bool
- lExpectErrorNumeric :: forall e. IsError e => ErrorTagMap -> (e -> Bool) -> ExecutorError -> Bool
- lExpectCustomError :: forall tag arg. (IsError (CustomError tag), arg ~ ErrorArg tag, Eq arg) => Label tag -> arg -> ExecutorError -> Bool
- lExpectCustomErrorNumeric :: forall tag arg. (IsError (CustomError tag), arg ~ ErrorArg tag, Eq arg) => ErrorTagMap -> Label tag -> arg -> ExecutorError -> Bool
- lExpectCustomError_ :: forall tag. (IsError (CustomError tag), ErrorArg tag ~ ()) => Label tag -> ExecutorError -> Bool
- lExpectCustomErrorNumeric_ :: forall tag. (IsError (CustomError tag), ErrorArg tag ~ ()) => ErrorTagMap -> Label tag -> ExecutorError -> Bool
- lExpectConsumerStorage :: forall cp st contract. (st ~ [cp], NiceStorage st, ToContractRef cp contract) => contract -> (st -> Either ValidationError ()) -> SuccessValidator
- lExpectViewConsumerStorage :: (st ~ [cp], Eq cp, Buildable cp, NiceStorage st, ToContractRef cp contract) => contract -> [cp] -> SuccessValidator
- data TxData = TxData {}
- genesisAddresses :: NonEmpty Address
- genesisAddress :: Address
- genesisAddress1 :: Address
- genesisAddress2 :: Address
- genesisAddress3 :: Address
- genesisAddress4 :: Address
- genesisAddress5 :: Address
- genesisAddress6 :: Address
- runDocTests :: HasCallStack => [DocTest] -> ContractDoc -> [TestTree]
- testLorentzDoc :: [DocTest]
- excludeDocTests :: [DocTest] -> [DocTest] -> [DocTest]
- failedProp :: Text -> Property
- succeededProp :: Property
- qcIsLeft :: Show b => Either a b -> Property
- qcIsRight :: Show a => Either a b -> Property
- dummyContractEnv :: ContractEnv
- minTimestamp :: Timestamp
- maxTimestamp :: Timestamp
- midTimestamp :: Timestamp
- contractConsumer :: Contract cp [cp]
Importing a contract
specWithContract :: (Each [Typeable, SingI] [cp, st], HasCallStack) => FilePath -> ((Contract, Contract cp st) -> Spec) -> Spec Source #
Import contract and use it in the spec. Both versions of contract are passed to the callback function (untyped and typed).
If contract's import fails, a spec with single failing expectation will be generated (so tests will likely run unexceptionally, but a failing result will notify about problem).
specWithTypedContract :: (Each [Typeable, SingI] [cp, st], HasCallStack) => FilePath -> (Contract cp st -> Spec) -> Spec Source #
A version of specWithContract
which passes only the typed
representation of the contract.
Unit testing
type ContractReturn st = (Either MichelsonFailed ([Operation], Value st), InterpreterState) Source #
type ContractPropValidator st prop = ContractReturn st -> prop Source #
Type for contract execution validation.
It's a function which is supplied with contract execution output (failure or new storage with operation list).
Function returns a property which type is designated by type variable prop
and might be Property
or Expectation
or anything else relevant.
contractProp :: (IsoValue param, IsoValue storage, ToT param ~ cp, ToT storage ~ st, ParameterScope cp) => Contract cp st -> ContractPropValidator st prop -> ContractEnv -> param -> storage -> prop Source #
Contract's property tester against given input. Takes contract environment, initial storage and parameter, interprets contract on this input and invokes validation function.
contractPropVal :: ParameterScope cp => Contract cp st -> ContractPropValidator st prop -> ContractEnv -> Value cp -> Value st -> prop Source #
Version of contractProp
which takes Val
as arguments instead
of regular Haskell values.
Integrational testing
Testing engine
type IntegrationalValidator = Either (ExecutorError -> 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 IntegrationalScenario = IntegrationalScenarioM Validated Source #
type IntegrationalScenarioM = StateT InternalState (Except ScenarioError) Source #
A monad inside which integrational tests can be described using do-notation.
data ValidationError Source #
UnexpectedExecutorError IntegrationalExecutorError | |
UnexpectedTypeCheckError TCError | |
ExpectingInterpreterToFail | |
IncorrectUpdates ValidationError [GStateUpdate] | |
IncorrectStorageUpdate AddressName Text | |
InvalidStorage AddressName ExpectedStorage Text | |
InvalidBalance AddressName ExpectedBalance Text | |
UnexpectedUpdates (NonEmpty GStateUpdate) | |
CustomValidationError 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 :: HasCallStack => 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 :: forall cp st. (ParameterDeclaresEntryPoints cp, NiceStorage st) => Contract cp st -> Text -> st -> Mutez -> IntegrationalScenarioM (ContractRef cp) Source #
Like originate
, but for Lorentz contracts.
lOriginateEmpty :: (ParameterDeclaresEntryPoints cp, NiceStorage st, Default st) => Contract cp st -> Text -> IntegrationalScenarioM (ContractRef cp) Source #
Originate a contract with empty balance and default storage.
lTransfer :: forall cp epRef epArg contract. (HasEntryPointArg cp epRef epArg, IsoValue epArg, ToContractRef cp contract) => ("from" :! Address) -> ("to" :! contract) -> Mutez -> epRef -> epArg -> IntegrationalScenarioM () Source #
Similar to transfer
, for Lorentz values.
lCall :: forall cp defEpName contract. (HasDefEntryPointArg cp defEpName cp, IsoValue cp, ToContractRef cp contract) => contract -> cp -> IntegrationalScenarioM () Source #
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 contract. (HasEntryPointArg cp epRef epArg, IsoValue epArg, ToContractRef cp contract) => contract -> epRef -> epArg -> IntegrationalScenarioM () Source #
Call an entrypoint of a contract without caring about the source address. Transfers 0 mutez.
lCallDef :: forall cp defEpName defArg contract. (HasDefEntryPointArg cp defEpName defArg, IsoValue defArg, ToContractRef cp contract) => contract -> defArg -> IntegrationalScenarioM () Source #
lCallEP
for default entrypoint.
validate :: IntegrationalValidator -> IntegrationalScenario Source #
Validate the execution result.
integrationalFail :: ValidationError -> IntegrationalScenarioM anything Source #
Just fail with given error.
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.
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 (which are triggered by the
validate
function) use 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 -> IntegrationalScenarioM () Source #
Test given scenario with the state gathered till this moment; if this scenario passes, go on as if it never happened.
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.
expectNoUpdates :: SuccessValidator Source #
Check that there were no updates.
expectNoStorageUpdates :: SuccessValidator Source #
Check that there were no storage updates.
lExpectStorageUpdate :: forall st addr. (NiceStorage st, ToAddress addr, HasCallStack) => addr -> (st -> Either ValidationError ()) -> SuccessValidator Source #
Similar to expectStorageUpdate
, for Lorentz values.
lExpectBalance :: ToAddress addr => addr -> Mutez -> SuccessValidator Source #
Like expectBalance
, for Lorentz values.
lExpectStorageConst :: forall st addr. (NiceStorage st, ToAddress addr) => addr -> st -> SuccessValidator Source #
Similar to expectStorageConst
, for Lorentz values.
lExpectMichelsonFailed :: forall addr. ToAddress addr => (MichelsonFailed -> Bool) -> addr -> ExecutorError -> Bool Source #
Expect that interpretation of contract with given address ended with [FAILED].
lExpectFailWith :: forall e. (Typeable (ToT e), IsoValue e) => (e -> Bool) -> ExecutorError -> Bool 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 -> Bool Source #
Expect contract to fail with given error.
lExpectErrorNumeric :: forall e. IsError e => ErrorTagMap -> (e -> Bool) -> ExecutorError -> Bool 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 -> Bool 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 -> Bool 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 -> Bool Source #
Specialization of lExpectCustomError
for non-arg error case.
lExpectCustomErrorNumeric_ :: forall tag. (IsError (CustomError tag), ErrorArg tag ~ ()) => ErrorTagMap -> Label tag -> ExecutorError -> Bool Source #
Version of lExpectCustomError_
for the case when numeric
representation of errors is used.
lExpectConsumerStorage :: forall cp st contract. (st ~ [cp], NiceStorage st, ToContractRef cp contract) => contract -> (st -> Either ValidationError ()) -> SuccessValidator Source #
Version of lExpectStorageUpdate
specialized to "consumer" contract
(see contractConsumer
).
lExpectViewConsumerStorage :: (st ~ [cp], Eq cp, Buildable cp, NiceStorage st, ToContractRef cp contract) => contract -> [cp] -> 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.
Various
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.
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 !!
Autodoc testing
runDocTests :: HasCallStack => [DocTest] -> ContractDoc -> [TestTree] Source #
Finalize test suites.
testLorentzDoc :: [DocTest] Source #
Tests all properties.
excludeDocTests :: [DocTest] -> [DocTest] -> [DocTest] Source #
Calling excludeDocTests tests toExclude
returns all test suites from
tests
which are not present in toExclude
.
General utilities
succeededProp :: Property Source #
A Property
that always succeeds.
Dummy values
dummyContractEnv :: ContractEnv Source #
Dummy ContractEnv
with some reasonable hardcoded values. You
can override values you are interested in using record update
syntax.
Arbitrary data
minTimestamp :: Timestamp Source #
Minimal (earliest) timestamp used for Arbitrary (CValue 'CTimestamp)
maxTimestamp :: Timestamp Source #
Maximal (latest) timestamp used for Arbitrary (CValue 'CTimestamp)
midTimestamp :: Timestamp Source #
Median of minTimestamp
and maxTimestamp
.
Useful for testing (exactly half of generated dates will be before and after
this date).
Special contracts for testing
contractConsumer :: Contract cp [cp] Source #
Remembers parameters it was called with, last goes first.