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

Commit a6868cd

Browse files
authored
add property to sanity check model (#114)
checking that balances sometimes change
1 parent 0709726 commit a6868cd

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

plutus-contract/src/Plutus/Contract/Test/ContractModel.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ module Plutus.Contract.Test.ContractModel
9696
, SchemaConstraints
9797
, ContractInstanceSpec(..)
9898
, HandleFun
99+
-- ** Model properties
100+
, propSanityCheckModel
99101
-- ** Emulator properties
100102
, propRunActions_
101103
, propRunActions
@@ -1111,6 +1113,12 @@ checkNoCrashes = foldr (\ (ContractInstanceSpec k w c) -> (assertOutcome c (inst
11111113
notError Done{} = True
11121114
notError NotDone{} = True
11131115

1116+
-- | Sanity check a `ContractModel`. Ensures that wallet balances are not always unchanged.
1117+
propSanityCheckModel :: forall state. ContractModel state => Property
1118+
propSanityCheckModel = QC.expectFailure $ noBalanceChanges . stateAfter @state
1119+
where
1120+
noBalanceChanges s = all isZero (s ^. balanceChanges)
1121+
11141122
-- $noLockedFunds
11151123
-- Showing that funds can not be locked in the contract forever.
11161124

plutus-use-cases/test/Spec/GameStateMachine.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module Spec.GameStateMachine
1919
, prop_Game, propGame', prop_GameWhitelist
2020
, prop_NoLockedFunds
2121
, prop_CheckNoLockedFundsProof
22+
, prop_SanityCheckModel
2223
) where
2324

2425
import Control.Lens
@@ -171,6 +172,9 @@ prop_Game = propRunActions_ handleSpec
171172
prop_GameWhitelist :: Actions GameModel -> Property
172173
prop_GameWhitelist = checkErrorWhitelist handleSpec defaultWhitelist
173174

175+
prop_SanityCheckModel :: Property
176+
prop_SanityCheckModel = propSanityCheckModel @GameModel
177+
174178
propGame' :: LogLevel -> Actions GameModel -> Property
175179
propGame' l = propRunActionsWithOptions
176180
(set minLogLevel l defaultCheckOptions)
@@ -293,6 +297,9 @@ tests =
293297

294298
, testProperty "can always get the funds out" $
295299
withMaxSuccess 10 prop_NoLockedFunds
300+
301+
, testProperty "sanity check the contract model" $
302+
prop_SanityCheckModel
296303
]
297304

298305
initialVal :: Value

0 commit comments

Comments
 (0)