@@ -13,6 +13,7 @@ module Test.Cardano.Db.Mock.Unit.Conway.Rollback (
13
13
poolStatRollback ,
14
14
) where
15
15
16
+ import qualified Cardano.Db as Db
16
17
import Cardano.Ledger.Coin (Coin (.. ))
17
18
import Cardano.Ledger.Conway.TxCert (ConwayDelegCert (.. ), Delegatee (.. ))
18
19
import Cardano.Mock.ChainSync.Server (IOManager (), addBlock , rollback )
@@ -26,11 +27,10 @@ import Ouroboros.Network.Block (blockPoint)
26
27
import Test.Cardano.Db.Mock.Config
27
28
import Test.Cardano.Db.Mock.Examples (mockBlock0 , mockBlock1 , mockBlock2 )
28
29
import Test.Cardano.Db.Mock.UnifiedApi
30
+ import qualified Test.Cardano.Db.Mock.UnifiedApi as Api
29
31
import Test.Cardano.Db.Mock.Validate (assertBlockNoBackoff , assertTxCount , runQuery )
30
32
import Test.Tasty.HUnit (Assertion (), assertBool , assertEqual )
31
33
import Prelude (last )
32
- import qualified Test.Cardano.Db.Mock.UnifiedApi as Api
33
- import qualified Cardano.Db as Db
34
34
35
35
simpleRollback :: IOManager -> [(Text , Text )] -> Assertion
36
36
simpleRollback =
@@ -297,37 +297,47 @@ rollbackFullTx =
297
297
298
298
poolStatRollback :: IOManager -> [(Text , Text )] -> Assertion
299
299
poolStatRollback =
300
- withFullConfigAndDropDB conwayConfigDir testLabel $ \ interpreter mockServer dbSync -> do
301
- startDBSync dbSync
302
-
303
- -- Create pools and stake to generate pool stats
304
- void $ Api. registerAllStakeCreds interpreter mockServer
305
- void $ Api. fillEpochs interpreter mockServer 2
306
-
307
- -- Create rollback point
308
- blks <- Api. forgeAndSubmitBlocks interpreter mockServer 10
309
- assertBlockNoBackoff dbSync (2 + length blks)
310
-
311
- -- Check initial pool stat count
312
- initialCount <- runQuery dbSync Db. queryPoolStatCount
313
-
314
- -- Forge more blocks to create additional pool stats
315
- void $ Api. fillEpochs interpreter mockServer 1
316
- assertBlockNoBackoff dbSync (3 + length blks)
317
-
318
- -- Verify pool stats increased
319
- afterCount <- runQuery dbSync Db. queryPoolStatCount
320
- assertBool " Pool stats should have increased" (afterCount > initialCount)
321
-
322
- -- Rollback to previous point
323
- atomically $ rollback mockServer (blockPoint $ last blks)
324
- assertBlockNoBackoff dbSync (3 + length blks) -- Delayed rollback
325
-
326
- -- Re-sync the same blocks - should not create duplicates
327
- void $ Api. fillEpochs interpreter mockServer 1
328
- finalCount <- runQuery dbSync Db. queryPoolStatCount
329
-
330
- -- Verify count matches and no constraint violations occurred
331
- assertEqual " Pool stat count should match after rollback" afterCount finalCount
300
+ withCustomConfig args (Just configPoolStats) conwayConfigDir testLabel $
301
+ \ interpreter mockServer dbSync -> do
302
+ startDBSync dbSync
303
+
304
+ -- Create pools and stake to generate pool stats
305
+ void $ Api. registerAllStakeCreds interpreter mockServer
306
+ epochBlks1 <- Api. fillEpochs interpreter mockServer 2
307
+
308
+ -- Create rollback point
309
+ rollbackBlks <- Api. forgeAndSubmitBlocks interpreter mockServer 10
310
+ let totalBeforeRollback = length epochBlks1 + length rollbackBlks + 1
311
+ assertBlockNoBackoff dbSync totalBeforeRollback
312
+
313
+ -- Check initial pool stat count
314
+ initialCount <- runQuery dbSync Db. queryPoolStatCount
315
+
316
+ -- Forge more blocks to create additional pool stats
317
+ epochBlks2 <- Api. fillEpochs interpreter mockServer 1
318
+ let totalAfterEpoch = totalBeforeRollback + length epochBlks2
319
+ assertBlockNoBackoff dbSync totalAfterEpoch
320
+
321
+ -- Verify pool stats increased
322
+ afterCount <- runQuery dbSync Db. queryPoolStatCount
323
+ assertBool " Pool stats should have increased" (afterCount > initialCount)
324
+
325
+ -- Rollback to previous point
326
+ atomically $ rollback mockServer (blockPoint $ last rollbackBlks)
327
+ assertBlockNoBackoff dbSync totalAfterEpoch -- Delayed rollback
328
+
329
+ -- Re-sync the same blocks - should not create duplicates
330
+ epochBlks3 <- Api. fillEpochs interpreter mockServer 1
331
+ let finalTotal = totalBeforeRollback + length epochBlks3 + 1
332
+ assertBlockNoBackoff dbSync finalTotal
333
+ finalCount <- runQuery dbSync Db. queryPoolStatCount
334
+
335
+ -- Verify count matches and no constraint violations occurred
336
+ assertEqual " Pool stat count should match after rollback" afterCount finalCount
332
337
where
338
+ args =
339
+ initCommandLineArgs
340
+ { claFullMode = False
341
+ }
342
+
333
343
testLabel = " conwayPoolStatRollback"
0 commit comments