@@ -271,6 +271,8 @@ instance HasVariables (BT.NonZero Word64) where
271
271
getAllVariables _ = mempty
272
272
273
273
instance StateModel Model where
274
+ type Error Model = LedgerDBError
275
+
274
276
data Action Model a where
275
277
WipeLedgerDB :: Action Model ()
276
278
TruncateSnapshots :: Action Model ()
@@ -302,7 +304,13 @@ instance StateModel Model where
302
304
min
303
305
(fromIntegral . AS. length $ chain)
304
306
(BT. unNonZero $ maxRollbacks secParam)
305
- numRollback <- QC. choose (0 , maxRollback)
307
+ numRollback <-
308
+ frequency
309
+ [ (10 , QC. choose (0 , maxRollback))
310
+ , -- Sometimes generate invalid 'ValidateAndCommit's for
311
+ -- negative testing.
312
+ (1 , QC. choose (maxRollback + 1 , maxRollback + 5 ))
313
+ ]
306
314
numNewBlocks <- QC. choose (numRollback, numRollback + 2 )
307
315
let
308
316
chain' = case modelRollback numRollback model of
@@ -371,6 +379,9 @@ instance StateModel Model where
371
379
precondition _ Init {} = False
372
380
precondition _ _ = True
373
381
382
+ validFailingAction Model {} ValidateAndCommit {} = True
383
+ validFailingAction _ _ = False
384
+
374
385
{- ------------------------------------------------------------------------------
375
386
Mocked ChainDB
376
387
-------------------------------------------------------------------------------}
@@ -527,22 +538,27 @@ data Environment
527
538
(IO NumOpenHandles )
528
539
(IO () )
529
540
541
+ data LedgerDBError = ErrorValidateExceededRollback
542
+
530
543
instance RunModel Model (StateT Environment IO ) where
531
544
perform _ (Init secParam) _ = do
532
545
Environment _ _ chainDb mkArgs fs _ cleanup <- get
533
546
(ldb, testInternals, getNumOpenHandles) <- lift $ do
534
547
let args = mkArgs secParam
535
548
openLedgerDB (argFlavorArgs args) chainDb (argLedgerDbCfg args) fs
536
549
put (Environment ldb testInternals chainDb mkArgs fs getNumOpenHandles cleanup)
550
+ pure $ pure ()
537
551
perform _ WipeLedgerDB _ = do
538
552
Environment _ testInternals _ _ _ _ _ <- get
539
553
lift $ wipeLedgerDB testInternals
554
+ pure $ pure ()
540
555
perform _ GetState _ = do
541
556
Environment ldb _ _ _ _ _ _ <- get
542
- lift $ atomically $ (,) <$> getImmutableTip ldb <*> getVolatileTip ldb
557
+ lift $ fmap pure $ atomically $ (,) <$> getImmutableTip ldb <*> getVolatileTip ldb
543
558
perform _ ForceTakeSnapshot _ = do
544
559
Environment _ testInternals _ _ _ _ _ <- get
545
560
lift $ takeSnapshotNOW testInternals TakeAtImmutableTip Nothing
561
+ pure $ pure ()
546
562
perform _ (ValidateAndCommit n blks) _ = do
547
563
Environment ldb _ chainDb _ _ _ _ <- get
548
564
lift $ do
@@ -558,7 +574,8 @@ instance RunModel Model (StateT Environment IO) where
558
574
(reverse (map blockRealPoint blks) ++ ) . drop (fromIntegral n)
559
575
atomically (forkerCommit forker)
560
576
forkerClose forker
561
- ValidateExceededRollBack {} -> error " Unexpected Rollback"
577
+ pure $ pure ()
578
+ ValidateExceededRollBack {} -> pure $ Left ErrorValidateExceededRollback
562
579
ValidateLedgerError (AnnLedgerError forker _ _) -> forkerClose forker >> error " Unexpected ledger error"
563
580
perform state@ (Model _ secParam) (DropAndRestore n) lk = do
564
581
Environment _ testInternals chainDb _ _ _ _ <- get
@@ -569,6 +586,7 @@ instance RunModel Model (StateT Environment IO) where
569
586
perform _ TruncateSnapshots _ = do
570
587
Environment _ testInternals _ _ _ _ _ <- get
571
588
lift $ truncateSnapshots testInternals
589
+ pure $ pure ()
572
590
perform UnInit _ _ = error " Uninitialized model created a command different than Init"
573
591
574
592
monitoring _ (ValidateAndCommit n _) _ _ = tabulate " Rollback depths" [show n]
@@ -602,6 +620,11 @@ instance RunModel Model (StateT Environment IO) where
602
620
pure $ volSt == vol && immSt == imm
603
621
postcondition _ _ _ _ = pure True
604
622
623
+ postconditionOnFailure _ ValidateAndCommit {} _ res = case res of
624
+ Right () -> False <$ counterexamplePost " Unexpected success on invalid ValidateAndCommit"
625
+ Left ErrorValidateExceededRollback -> pure True
626
+ postconditionOnFailure _ _ _ _ = pure True
627
+
605
628
{- ------------------------------------------------------------------------------
606
629
Additional checks
607
630
-------------------------------------------------------------------------------}
0 commit comments