Skip to content

Commit d795fb3

Browse files
committed
Minor polishing
- Avoid orphans - We actually can't check that the open states are consistent directly as we would need to statefully get that info from the SUT.
1 parent 3669032 commit d795fb3

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ module Test.Ouroboros.Storage (tests) where
55
import qualified Test.Ouroboros.Storage.ChainDB as ChainDB
66
import qualified Test.Ouroboros.Storage.ImmutableDB as ImmutableDB
77
import qualified Test.Ouroboros.Storage.LedgerDB as LedgerDB
8-
import qualified Test.Ouroboros.Storage.VolatileDB as VolatileDB
98
import qualified Test.Ouroboros.Storage.PerasCertDB as PerasCertDB
10-
9+
import qualified Test.Ouroboros.Storage.VolatileDB as VolatileDB
1110
import Test.Tasty (TestTree, testGroup)
1211

1312
--

ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/PerasCertDB/StateMachine.hs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
{-# LANGUAGE StandaloneDeriving #-}
1212
{-# LANGUAGE TypeFamilies #-}
1313
{-# LANGUAGE UndecidableInstances #-}
14-
{-# OPTIONS_GHC -Wno-orphans #-}
1514

1615
module Test.Ouroboros.Storage.PerasCertDB.StateMachine (tests) where
1716

@@ -44,15 +43,14 @@ prop_qd actions = QC.monadic f $ property () <$ runActions actions
4443
f :: StateT (PerasCertDB IO TestBlock) IO Property -> Property
4544
f = ioProperty . flip evalStateT (error "unreachable")
4645

47-
type Block = TestBlock
48-
newtype Model = Model (Model.Model Block) deriving (Show, Generic)
46+
newtype Model = Model (Model.Model TestBlock) deriving (Show, Generic)
4947

5048
instance StateModel Model where
5149
data Action Model a where
5250
OpenDB :: Action Model ()
5351
CloseDB :: Action Model ()
54-
AddCert :: PerasCert Block -> Action Model ()
55-
GetWeightSnapshot :: Action Model (PerasWeightSnapshot Block)
52+
AddCert :: PerasCert TestBlock -> Action Model ()
53+
GetWeightSnapshot :: Action Model (PerasWeightSnapshot TestBlock)
5654

5755
arbitraryAction _ (Model model)
5856
| model.open =
@@ -65,9 +63,18 @@ instance StateModel Model where
6563
where
6664
genAddCert = do
6765
pcCertRound <- PerasRoundNo <$> arbitrary
68-
pcCertBoostedBlock <- arbitrary
66+
pcCertBoostedBlock <- genPoint
6967
pure $ AddCert PerasCert{pcCertRound, pcCertBoostedBlock}
7068

69+
genPoint :: Gen (Point TestBlock)
70+
genPoint =
71+
oneof
72+
[ return GenesisPoint
73+
, BlockPoint <$> (SlotNo <$> arbitrary) <*> genHash
74+
]
75+
where
76+
genHash = TestHash . NE.fromList . getNonEmpty <$> arbitrary
77+
7178
initialState = Model Model.initModel
7279

7380
nextState (Model model) action _ = Model $ case action of
@@ -81,6 +88,7 @@ instance StateModel Model where
8188
action ->
8289
model.open && case action of
8390
CloseDB -> True
91+
-- Do not add equivocating certificates.
8492
AddCert cert -> all p model.certs
8593
where
8694
p cert' = perasCertRound cert /= perasCertRound cert' || cert == cert'
@@ -107,18 +115,9 @@ instance RunModel Model (StateT (PerasCertDB IO TestBlock) IO) where
107115
perasCertDB <- get
108116
lift $ atomically $ PerasCertDB.getWeightSnapshot perasCertDB
109117

110-
-- TODO: check open state consistency
111118
postcondition (Model model, _) GetWeightSnapshot _ actual = do
112119
let expected = Model.getWeightSnapshot model
113120
counterexamplePost $ "Model: " <> show expected
114121
counterexamplePost $ "SUT: " <> show actual
115122
pure $ expected == actual
116123
postcondition _ _ _ _ = pure True
117-
118-
-- TODO very ugly
119-
instance Arbitrary (Point TestBlock) where
120-
arbitrary =
121-
oneof
122-
[ return GenesisPoint
123-
, BlockPoint <$> (SlotNo <$> arbitrary) <*> (TestHash . NE.fromList . getNonEmpty <$> arbitrary)
124-
]

0 commit comments

Comments
 (0)