plutus-contract-0.1.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) 

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.

assertFailedTransaction :: (Tx -> ValidationError -> [ScriptValidationEvent] -> Bool) -> TracePredicate Source #

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

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

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

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

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

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 :: Address -> (Value -> Bool) -> TracePredicate Source #

Check that the funds at an address meet some condition.

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

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

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

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 

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

checkPredicateInner Source #

Arguments

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

Print out debug information in case of test failures

-> (Bool -> m ())

assert

-> (CoverageReport -> m ()) 
-> m () 

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

checkPredicateInnerStream Source #

Arguments

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

Print out debug information in case of test failures

-> (Bool -> m ())

assert

-> (CoverageReport -> m ()) 
-> m () 

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

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

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

Etc

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

Compare a golden PIR file to the provided CompiledCode.