plutus-contract-1.2.0.0
Safe HaskellNone
LanguageHaskell2010

Plutus.Contract.Test

Description

Testing contracts with HUnit and Tasty

Synopsis

Documentation

newtype TracePredicateF a Source #

Constructors

TracePredicate (forall effs. Members TestEffects effs => FoldM (Eff effs) EmulatorEvent a) 

type ContractConstraints s = (Forall (Output s) Unconstrained1, Forall (Input s) Unconstrained1, AllUniqueLabels (Input s), AllUniqueLabels (Output s), Forall (Input s) FromJSON, Forall (Input s) ToJSON, Forall (Output s) FromJSON, Forall (Output s) ToJSON) Source #

Assertions

assertDone :: forall contract w s e a. (Monoid w, IsContract contract) => contract w s e a -> ContractInstanceTag -> (a -> Bool) -> String -> TracePredicate Source #

A TracePredicate checking that the wallet's contract instance finished without errors.

assertNotDone :: forall contract w s e a. (Monoid w, IsContract contract) => contract w s e a -> ContractInstanceTag -> String -> TracePredicate Source #

A TracePredicate checking that the wallet's contract instance is waiting for input.

assertContractError :: forall contract w s e a. (Monoid w, IsContract contract) => contract w s e a -> ContractInstanceTag -> (e -> Bool) -> String -> TracePredicate Source #

A TracePredicate checking that the wallet's contract instance failed with an error.

data Outcome e a Source #

Constructors

Done a

The contract finished without errors and produced a result

NotDone

The contract is waiting for more input.

Failed e

The contract failed with an error.

Instances

Instances details
(Eq a, Eq e) => Eq (Outcome e a) Source # 
Instance details

Defined in Wallet.Emulator.Folds

Methods

(==) :: Outcome e a -> Outcome e a -> Bool Source #

(/=) :: Outcome e a -> Outcome e a -> Bool Source #

(Show a, Show e) => Show (Outcome e a) Source # 
Instance details

Defined in Wallet.Emulator.Folds

Methods

showsPrec :: Int -> Outcome e a -> ShowS Source #

show :: Outcome e a -> String Source #

showList :: [Outcome e a] -> ShowS Source #

assertOutcome :: forall contract w s e a. (Monoid w, IsContract contract) => contract w s e a -> ContractInstanceTag -> (Outcome e a -> Bool) -> String -> TracePredicate Source #

assertNoFailedTransactions :: TracePredicate Source #

Assert that no transaction failed to validate.

assertValidatedTransactionCount :: Int -> TracePredicate Source #

Assert that n transactions validated, and no transaction failed to validate.

assertValidatedTransactionCountOfTotal :: Int -> Int -> TracePredicate Source #

Assert that n transactions validated, and the rest failed.

assertFailedTransaction :: (CardanoTx -> ValidationError -> Bool) -> TracePredicate Source #

Assert that at least one transaction failed to validate, and that all transactions that failed meet the predicate.

assertEvaluationError :: Text -> TracePredicate Source #

Assert that at least one transaction failed to validate with an EvaluationError containing the given text.

assertHooks :: forall w s e a. Monoid w => Contract w s e a -> ContractInstanceTag -> ([PABReq] -> Bool) -> String -> TracePredicate Source #

assertResponses :: forall w s e a. Monoid w => Contract w s e a -> ContractInstanceTag -> ([Response PABResp] -> Bool) -> String -> TracePredicate Source #

Make an assertion about the responses provided to the contract instance.

assertBlockchain :: ([Block] -> Bool) -> TracePredicate Source #

An assertion about the blockchain

assertChainEvents :: ([ChainEvent] -> Bool) -> TracePredicate Source #

An assertion about the chain events

assertChainEvents' :: ([ChainEvent] -> String) -> ([ChainEvent] -> Bool) -> TracePredicate Source #

An assertion about the chain events with a custom error message

assertAccumState :: forall contract w s e a. (Monoid w, Show w, IsContract contract) => contract w s e a -> ContractInstanceTag -> (w -> Bool) -> String -> TracePredicate Source #

Make an assertion about the accumulated state w of a contract instance.

assertResumableResult :: forall w s e a. (Monoid w, Show e, Show a, Show w) => Contract w s e a -> ContractInstanceTag -> Shrinking -> (ResumableResult w e PABResp PABReq a -> Bool) -> String -> TracePredicate Source #

make an assertion about the ContractInstanceState of a contract instance

assertUnbalancedTx :: forall w s e a. Monoid w => Contract w s e a -> ContractInstanceTag -> (UnbalancedTx -> Bool) -> String -> TracePredicate Source #

assertEvents :: forall w s e a. Monoid w => Contract w s e a -> ContractInstanceTag -> ([PABResp] -> Bool) -> String -> TracePredicate Source #

walletFundsChangePlutus :: Wallet -> Value -> TracePredicate Source #

Check that the funds in the wallet have changed by the given amount, exluding fees, using the Plutus Value type.

walletFundsChange :: Wallet -> Value -> TracePredicate Source #

Check that the funds in the wallet have changed by the given amount, exluding fees.

walletFundsExactChange :: Wallet -> Value -> TracePredicate Source #

Check that the funds in the wallet have changed by the given amount, including fees.

waitingForSlot :: forall w s e a. Monoid w => Contract w s e a -> ContractInstanceTag -> Slot -> TracePredicate Source #

valueAtAddress :: CardanoAddress -> (Value -> Bool) -> TracePredicate Source #

Check that the funds at an address meet some condition.

plutusValueAtAddress :: CardanoAddress -> (Value -> Bool) -> TracePredicate Source #

dataAtAddress :: forall d. FromData d => CardanoAddress -> ([d] -> Bool) -> TracePredicate Source #

reasonable :: Validator -> Integer -> Assertion Source #

Assert that the size of a Validator is below the maximum.

reasonable' :: (String -> IO ()) -> Validator -> Integer -> Assertion Source #

Checking predicates

checkPredicate Source #

Arguments

:: String

Descriptive name of the test

-> TracePredicate

The predicate to check

-> EmulatorTrace () 
-> TestTree 

Check if the emulator trace meets the condition

checkPredicateCoverage Source #

Arguments

:: String

Descriptive name of the test

-> CoverageRef 
-> TracePredicate

The predicate to check

-> EmulatorTrace () 
-> TestTree 

checkPredicateCoverageOptions Source #

Arguments

:: CheckOptions

Options to use

-> String

Descriptive name of the test

-> CoverageRef 
-> TracePredicate

The predicate to check

-> EmulatorTrace () 
-> TestTree 

checkPredicateOptions Source #

Arguments

:: CheckOptions

Options to use

-> String

Descriptive name of the test

-> TracePredicate

The predicate to check

-> EmulatorTrace () 
-> TestTree 

A version of checkPredicate with configurable CheckOptions

checkPredicateGen :: GeneratorModel -> TracePredicate -> EmulatorTrace () -> Property Source #

Check if the emulator trace meets the condition, using the GeneratorModel to generate initial transactions for the blockchain

checkPredicateGenOptions :: CheckOptions -> GeneratorModel -> TracePredicate -> EmulatorTrace () -> Property Source #

A version of checkPredicateGen with configurable CheckOptions.

Note that the InitialChainState in the EmulatorConfig of the CheckOptions will be replaced with the mockchainInitialTxPool generated by the model.

checkPredicateInner Source #

Arguments

:: forall m a. Monad m 
=> CheckOptions 
-> TracePredicate 
-> EmulatorTrace a 
-> (String -> m ())

Print out debug information in case of test failures TODO: can we generalize Bool here? We need it to get extractPropertyResult to work

-> (Bool -> m ())

assert

-> (CoverageData -> m ()) 
-> m (Either EmulatorErr a) 

Evaluate a trace predicate on an emulator trace, printing out debug information and making assertions as we go.

checkPredicateInnerStream Source #

Arguments

:: forall m a. Monad m 
=> CheckOptions 
-> TracePredicate 
-> (forall effs. Stream (Of (LogMessage EmulatorEvent)) (Eff effs) (Either EmulatorErr a)) 
-> (String -> m ())

Print out debug information in case of test failures

-> (Bool -> m ())

assert

-> (CoverageData -> m ()) 
-> m (Either EmulatorErr a) 

checkEmulatorFails Source #

Arguments

:: String

Descriptive name of the test

-> CheckOptions 
-> TracePredicate 
-> EmulatorTrace ()

The trace that should fail

-> TestTree 

Check if the emulator trace fails with the condition

data CheckOptions Source #

Options for running the

Constructors

CheckOptions 

Fields

minLogLevel :: Lens' CheckOptions LogLevel Source #

changeInitialWalletValue :: Wallet -> (Value -> Value) -> CheckOptions -> CheckOptions Source #

Modify the value assigned to the given wallet in the initial distribution.

increaseTransactionLimits :: CheckOptions -> CheckOptions Source #

Set higher limits on transaction size and execution units. This can be used to work around MaxTxSizeUTxO and ExUnitsTooBigUTxO errors. Note that if you need this your Plutus script will probably not validate on Mainnet.

Etc

goldenPir :: FilePath -> CompiledCode a -> TestTree Source #

Compare a golden PIR file to the provided CompiledCode.