cleveland-0.1.2: Testing framework for Morley.
Safe HaskellNone
LanguageHaskell2010

Test.Cleveland.Internal.Abstract

Description

Abstract cleveland interface not bound to a particular implementation.

The interface may look a bit untyped and unsafe in some places. For example, in order to call a contract one should supply a simple address rather than a contract ref, so it is easy to pass a value of wrong type. Also it is easy to call a non-existing entrypoint.

Subjectively, it makes writing test scenarios easier because you have to prove less to the compiler. It also makes implementation of cleveland engine a bit easier. Of course, it also makes it easier to make certain mistakes. However, we expect users of this interface to also use the functionality of the Test.Cleveland.Internal.Pure module and convert cleveland scenarios to purely testable scenarios for integrational testing engine. In this case errors should be detected almost as quickly as they would reported by the compiler, at least before trying to run scenario on a live network.

Also this interface uses Address rather than EpAddress. I (@gromak) concluded that EpAddress can not be passed to tezos-client. For key addresses it just does not make sense and for contract addresses I get such errors:

  bad contract notation
  Invalid contract notation "KT1VrFpBPwBTm3hsK7DB7SPmY8fTHJ3vY6sJ%mint"
Synopsis

Documentation

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.

Constructors

(NiceParameter cp, NiceStorage st, NiceViewsDescriptor vd) => ContractHandle 

Fields

Instances

Instances details
(cp' ~ cp, vd ~ vd') => ToTAddress cp' vd' (ContractHandle cp st vd) Source # 
Instance details

Defined in Test.Cleveland.Lorentz.Types

Methods

toTAddress :: ContractHandle cp st vd -> TAddress cp' vd'

ToContractRef arg (TAddress cp vd) => ToContractRef arg (ContractHandle cp st vd) Source # 
Instance details

Defined in Test.Cleveland.Lorentz.Types

Methods

toContractRef :: ContractHandle cp st vd -> ContractRef arg

st ~ st' => ToStorageType st' (ContractHandle cp st vd) Source # 
Instance details

Defined in Test.Cleveland.Lorentz.Types

Show (ContractHandle cp st vd) Source # 
Instance details

Defined in Test.Cleveland.Lorentz.Types

Methods

showsPrec :: Int -> ContractHandle cp st vd -> ShowS #

show :: ContractHandle cp st vd -> String #

showList :: [ContractHandle cp st vd] -> ShowS #

Buildable (ContractHandle cp st vd) Source # 
Instance details

Defined in Test.Cleveland.Lorentz.Types

Methods

build :: ContractHandle cp st vd -> Builder #

ToAddress (ContractHandle cp st vd) Source # 
Instance details

Defined in Test.Cleveland.Lorentz.Types

Methods

toAddress :: ContractHandle cp st vd -> Address #

data OriginateData param st vd Source #

Constructors

OriginateData 

Fields

  • odName :: AliasHint

    Alias for the originated contract.

  • odBalance :: Mutez

    Initial balance.

  • odStorage :: st

    Initial storage.

  • odContract :: Contract param st vd

    The contract itself.

    We are using Lorentz version here which is convenient. However, keep in mind that if someone wants to test a contract from .tz file, they should use UntypedOriginateData.

data TransferData Source #

Information about transfer operation.

Constructors

forall v addr.(NiceParameter v, ToAddress addr) => TransferData 

Fields

  • tdTo :: addr

    Receiver address for this transaction.

  • tdAmount :: Mutez

    Amount to be transferred.

  • tdEntrypoint :: EpName

    An entrypoint to be called. Consider using ep in testing scenarios.

  • tdParameter :: v

    Parameter that will be used for a contract call. Set to () for transfers to key addresses.

newtype Sender Source #

Designates the special sender address.

Transfers and some other operations will occur on behalf of this address. This is initialized to moneybag address and then can be locally modified.

Operations in ClevelandOpsImpl are affected by this address.

Constructors

Sender 

Fields

newtype Moneybag Source #

Designates the address that gifts money to new addresses.

Once a new address is allocated in a test scenario, we have to transfer some money to it so that it is able to serve as transactions sender. Moneybag serves as a source of that money.

We do not use Sender for this purpose because in most situations changing moneybag is not necessary. If a user wraps a large piece of their script with withSender call and that changes the moneybag - this behaviour may be undesired and unexpected to the user.

Constructors

Moneybag 

Fields

data UntypedOriginateData Source #

Untyped version of OriginateData. It can be used for interaction with raw Michelson contracts

Constructors

UntypedOriginateData 

Fields

data RunCode cp st vd Source #

The data needed to call the /run_code RPC endpoint.

Constructors

RunCode 

Fields

data ClevelandInput Source #

Designates an operation input.

Instances

Instances details
OperationInfoDescriptor ClevelandInput Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

Associated Types

type TransferInfo ClevelandInput

type OriginationInfo ClevelandInput

type RevealInfo ClevelandInput

type OriginationInfo ClevelandInput Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

type OriginationInfo ClevelandInput = UntypedOriginateData
type RevealInfo ClevelandInput Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

type RevealInfo ClevelandInput = PublicKey
type TransferInfo ClevelandInput Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

type TransferInfo ClevelandInput = TransferData

newtype DefaultAliasCounter Source #

Counter which is used to provide different default aliases.

Actions

data ClevelandOpsImpl m Source #

A record data type with operations creating primitives.

Constructors

ClevelandOpsImpl 

Fields

data ClevelandMiscImpl m Source #

A record data type with all base methods one can use during a cleveland test.

Constructors

ClevelandMiscImpl 

Fields

data EmulatedImpl m Source #

A record data type with all base methods one can use during cleveland, but which are available only when running on an emulated environment (e.g. Morley.Michelson.Runtime) and not on a real network.

Constructors

EmulatedImpl 

Fields

  • eiBranchout :: [(Text, m ())] -> m ()

    Execute multiple testing scenarios independently.

    • Actions performed before eiBranchout will be observed by all branches.
    • Actions performed in branches will _not_ be observed by any actions performed after eiBranchout.
    • Actions performed in one branch will _not_ be observed by another branch.
    • The test succeeds IFF all branches succeed.
    • If any branch fails, the test ends immediately and the remaining branches won't be executed.

    The following property holds:

    pre >> branchout [a, b, c] = branchout [pre >> a, pre >> b, pre >> c]

    The list of branches must be non-empty.

  • eiGetStorage :: forall st addr. (HasCallStack, ToStorageType st addr) => addr -> m st

    Retrieve a contract's full storage, including the contents of its big_maps. This function can only be used in emulator-only tests.

  • eiGetMorleyLogs :: forall a. m a -> m (LogsInfo, a)

    Returns the result of the action with the logs it produced

  • eiSetVotingPowers :: VotingPowers -> m ()

    Change voting power distribution.

mapClevelandOpsImplExceptions :: (forall a. HasCallStack => m a -> m a) -> ClevelandOpsImpl m -> ClevelandOpsImpl m Source #

Runs a handler over every action.

mapClevelandMiscImplExceptions :: (forall a. HasCallStack => m a -> m a) -> ClevelandMiscImpl m -> ClevelandMiscImpl m Source #

Runs a handler over every action (except cmiAttempt and cmiThrow), possibly transforming exceptions thrown by those actions.

Batching

data BatchResultMismatch Source #

A batch returned invalid output, e.g. origination address when transaction was supplied.

Constructors

BatchResultMismatch Text

Carries expected operation type in lowercase

Instances

Instances details
Buildable BatchResultMismatch Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

data ClevelandOpsBatch a Source #

Where the batched operations occur.

Note that this is not a Monad, rather an Applicative - use -XApplicativeDo extension for nicer experience.

Instances

Instances details
(TypeError (((('Text "Attempt to use monad capabilities within a batch" :$$: 'Text "In case you are using a do-block, make sure that") :$$: 'Text "\8226 `ApplicativeDo` extension is enabled") :$$: 'Text "\8226 there is a return statement in the end") :$$: 'Text "\8226 returned value picks variables in the order in which they are defined") :: Constraint) => Monad ClevelandOpsBatch Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

Functor ClevelandOpsBatch Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

Applicative ClevelandOpsBatch Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

MonadOps ClevelandOpsBatch Source # 
Instance details

Defined in Test.Cleveland.Internal.Actions

runBatched :: (HasCallStack, Functor m) => ClevelandOpsImpl m -> ClevelandOpsBatch a -> m a Source #

Run a series of operations within a batch.

Example:

contract <- runBatched impl $ do
  -- this block is executed within ClevelandOpsBatch
  contract <- runSingleOperation batchedOpsImpl "origination" ...
  for_ [1..3] i ->
    runSingleOperation batchedOpsImpl "transfer" ...
  return contract

See ClevelandOpsBatch for some precautions.

batchedOpsImpl :: ClevelandOpsImpl ClevelandOpsBatch Source #

ClevelandOpsImpl suitable for methods executed within a batch.

runOperationBatchM :: (HasCallStack, Buildable e, Functor m) => Proxy e -> ClevelandOpsImpl m -> BatchingM (OperationInfo ClevelandInput) (OperationInfo Result) e a -> m a Source #

Version of coiRunOperationBatch that uses BatchingM.

This is an internal function.

Invariant: all errors described by e must be internal and should not occur in practice (we require e type to be specified explicitly to hinder incorrect usage).

runSingleOperation :: (HasCallStack, Functor m) => ClevelandOpsImpl m -> Text -> OperationInfo ClevelandInput -> (OperationInfo Result -> Maybe a) -> m a Source #

Helper that runs a single operation using ClevelandOpsImpl.

Validation

data TransferFailure Source #

Failures that could be expected in the execution of a transfer. These can be caught and handled with attempt.

Constructors

TransferFailure 

data TransferFailureReason Source #

Constructors

FailedWith ExpressionOrTypedValue (Maybe InstrCallStack)

Expect that interpretation of contract with the given address ended with FAILWITH.

EmptyTransaction

Expect failure due to an attempt to transfer 0tz towards a simple address.

BadParameter

Expect failure due to an attempt to call a contract with an invalid parameter.

MutezArithError MutezArithErrorType

Expect failure due to an arithmetic over-/underflow

ShiftOverflow

Expect that interpretation of contract with the given address ended with an overflow error.

GasExhaustion 

data FailedInBranch Source #

When an exception is thrown in a branchout branch, we wrap it in this constructor to remember in _which_ branch it was thrown. We use this information to provide better error messages when a test fails.

newtype ScenarioBranchName Source #

When using branchout function for building test scenarios - names of branches we are currently within.

Constructors

ScenarioBranchName 

Fields

data ExpressionOrTypedValue where Source #

Representation of Expression we got from the RPC or a typed value we got from the emulator.

Constructors

EOTVExpression :: Expression -> ExpressionOrTypedValue 
EOTVTypedValue :: (SingI t, ConstantScope t) => Value t -> ExpressionOrTypedValue 

Helpers

auto :: SpecificOrDefaultAliasHint Source #

Helper to use automatically determined unique alias.

ep :: HasCallStack => Text -> EpName Source #

A short partial constructor for EpName. It is supposed to be applied to string constants, so programmer is responsible for validity. And this code is for tests anyway, so each failure is a programmer mistake.

It is intentionally here and not in some deeper module because the name is really short and more suitable for writing scenarios.

Morley client re-exports

Capability records

data ClevelandCaps m Source #

A record with all the capabilities available to any cleveland test.

data EmulatedCaps m Source #

A record with all the capabilities available to a cleveland test on the emulator.

class Monad (ClevelandBaseMonad caps) => HasClevelandCaps caps where Source #

A proof that the given caps record contains the basic cleveland capabilities.

Associated Types

type ClevelandBaseMonad caps :: Type -> Type Source #

This will be either PureM or ClientM.

class HasClevelandCaps caps => HasEmulatedCaps caps where Source #

A proof that the given caps record contains the basic cleveland capabilities + the emulator capabiilities.

type MonadCleveland caps m = (m ~ ReaderT caps (ClevelandBaseMonad caps), HasClevelandCaps caps) Source #

Constraint for a monad in which we can do cleveland actions.

type MonadEmulated caps m = (MonadCleveland caps m, HasEmulatedCaps caps) Source #

Constraint for a monad in which we can do cleveland actions that can't be run on a real network. It requires the EmulatedImpl capability.

type ClevelandT m = ReaderT (ClevelandCaps m) m Source #

Monad transformer that adds only the ClevelandCaps capabilities.

type EmulatedT m = ReaderT (EmulatedCaps m) m Source #

Monad transformer that adds both ClevelandCaps and EmulatedCaps capabilities.

Log utilities

data ScenarioLogs Source #

Constructors

ScenarioLogs 

Fields

Instances

Instances details
Eq ScenarioLogs Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

Show ScenarioLogs Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

MonadWriter LogsInfo PureM Source # 
Instance details

Defined in Test.Cleveland.Internal.Pure

Methods

writer :: (a, LogsInfo) -> PureM a #

tell :: LogsInfo -> PureM () #

listen :: PureM a -> PureM (a, LogsInfo) #

pass :: PureM (a, LogsInfo -> LogsInfo) -> PureM a #

logsL :: Lens' ScenarioLogs MorleyLogs Source #

An alias for slLog with a clearer name

filterLogsByAddrL :: (ToAddress addr, Applicative f) => addr -> (MorleyLogs -> f MorleyLogs) -> ScenarioLogs -> f ScenarioLogs Source #

Lens combinator specified for filtering logs by address from LogsInfo

logsForAddress :: (Each s s ScenarioLogs ScenarioLogs, ToAddress addr) => addr -> s -> [MorleyLogs] Source #

Get logs for a given address from LogsInfo

collectLogs :: LogsInfo -> MorleyLogs Source #

Collect logs produced by all contracts into the single list