Skip to content

Commit 0d7c288

Browse files
committed
fix tests
1 parent d25a038 commit 0d7c288

File tree

2 files changed

+49
-34
lines changed

2 files changed

+49
-34
lines changed

cardano-chain-gen/test/Test/Cardano/Db/Mock/Config.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module Test.Cardano.Db.Mock.Config (
3535
configMetadataEnable,
3636
configMetadataDisable,
3737
configMetadataKeys,
38+
configPoolStats,
3839
mkFingerPrint,
3940
mkMutableDir,
4041
mkDBSyncEnv,
@@ -353,6 +354,10 @@ configMetadataKeys :: SyncNodeConfig -> SyncNodeConfig
353354
configMetadataKeys cfg = do
354355
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioMetadata = MetadataKeys $ 1 :| []}}
355356

357+
configPoolStats :: SyncNodeConfig -> SyncNodeConfig
358+
configPoolStats cfg = do
359+
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioPoolStats = PoolStatsConfig True}}
360+
356361
initCommandLineArgs :: CommandLineArgs
357362
initCommandLineArgs =
358363
CommandLineArgs

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Rollback.hs

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module Test.Cardano.Db.Mock.Unit.Conway.Rollback (
1313
poolStatRollback,
1414
) where
1515

16+
import qualified Cardano.Db as Db
1617
import Cardano.Ledger.Coin (Coin (..))
1718
import Cardano.Ledger.Conway.TxCert (ConwayDelegCert (..), Delegatee (..))
1819
import Cardano.Mock.ChainSync.Server (IOManager (), addBlock, rollback)
@@ -26,11 +27,10 @@ import Ouroboros.Network.Block (blockPoint)
2627
import Test.Cardano.Db.Mock.Config
2728
import Test.Cardano.Db.Mock.Examples (mockBlock0, mockBlock1, mockBlock2)
2829
import Test.Cardano.Db.Mock.UnifiedApi
30+
import qualified Test.Cardano.Db.Mock.UnifiedApi as Api
2931
import Test.Cardano.Db.Mock.Validate (assertBlockNoBackoff, assertTxCount, runQuery)
3032
import Test.Tasty.HUnit (Assertion (), assertBool, assertEqual)
3133
import Prelude (last)
32-
import qualified Test.Cardano.Db.Mock.UnifiedApi as Api
33-
import qualified Cardano.Db as Db
3434

3535
simpleRollback :: IOManager -> [(Text, Text)] -> Assertion
3636
simpleRollback =
@@ -297,37 +297,47 @@ rollbackFullTx =
297297

298298
poolStatRollback :: IOManager -> [(Text, Text)] -> Assertion
299299
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
332337
where
338+
args =
339+
initCommandLineArgs
340+
{ claFullMode = False
341+
}
342+
333343
testLabel = "conwayPoolStatRollback"

0 commit comments

Comments
 (0)