@@ -10,6 +10,7 @@ module Test.Cardano.Db.Mock.Unit.Conway.Rollback (
10
10
stakeAddressRollback ,
11
11
rollbackChangeTxOrder ,
12
12
rollbackFullTx ,
13
+ poolStatRollback ,
13
14
) where
14
15
15
16
import Cardano.Ledger.Coin (Coin (.. ))
@@ -25,9 +26,11 @@ import Ouroboros.Network.Block (blockPoint)
25
26
import Test.Cardano.Db.Mock.Config
26
27
import Test.Cardano.Db.Mock.Examples (mockBlock0 , mockBlock1 , mockBlock2 )
27
28
import Test.Cardano.Db.Mock.UnifiedApi
28
- import Test.Cardano.Db.Mock.Validate (assertBlockNoBackoff , assertTxCount )
29
- import Test.Tasty.HUnit (Assertion ())
29
+ import Test.Cardano.Db.Mock.Validate (assertBlockNoBackoff , assertTxCount , runQuery )
30
+ import Test.Tasty.HUnit (Assertion (), assertBool , assertEqual )
30
31
import Prelude (last )
32
+ import qualified Test.Cardano.Db.Mock.UnifiedApi as Api
33
+ import qualified Cardano.Db as Db
31
34
32
35
simpleRollback :: IOManager -> [(Text , Text )] -> Assertion
33
36
simpleRollback =
@@ -291,3 +294,40 @@ rollbackFullTx =
291
294
assertTxCount dbSync 14
292
295
where
293
296
testLabel = " conwayRollbackFullTx"
297
+
298
+ poolStatRollback :: IOManager -> [(Text , Text )] -> Assertion
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
332
+ where
333
+ testLabel = " conwayPoolStatRollback"
0 commit comments