Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- specWithContract :: (Each '[SingI] [cp, st], HasCallStack) => FilePath -> (Contract cp st -> Spec) -> Spec
- specWithTypedContract :: (Each '[SingI] [cp, st], HasCallStack) => FilePath -> (Contract cp st -> Spec) -> Spec
- specWithUntypedContract :: FilePath -> (Contract -> Spec) -> Spec
- importContract :: forall cp st vd. (NiceParameter cp, NiceStorage st, NiceViewsDescriptor vd, DemoteViewsDescriptor vd) => FilePath -> IO (Contract cp st vd)
- embedContract :: forall cp st vd. (NiceParameter cp, NiceStorage st, NiceViewsDescriptor vd, DemoteViewsDescriptor vd) => FilePath -> TExpQ (Contract cp st vd)
- embedContractM :: forall cp st vd. (NiceParameter cp, NiceStorage st, NiceViewsDescriptor vd, DemoteViewsDescriptor vd) => IO FilePath -> TExpQ (Contract cp st vd)
- importValue :: forall a. IsoValue a => FilePath -> IO a
- embedValue :: forall a. IsoValue a => FilePath -> TExpQ a
- embedValueM :: forall a. IsoValue a => IO FilePath -> TExpQ a
- type ContractReturn (st :: T) = (Either MichelsonFailureWithStack ([Operation], Value st), (InterpreterState, MorleyLogs))
- 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
- testContractCoversEntrypointsT :: forall exp. TestName -> ContractEPTypeTest exp
- testContractMatchesEntrypointsT :: forall exp. TestName -> ContractEPTypeTest exp
- testContractCoversEntrypoints :: NiceParameterFull contractEps => TestName -> ContractEPTest contractEps st vd
- testContractMatchesEntrypoints :: NiceParameterFull contractEps => TestName -> ContractEPTest contractEps st vd
- data ContractHandle (cp :: Type) (st :: Type) (vd :: Type) = (NiceParameter cp, NiceStorage st, NiceViewsDescriptor vd) => ContractHandle {
- chContractName :: Text
- chAddress :: Address
- chNiceParameterEvi :: forall param st vd. ContractHandle param st vd -> Dict (ParameterScope $ ToT st)
- chNiceStorageEvi :: forall param st vd. ContractHandle param st vd -> Dict (StorageScope $ ToT st)
- class ToAddress addr => ToStorageType st addr where
- pickNiceStorage :: addr -> Dict (NiceStorage st)
- toAddress :: ToAddress a => a -> Address
- runDocTests :: (ContainsDoc code, HasCallStack) => [DocTest] -> code -> [TestTree]
- testLorentzDoc :: [DocTest]
- excludeDocTests :: [DocTest] -> [DocTest] -> [DocTest]
- failedTest :: (HasCallStack, MonadTest m) => Text -> m ()
- succeededTest :: MonadTest m => m ()
- eitherIsLeft :: (Show b, MonadTest m, HasCallStack) => Either a b -> m ()
- eitherIsRight :: (Show a, MonadTest m, HasCallStack) => Either a b -> m ()
- meanTimeUpperBoundProp :: (KnownDivRat unit Second, KnownUnitName unit, HasCallStack) => Time unit -> (a -> b) -> a -> Property
- meanTimeUpperBoundPropNF :: (KnownDivRat unit Second, KnownUnitName unit, HasCallStack, NFData b) => Time unit -> (a -> b) -> a -> Property
- mcs :: RatioNat -> Time Microsecond
- ms :: RatioNat -> Time Millisecond
- sec :: RatioNat -> Time Second
- minute :: RatioNat -> Time Minute
- dummyContractEnv :: ContractEnv
- contractConsumer :: (NiceParameterFull cp, NiceStorageFull cp) => Contract cp [cp] ()
Importing a contract
specWithContract :: (Each '[SingI] [cp, st], HasCallStack) => FilePath -> (Contract cp st -> Spec) -> Spec Source #
Deprecated: Use testTreesWithContract &c. instead
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 '[SingI] [cp, st], HasCallStack) => FilePath -> (Contract cp st -> Spec) -> Spec Source #
Deprecated: Use testTreesWithContract &c. instead
A version of specWithContract
which passes only the typed
representation of the contract.
specWithUntypedContract :: FilePath -> (Contract -> Spec) -> Spec Source #
Deprecated: Use testTreesWithContract &c. instead
importContract :: forall cp st vd. (NiceParameter cp, NiceStorage st, NiceViewsDescriptor vd, DemoteViewsDescriptor vd) => FilePath -> IO (Contract cp st vd) Source #
Import contract from a given FilePath
.
In this and similar functions, parameter and storage types must exactly match
the ones in the contract, while for views this is not necessary. Only
make sure that all views beyond vd
type are present in the contract; ()
always works as views descriptor of the contract.
embedContract :: forall cp st vd. (NiceParameter cp, NiceStorage st, NiceViewsDescriptor vd, DemoteViewsDescriptor vd) => FilePath -> TExpQ (Contract cp st vd) Source #
Import a contract at compile time assuming its expected type is known.
Use it like:
myContract :: Contract Parameter Storage myContract = $$(embedContract "my_contract.tz")
or
let myContract = $$(embedContract @Parameter @Storage "my_contract.tz")
See also the note in Test.Cleveland.Lorentz.Import
embedContractM :: forall cp st vd. (NiceParameter cp, NiceStorage st, NiceViewsDescriptor vd, DemoteViewsDescriptor vd) => IO FilePath -> TExpQ (Contract cp st vd) Source #
Version of embedContract
that accepts a filepath constructor in IO.
Useful when the path should depend on environmental variables or other user input.
See also the note in Test.Cleveland.Lorentz.Import
Importing a value
importValue :: forall a. IsoValue a => FilePath -> IO a Source #
Import a value from a given FilePath
embedValue :: forall a. IsoValue a => FilePath -> TExpQ a Source #
Import a value from a given FilePath
at compile time
and embed it as a value using Template Haskell, f. ex.
let someAddress = $$(embedValue @Address "/path/to/addressFile.tz")
See also the note in Test.Cleveland.Lorentz.Import
embedValueM :: forall a. IsoValue a => IO FilePath -> TExpQ a Source #
A variant of embedValue
that accepts FilePath
in IO
.
Can be useful when FilePath
depends on the environment.
See also the note in Test.Cleveland.Lorentz.Import
Unit testing
type ContractReturn (st :: T) = (Either MichelsonFailureWithStack ([Operation], Value st), (InterpreterState, MorleyLogs)) #
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 Test.QuickCheck.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 #
ContractCode'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 Value
as arguments instead
of regular Haskell values.
This function assumes that contract has no explicit default entrypoints and you always have to construct parameter manually; if you need to test contract calling specific entrypoints, use integrational testing defined by Test.Cleveland.Michelson.Integrational module.
testContractCoversEntrypointsT :: forall exp. TestName -> ContractEPTypeTest exp Source #
Expect the contract to cover or exactly match with the entrypoints given in spec passed as the first type argument. Checks both the contract type and the contract itself (when represented as an untyped Michelson contract).
testContractMatchesEntrypointsT :: forall exp. TestName -> ContractEPTypeTest exp Source #
Expect the contract to cover or exactly match with the entrypoints given in spec passed as the first type argument. Checks both the contract type and the contract itself (when represented as an untyped Michelson contract).
testContractCoversEntrypoints :: NiceParameterFull contractEps => TestName -> ContractEPTest contractEps st vd Source #
Expect the contract to cover or exactly match with the entrypoints given in spec passed as a
Map
of names to types. Checks both the contract type and the contract itself (when represented as
an untyped Michelson contract).
testContractMatchesEntrypoints :: NiceParameterFull contractEps => TestName -> ContractEPTest contractEps st vd Source #
Expect the contract to cover or exactly match with the entrypoints given in spec passed as a
Map
of names to types. Checks both the contract type and the contract itself (when represented as
an untyped Michelson contract).
Basic types
data ContractHandle (cp :: Type) (st :: Type) (vd :: Type) Source #
Handle to a contract.
This is what you get when originating a contract and that allows further operations with the contract within the test framework.
Note that this is part of the testing framework and exists solely in Haskell
world, so it has no IsoValue
and related instances and cannot be used in
Lorentz code.
(NiceParameter cp, NiceStorage st, NiceViewsDescriptor vd) => ContractHandle | |
|
Instances
chNiceParameterEvi :: forall param st vd. ContractHandle param st vd -> Dict (ParameterScope $ ToT st) Source #
Extract the evidence in typed Michelson that the parameter type is valid for such scope.
chNiceStorageEvi :: forall param st vd. ContractHandle param st vd -> Dict (StorageScope $ ToT st) Source #
Extract the evidence in typed Michelson that the storage type is valid for such scope.
class ToAddress addr => ToStorageType st addr where Source #
Declares that addr
points to an entity with a storage.
addr
may fix storage type or may not - in the latter case the caller
has to specify the storage type explicitly via type annotation.
pickNiceStorage :: addr -> Dict (NiceStorage st) Source #
Pick proof of that storage type is valid.
Instances
NiceStorage st => ToStorageType st Address Source # | |
Defined in Test.Cleveland.Lorentz.Types pickNiceStorage :: Address -> Dict (NiceStorage st) Source # | |
st ~ st' => ToStorageType st' (ContractHandle cp st vd) Source # | |
Defined in Test.Cleveland.Lorentz.Types pickNiceStorage :: ContractHandle cp st vd -> Dict (NiceStorage st') Source # |
Conversions
Autodoc testing
runDocTests :: (ContainsDoc code, HasCallStack) => [DocTest] -> code -> [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
failedTest :: (HasCallStack, MonadTest m) => Text -> m () Source #
A Property
that always fails with given message.
succeededTest :: MonadTest m => m () Source #
A Property
that always succeeds.
eitherIsLeft :: (Show b, MonadTest m, HasCallStack) => Either a b -> m () Source #
The Property
holds on `Left a`.
eitherIsRight :: (Show a, MonadTest m, HasCallStack) => Either a b -> m () Source #
The Property
holds on `Right b`.
meanTimeUpperBoundProp :: (KnownDivRat unit Second, KnownUnitName unit, HasCallStack) => Time unit -> (a -> b) -> a -> Property Source #
Benchmarks the given function and checks that the mean time to evaluate to weak head normal form is under the given amount of time.
This test fails if the benchmark takes longer than 30 seconds to run.
meanTimeUpperBoundPropNF :: (KnownDivRat unit Second, KnownUnitName unit, HasCallStack, NFData b) => Time unit -> (a -> b) -> a -> Property Source #
Benchmarks the given function and checks that the mean time to evaluate to normal form is under the given amount of time.
This test aborts and fails if the benchmark takes longer than 120 seconds to run.
Re-exports
These functions from Time
are re-exported here to make it convenient to call
meanTimeUpperBoundProp
and meanTimeUpperBoundPropNF
.
mcs :: RatioNat -> Time Microsecond #
Creates Microsecond
from given Natural
.
>>>
mcs 42
42mcs
ms :: RatioNat -> Time Millisecond #
Creates Millisecond
from given Natural
.
>>>
ms 42
42ms
Dummy values
dummyContractEnv :: ContractEnv #
Special contracts for testing
contractConsumer :: (NiceParameterFull cp, NiceStorageFull cp) => Contract cp [cp] () Source #
Remembers parameters it was called with, last goes first.