11
11
{-# LANGUAGE StandaloneDeriving #-}
12
12
{-# LANGUAGE TypeFamilies #-}
13
13
{-# LANGUAGE UndecidableInstances #-}
14
- {-# OPTIONS_GHC -Wno-orphans #-}
15
14
16
15
module Test.Ouroboros.Storage.PerasCertDB.StateMachine (tests ) where
17
16
@@ -44,15 +43,14 @@ prop_qd actions = QC.monadic f $ property () <$ runActions actions
44
43
f :: StateT (PerasCertDB IO TestBlock ) IO Property -> Property
45
44
f = ioProperty . flip evalStateT (error " unreachable" )
46
45
47
- type Block = TestBlock
48
- newtype Model = Model (Model. Model Block ) deriving (Show , Generic )
46
+ newtype Model = Model (Model. Model TestBlock ) deriving (Show , Generic )
49
47
50
48
instance StateModel Model where
51
49
data Action Model a where
52
50
OpenDB :: Action Model ()
53
51
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 )
56
54
57
55
arbitraryAction _ (Model model)
58
56
| model. open =
@@ -65,9 +63,18 @@ instance StateModel Model where
65
63
where
66
64
genAddCert = do
67
65
pcCertRound <- PerasRoundNo <$> arbitrary
68
- pcCertBoostedBlock <- arbitrary
66
+ pcCertBoostedBlock <- genPoint
69
67
pure $ AddCert PerasCert {pcCertRound, pcCertBoostedBlock}
70
68
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
+
71
78
initialState = Model Model. initModel
72
79
73
80
nextState (Model model) action _ = Model $ case action of
@@ -81,6 +88,7 @@ instance StateModel Model where
81
88
action ->
82
89
model. open && case action of
83
90
CloseDB -> True
91
+ -- Do not add equivocating certificates.
84
92
AddCert cert -> all p model. certs
85
93
where
86
94
p cert' = perasCertRound cert /= perasCertRound cert' || cert == cert'
@@ -107,18 +115,9 @@ instance RunModel Model (StateT (PerasCertDB IO TestBlock) IO) where
107
115
perasCertDB <- get
108
116
lift $ atomically $ PerasCertDB. getWeightSnapshot perasCertDB
109
117
110
- -- TODO: check open state consistency
111
118
postcondition (Model model, _) GetWeightSnapshot _ actual = do
112
119
let expected = Model. getWeightSnapshot model
113
120
counterexamplePost $ " Model: " <> show expected
114
121
counterexamplePost $ " SUT: " <> show actual
115
122
pure $ expected == actual
116
123
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