cleveland-0.3.1: Testing framework for Morley.
Safe HaskellSafe-Inferred
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 octez-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 ScenarioLogs Source #

Constructors

ScenarioLogs 

Fields

Instances

Instances details
Show ScenarioLogs Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

Eq 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 #

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.

data RunCode cp st vd Source #

The data needed to call the /run_code RPC endpoint.

Constructors

RunCode 

Fields

  • rcContract :: Contract cp st vd
     
  • rcParameter :: Value

    The parameter value should have the same "structure" as cp, except it _may_ also have big_map IDs. E.g. if the contract's parameter is pair (big_map string string) (big_map string string), then rcParameter may be one of:

    • pair (big_map string string) (big_map string string)
    • pair nat (big_map string string)
    • pair (big_map string string) nat
    • pair nat nat

    ... where nat represents a big_map ID.

  • rcStorage :: Value

    The storage value should have the same "structure" as st, except it _may_ also have big_map IDs. See the documentation of rcParameter.

  • rcAmount :: Mutez

    The value that will be returned by the AMOUNT instruction.

  • rcLevel :: Maybe Natural

    The value that will be returned by the LEVEL instruction.

  • rcNow :: Maybe Timestamp

    The value that will be returned by the NOW instruction.

  • rcBalance :: Mutez

    The balance that will be returned by the BALANCE instruction.

  • rcSource :: Maybe ImplicitAddress

    The value that will be returned by the SOURCE instruction.

data SomeTicket where Source #

Constructors

SomeTicket :: SingI t => Ticket (Value t) -> SomeTicket 

Instances

Instances details
Buildable SomeTicket Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

Methods

build :: SomeTicket -> Builder #

Eq SomeTicket Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

data ClevelandMiscImpl m Source #

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

Constructors

ClevelandMiscImpl 

Fields

data ClevelandOpsImpl m Source #

A record data type with operations creating primitives.

Constructors

ClevelandOpsImpl 

Fields

newtype DefaultAliasCounter Source #

Counter which is used to provide different default aliases.

data SpecificOrDefaultAlias Source #

An alias with default value that can be used to define unique alias automatically.

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.

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 

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 ClevelandResult Source #

Designates an operation result.

Instances

Instances details
OperationInfoDescriptor ClevelandResult Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

Associated Types

type TransferInfo ClevelandResult

type TransferTicketInfo ClevelandResult

type OriginationInfo ClevelandResult

type RevealInfo ClevelandResult

type DelegationInfo ClevelandResult

type DelegationInfo ClevelandResult Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

type DelegationInfo ClevelandResult = DelegationInfo Result
type OriginationInfo ClevelandResult Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

type OriginationInfo ClevelandResult = OriginationInfo Result
type RevealInfo ClevelandResult Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

type RevealInfo ClevelandResult = RevealInfo Result
type TransferInfo ClevelandResult Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

type TransferInfo ClevelandResult = [ContractEvent]
type TransferTicketInfo ClevelandResult Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

type TransferTicketInfo ClevelandResult = [ContractEvent]

data ContractEvent Source #

Data structure representing a contract event.

Constructors

ContractEvent 

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 TransferTicketInfo ClevelandInput

type OriginationInfo ClevelandInput

type RevealInfo ClevelandInput

type DelegationInfo ClevelandInput

type DelegationInfo ClevelandInput Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

type DelegationInfo ClevelandInput = Maybe KeyHash
type OriginationInfo ClevelandInput Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

type OriginationInfo ClevelandInput = SomeOriginateData 'NotLarge
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
type TransferTicketInfo ClevelandInput Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

type TransferTicketInfo ClevelandInput = TransferTicketData

data SomeOriginateData large where Source #

OriginateData existential over OriginationType.

Constructors

SomeOriginateData :: OriginateData oty large -> SomeOriginateData large 

newtype TypedContract cp st vd Source #

A wrapper around Contract to reduce awkwardness

Constructors

TypedContract (Contract (ToT cp) (ToT st)) 

Instances

Instances details
(NiceStorage st, NiceViewsDescriptor vd, NiceParameter cp) => ContractClass (TypedContract cp st vd) Source # 
Instance details

Defined in Test.Cleveland.Internal.Actions.Originate

Associated Types

type ContractOriginateType (TypedContract cp st vd) :: OriginationType Source #

type ContractOriginateType (TypedContract cp st vd) Source # 
Instance details

Defined in Test.Cleveland.Internal.Actions.Originate

data TransferTicketData Source #

Information about transfer operation.

Constructors

forall t addr.(WellTyped t, ToL1Address addr) => TransferTicketData 

Fields

  • ttdTo :: addr

    Receiver address for this transaction.

  • ttdEntrypoint :: EpName

    An entrypoint to be called.

  • ttdParameter :: Value ('TTicket t)

    Ticket and amount to transfer.

data TransferData Source #

Information about transfer operation.

Constructors

forall v addr.(NiceParameter v, ToL1Address 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.

data ODContractAndStorage oty where Source #

Constructors

ODContractAndStorageLorentz

Lorentz contract and storage.

Fields

  • :: { 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 OTUntyped origination type.

  •    } -> ODContractAndStorage ('OTTypedLorentz param st vd)
     
ODContractAndStorageUntyped

Untyped contract and storage.

Fields

ODContractAndStorageTyped

Typed Morley contract and storage.

Fields

data OriginateData oty large Source #

Data common for all origination types.

Constructors

OriginateData 

Fields

data LargeOrigination Source #

Whether this contract should be originated in a single origination operation or, if it goes over the origination size limit, in multiple operations.

Constructors

IsLarge 
NotLarge 

auto :: SpecificOrDefaultAlias Source #

Helper to use automatically determined unique alias.

data NetworkCaps m Source #

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

data EmulatedCaps m Source #

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

data ClevelandCaps m Source #

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

class NiceEntrypointName epName => EntrypointNameConstructor (epName :: Symbol) a where Source #

Methods

ep :: a Source #

A short partial constructor for EpName or EntrypointRef. It accepts a type-level string as its type argument. The programmer is responsible for validity. And this code is for tests anyway, so each failure is a programmer mistake.

Note that entrypoint names should be capitalized, e.g.

ep @"Entrypoint"

corresponds to entrypoint, etc.

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

For EpName, an instance is provided accepting a value-level Text instead of a type-level symbol. This is mostly for cases where the type-level symbol doesn't work. Note that value-level string will be used verbatim, hence capitalization is arbitrary.

ep "entrypoint"

Instances

Instances details
NiceEntrypointName epName => EntrypointNameConstructor epName EpName Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

Methods

ep :: EpName Source #

(NiceEntrypointName epName, mname ~ 'Just epName) => EntrypointNameConstructor epName (EntrypointRef mname) Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

Methods

ep :: EntrypointRef mname Source #

(any ~ "", t ~ Text) => EntrypointNameConstructor any (t -> EpName) Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

Methods

ep :: t -> EpName Source #

data TransferFailureReason Source #

Constructors

FailedWith ExpressionOrTypedValue (Maybe ErrorSrcPos)

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

newtype ClevelandOpsBatch a Source #

Where the batched operations occur.

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

Constructors

ClevelandOpsBatch 

Fields

Instances

Instances details
Applicative ClevelandOpsBatch Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

Functor ClevelandOpsBatch Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

(Bottom, 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

MonadOpsInternal ClevelandOpsBatch Source # 
Instance details

Defined in Test.Cleveland.Internal.Actions.MonadOpsInternal

(SingI emit, DoTransfer mode, a ~ FTransferResult emit) => TransferFunc mode emit am (ClevelandOpsBatch a) Source #

The terminating case for batched transfer

Instance details

Defined in Test.Cleveland.Internal.Actions.Transfer

TerminatingOFConstraints ct props ClevelandOpsBatch a => OriginateFunc ct props (ClevelandOpsBatch a) Source #

The terminating case for batched transfer.

Instance details

Defined in Test.Cleveland.Internal.Actions.Originate

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

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 ClevelandResult) 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 ClevelandResult -> Maybe a) -> m a Source #

Helper that runs a single operation using ClevelandOpsImpl.

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.

type NetworkT m = ReaderT (NetworkCaps m) m Source #

Monad transformer that adds both ClevelandCaps and NetworkCaps capabilities.

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

Monad transformer that adds both ClevelandCaps and EmulatedCaps capabilities.

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

Monad transformer that adds only the ClevelandCaps capabilities.

type MonadNetwork caps m = (MonadCleveland caps m, HasNetworkCaps caps) Source #

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

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 EmulatedCaps capability.

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

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

class HasClevelandCaps caps => HasNetworkCaps caps where Source #

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

Instances

Instances details
Monad m => HasNetworkCaps (NetworkCaps m) Source # 
Instance details

Defined in Test.Cleveland.Internal.Abstract

class HasClevelandCaps caps => HasEmulatedCaps caps where Source #

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

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.