Skip to content

Commit 2d6cba4

Browse files
Update prop_putDelistedPools to check for overwriting.
In particular, we check that 'putDelistedPools' completely overwrites the existing set every time. In response to review feedback: #2277 (comment)
1 parent 159afdc commit 2d6cba4

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

lib/core/test/unit/Cardano/Pool/DB/Properties.hs

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,43 +1459,48 @@ prop_putLastMetadataGCReadLastMetadataGC DBLayer{..} posixTime = do
14591459
assertWith "Setting sync time and reading afterwards works"
14601460
(time == Just posixTime)
14611461

1462+
-- Check that 'putDelistedPools' completely overwrites the existing set
1463+
-- of delisted pools every time:
1464+
--
14621465
prop_putDelistedPools
14631466
:: DBLayer IO
1464-
-> [(CertificatePublicationTime, PoolRegistrationCertificate)]
1467+
-> [PoolId]
1468+
-> [PoolId]
14651469
-> Property
1466-
prop_putDelistedPools DBLayer {..} entries =
1467-
monadicIO (setup >> prop)
1470+
prop_putDelistedPools DBLayer {..} pools1 pools2 =
1471+
checkCoverage
1472+
$ cover 2 (Set.size poolSet1 == 0)
1473+
"number of pools in set #1 = 0"
1474+
$ cover 2 (Set.size poolSet1 == 1)
1475+
"number of pools in set #1 = 1"
1476+
$ cover 2 (Set.size poolSet1 > 1)
1477+
"number of pools in set #1 > 1"
1478+
$ cover 2 (Set.size poolSet2 == 0)
1479+
"number of pools in set #2 = 0"
1480+
$ cover 2 (Set.size poolSet2 == 1)
1481+
"number of pools in set #2 = 1"
1482+
$ cover 2 (Set.size poolSet2 > 1)
1483+
"number of pools in set #2 > 1"
1484+
$ monadicIO (setup >> prop)
14681485
where
1469-
setup = run $ atomically cleanDB
1470-
entriesIn = L.sort entries
1471-
prop = do
1472-
run $ atomically $
1473-
mapM_ (uncurry putPoolRegistration) entriesIn
1474-
entriesOut <- run . atomically $ L.sort . catMaybes
1475-
<$> mapM (readPoolRegistration . view #poolId . snd) entries
1486+
poolSet1 = Set.fromList pools1 `Set.difference` Set.fromList pools2
1487+
poolSet2 = Set.fromList pools2 `Set.difference` Set.fromList pools1
14761488

1477-
monitor $ counterexample $ unlines
1478-
[ "Written into DB: "
1479-
, show entriesIn
1480-
, "Read from DB: "
1481-
, show entriesOut
1482-
]
1483-
1484-
assertWith "entriesIn == entriesOut"
1485-
$ entriesIn == entriesOut
1489+
setup = run $ atomically cleanDB
14861490

1487-
-- delist pools
1488-
let poolsToDelist = L.sort $ fmap (view #poolId . snd) entriesIn
1489-
run $ atomically $ putDelistedPools poolsToDelist
1490-
poolsDelisted <- L.sort <$> run (atomically readDelistedPools)
1491+
prop = forM_ [poolSet1, poolSet2] $ \poolsToMarkAsDelisted -> do
1492+
run $ atomically $ putDelistedPools $
1493+
Set.toList poolsToMarkAsDelisted
1494+
poolsActuallyDelisted <- Set.fromList . L.sort <$>
1495+
run (atomically readDelistedPools)
14911496
monitor $ counterexample $ unlines
1492-
[ "Pools to delist: "
1493-
, pretty poolsToDelist
1497+
[ "Pools to mark as delisted: "
1498+
, pretty $ Set.toList poolsToMarkAsDelisted
14941499
, "Pools actually delisted: "
1495-
, pretty poolsDelisted
1500+
, pretty $ Set.toList poolsActuallyDelisted
14961501
]
1497-
assertWith "poolsToDelist == poolsDelisted"
1498-
$ poolsToDelist == poolsDelisted
1502+
assertWith "poolsToMarkAsDelisted == poolsActuallyDelisted"
1503+
$ poolsToMarkAsDelisted == poolsActuallyDelisted
14991504

15001505
prop_putDelistedPoolsPersists
15011506
:: DBLayer IO

0 commit comments

Comments
 (0)