Skip to content

Commit

Permalink
Merge pull request #367 from input-output-hk/jonathanknowles/db-qsm-t…
Browse files Browse the repository at this point in the history
…ag-coverage

Make DB QSM tests fail if one or more tags are not covered.
  • Loading branch information
rvl authored Jun 5, 2019
2 parents d7e6fd6 + 5793aa4 commit 9b4bca2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/core/cardano-wallet-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ test-suite unit
, containers
, cryptonite
, deepseq
, extra >= 1.6.17
, file-embed
, fmt
, foldl
Expand Down
23 changes: 20 additions & 3 deletions lib/core/test/unit/Cardano/Wallet/DB/StateMachine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ import Crypto.Hash
import Data.Bifunctor
( bimap, first )
import Data.Foldable
( toList )
( foldl', toList )
import Data.Functor.Classes
( Eq1, Show1 )
import Data.List.Extra
( enumerate )
import Data.Map
( Map )
import Data.Maybe
Expand Down Expand Up @@ -640,7 +642,11 @@ data Tag
-- ^ Private key was written then read.
| ReadTxHistoryAfterDelete
-- ^ wallet deleted, then tx history read.
deriving (Show)
deriving (Bounded, Enum, Eq, Ord, Show)

-- | The list of all possible 'Tag' values.
allTags :: [Tag]
allTags = enumerate

tag :: [Event Symbolic] -> [Tag]
tag = Foldl.fold $ catMaybes <$> sequenceA
Expand Down Expand Up @@ -854,13 +860,24 @@ repeatedly = flip . L.foldl' . flip

prop_sequential :: DBLayerTest -> Property
prop_sequential db =
QC.checkCoverage $
forAllCommands (sm dbLayerUnused) Nothing $ \cmds ->
monadicIO $ do
liftIO $ cleanDB db
let sm' = sm db
(hist, _model, res) <- runCommands sm' cmds
prettyCommands sm' hist $ res === Ok
prettyCommands sm' hist
$ measureTagCoverage cmds
$ res === Ok
where
measureTagCoverage :: Commands (At Cmd) (At Resp) -> Property -> Property
measureTagCoverage cmds prop = foldl' measureTag prop allTags
where
measureTag :: Property -> Tag -> Property
measureTag p t = QC.cover 5 (t `Set.member` matchedTags) (show t) p

matchedTags :: Set Tag
matchedTags = Set.fromList $ tag $ execCmds cmds

prop_parallel :: DBLayerTest -> Property
prop_parallel db =
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resolver: lts-13.8
resolver: lts-13.24
packages:
- .
- lib/bech32
Expand Down

0 comments on commit 9b4bca2

Please sign in to comment.