Module

Contract.Test.Assert

#ContractAssertion

type ContractAssertion (a :: Type) = ReaderT (Ref (List ContractAssertionFailure)) Contract a

Monad allowing for accumulation of assertion failures.

#ContractCheck

type ContractCheck a = ContractAssertion a -> ContractAssertion ((ContractAssertion a) /\ (ContractAssertion Unit))

A check that can run some initialization code before the Contract is run and check the results afterwards. It is used to implement assertions that require state monitoring, e.g. checking gains at address.

#ExpectedActual

#Label

type Label = String

#Labeled

data Labeled (a :: Type)

Constructors

Instances

#assertContractEqual

assertContractEqual :: forall (a :: Type). Eq a => Show a => a -> a -> ContractAssertion Unit

#assertContractExpectedActual

#assertContractMaybe

#assertNewUtxosAtAddress

assertNewUtxosAtAddress :: forall (a :: Type). Labeled Address -> TransactionHash -> (Array TransactionOutput -> ContractAssertion a) -> ContractAssertion a

Assert some property of address UTxOs created by a Transaction.

#assertNewUtxosInWallet

assertNewUtxosInWallet :: forall (a :: Type). TransactionHash -> (Array TransactionOutput -> ContractAssertion a) -> ContractAssertion a

Assert some property of wallet UTxOs created by a Transaction.

#assertOutputHasDatum

assertOutputHasDatum :: Maybe OutputDatum -> Labeled TransactionOutput -> ContractAssertion Unit

Requires that the transaction output contains the specified datum, datum hash or does not contain anything.

#assertOutputHasRefScript

assertOutputHasRefScript :: ScriptRef -> Labeled TransactionOutput -> ContractAssertion Unit

Requires that the transaction output contains the specified reference script.

#assertTxHasMetadata

assertTxHasMetadata :: forall (metadata :: Type) (a :: Type). MetadataType metadata => Eq metadata => Show metadata => Label -> TransactionHash -> metadata -> ContractAssertion Unit

#assertionToCheck

assertionToCheck :: forall (a :: Type). String -> (a -> ContractAssertion Unit) -> ContractCheck a

Create a check that simply asserts something about a Contract result.

If a Contract throws an exception, the assertion is never checked, because the result is never computed. In this case, a warning will be printed, containing the given description.

#checkExUnitsNotExceed

checkExUnitsNotExceed :: forall (a :: Type). ExUnits -> ContractCheck a

Sets a limit on ExUnits budget. All ExUnits values of all submitted transactions are combined. Transactions that are constructed, but not submitted, are not considered. The execution of the Contract will not be interrupted in case the ExUnits limit is reached.

#checkGainAtAddress

checkGainAtAddress :: forall (a :: Type). Labeled Address -> (Maybe a -> Contract BigInt) -> ContractCheck a

Requires that the computed amount of lovelace was gained at the address by calling the contract.

#checkGainAtAddress'

checkGainAtAddress' :: forall (a :: Type). Labeled Address -> BigInt -> ContractCheck a

Requires that the passed amount of lovelace was gained at the address by calling the contract.

#checkGainInWallet

checkGainInWallet :: forall (a :: Type). (Maybe a -> Contract BigInt) -> ContractCheck a

Requires that the computed amount of lovelace was gained in the wallet by calling the contract.

#checkGainInWallet'

checkGainInWallet' :: forall (a :: Type). BigInt -> ContractCheck a

Requires that the passed amount of lovelace was gained in the wallet by calling the contract.

#checkLossAtAddress

checkLossAtAddress :: forall (a :: Type). Labeled Address -> (Maybe a -> Contract BigInt) -> ContractCheck a

Requires that the computed amount of lovelace was lost at the address by calling the contract.

#checkLossAtAddress'

checkLossAtAddress' :: forall (a :: Type). Labeled Address -> BigInt -> ContractCheck a

Requires that the passed amount of lovelace was lost at the address by calling the contract.

#checkLossInWallet

checkLossInWallet :: forall (a :: Type). (Maybe a -> Contract BigInt) -> ContractCheck a

Requires that the computed amount of lovelace was lost in the wallet by calling the contract.

#checkLossInWallet'

checkLossInWallet' :: forall (a :: Type). BigInt -> ContractCheck a

Requires that the passed amount of lovelace was lost in the wallet by calling the contract.

#checkLovelaceDeltaAtAddress

#checkLovelaceDeltaInWallet

#checkTokenDeltaAtAddress

#checkTokenDeltaInWallet

#checkTokenGainAtAddress

checkTokenGainAtAddress :: forall (a :: Type). Labeled Address -> (ScriptHash /\ AssetName) -> (Maybe a -> Contract BigInt) -> ContractCheck a

Requires that the computed number of tokens was gained at the address by calling the contract.

#checkTokenGainAtAddress'

checkTokenGainAtAddress' :: forall (a :: Type). Labeled Address -> (ScriptHash /\ AssetName /\ BigInt) -> ContractCheck a

Requires that the passed number of tokens was gained at the address by calling the contract.

#checkTokenGainInWallet

checkTokenGainInWallet :: forall (a :: Type). (ScriptHash /\ AssetName) -> (Maybe a -> Contract BigInt) -> ContractCheck a

Requires that the computed number of tokens was gained in the wallet by calling the contract.

#checkTokenGainInWallet'

checkTokenGainInWallet' :: forall (a :: Type). (ScriptHash /\ AssetName /\ BigInt) -> ContractCheck a

Requires that the passed number of tokens was gained in the wallet by calling the contract.

#checkTokenLossAtAddress

checkTokenLossAtAddress :: forall (a :: Type). Labeled Address -> (ScriptHash /\ AssetName) -> (Maybe a -> Contract BigInt) -> ContractCheck a

Requires that the computed number of tokens was lost at the address by calling the contract.

#checkTokenLossAtAddress'

checkTokenLossAtAddress' :: forall (a :: Type). Labeled Address -> (ScriptHash /\ AssetName /\ BigInt) -> ContractCheck a

Requires that the passed number of tokens was lost at the address by calling the contract.

#checkTokenLossInWallet

checkTokenLossInWallet :: forall (a :: Type). (ScriptHash /\ AssetName) -> (Maybe a -> Contract BigInt) -> ContractCheck a

Requires that the computed number of tokens was lost in the wallet by calling the contract.

#checkTokenLossInWallet'

checkTokenLossInWallet' :: forall (a :: Type). (ScriptHash /\ AssetName /\ BigInt) -> ContractCheck a

Requires that the passed number of tokens was lost in the wallet by calling the contract.

#checkValueDeltaAtAddress

checkValueDeltaAtAddress :: forall (a :: Type). Labeled Address -> (Maybe a -> Value -> Value -> ContractAssertion Unit) -> ContractCheck a

Arguments are:

  • a labeled address
  • a callback that implements the assertion, accepting Contract execution result, and values (before and after). The value may not be computed due to an exception, hence it's wrapped in Maybe.

#checkValueDeltaInWallet

checkValueDeltaInWallet :: forall (a :: Type). (Maybe a -> Value -> Value -> ContractAssertion Unit) -> ContractCheck a

Accepts a callback that implements the assetion. The result value of type a may not be computed due to an exception, hence it's wrapped in Maybe.

#collectAssertionFailures

collectAssertionFailures :: forall (a :: Type). Array (ContractCheck a) -> ContractAssertion a -> Contract ((Either Error a) /\ (Array ContractAssertionFailure))

Like runChecks, but does not throw a user-readable report, collecting the exceptions instead.

#label

label :: forall (a :: Type). a -> Label -> Labeled a

#noLabel

noLabel :: forall (a :: Type). a -> Labeled a

#printContractAssertionFailure

printContractAssertionFailure :: ContractAssertionFailure -> String

Pretty printing function that produces a human readable report for a single ContractAssertionFailure

#printContractAssertionFailures

printContractAssertionFailures :: Array ContractAssertionFailure -> String

A pretty-printing function that produces a human-readable report on failures.

#printExpectedActual

printExpectedActual :: forall (a :: Type). Show a => ExpectedActual a -> String

#printLabeled

printLabeled :: forall (a :: Type). Show a => Labeled a -> String

#runChecks

runChecks :: forall (a :: Type). Array (ContractCheck a) -> ContractAssertion a -> Contract a

Accepts an array of checks and interprets them into a Contract.

#unlabel

unlabel :: forall (a :: Type). Labeled a -> a

Modules