Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
add property to sanity check model (#114)
Browse files Browse the repository at this point in the history
checking that balances sometimes change
  • Loading branch information
UlfNorell authored Nov 22, 2021
1 parent 0709726 commit a6868cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions plutus-contract/src/Plutus/Contract/Test/ContractModel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ module Plutus.Contract.Test.ContractModel
, SchemaConstraints
, ContractInstanceSpec(..)
, HandleFun
-- ** Model properties
, propSanityCheckModel
-- ** Emulator properties
, propRunActions_
, propRunActions
Expand Down Expand Up @@ -1111,6 +1113,12 @@ checkNoCrashes = foldr (\ (ContractInstanceSpec k w c) -> (assertOutcome c (inst
notError Done{} = True
notError NotDone{} = True

-- | Sanity check a `ContractModel`. Ensures that wallet balances are not always unchanged.
propSanityCheckModel :: forall state. ContractModel state => Property
propSanityCheckModel = QC.expectFailure $ noBalanceChanges . stateAfter @state
where
noBalanceChanges s = all isZero (s ^. balanceChanges)

-- $noLockedFunds
-- Showing that funds can not be locked in the contract forever.

Expand Down
7 changes: 7 additions & 0 deletions plutus-use-cases/test/Spec/GameStateMachine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Spec.GameStateMachine
, prop_Game, propGame', prop_GameWhitelist
, prop_NoLockedFunds
, prop_CheckNoLockedFundsProof
, prop_SanityCheckModel
) where

import Control.Lens
Expand Down Expand Up @@ -171,6 +172,9 @@ prop_Game = propRunActions_ handleSpec
prop_GameWhitelist :: Actions GameModel -> Property
prop_GameWhitelist = checkErrorWhitelist handleSpec defaultWhitelist

prop_SanityCheckModel :: Property
prop_SanityCheckModel = propSanityCheckModel @GameModel

propGame' :: LogLevel -> Actions GameModel -> Property
propGame' l = propRunActionsWithOptions
(set minLogLevel l defaultCheckOptions)
Expand Down Expand Up @@ -293,6 +297,9 @@ tests =

, testProperty "can always get the funds out" $
withMaxSuccess 10 prop_NoLockedFunds

, testProperty "sanity check the contract model" $
prop_SanityCheckModel
]

initialVal :: Value
Expand Down

0 comments on commit a6868cd

Please sign in to comment.