1
1
{-# LANGUAGE OverloadedStrings #-}
2
2
{-# LANGUAGE ScopedTypeVariables #-}
3
3
{-# LANGUAGE TypeApplications #-}
4
+ {-# LANGUAGE RecordWildCards #-}
4
5
5
6
module Test.Cardano.Db.Mock.Config (
6
7
Config (.. ),
7
8
DBSyncEnv (.. ),
8
- TxOutParam (.. ),
9
+ CommandLineArgs (.. ),
10
+ TxOutParam (.. ),
11
+ initCommandLineArgs ,
9
12
babbageConfigDir ,
10
13
alonzoConfigDir ,
11
14
emptyMetricsSetters ,
@@ -30,7 +33,8 @@ module Test.Cardano.Db.Mock.Config (
30
33
startDBSync ,
31
34
withDBSyncEnv ,
32
35
withFullConfig ,
33
- withTxOutParamConfig ,
36
+ withCustomConfig ,
37
+ withCustomConfigAndLogs ,
34
38
withFullConfig' ,
35
39
) where
36
40
@@ -93,8 +97,26 @@ data DBSyncEnv = DBSyncEnv
93
97
94
98
-- used for testing of tx out pruning feature
95
99
data TxOutParam = TxOutParam
96
- { paramMigrateConsumed :: Bool ,
97
- paramPruneTxOut :: Bool
100
+ { paramMigrateConsumed :: Bool
101
+ , paramPruneTxOut :: Bool
102
+ }
103
+
104
+ data CommandLineArgs = CommandLineArgs
105
+ { claHasConfigFile :: Bool
106
+ , claEpochDisabled :: Bool
107
+ , claHasCache :: Bool
108
+ , claShouldUseLedger :: Bool
109
+ , claSkipFix :: Bool
110
+ , claOnlyFix :: Bool
111
+ , claForceIndexes :: Bool
112
+ , claHasMultiAssets :: Bool
113
+ , claHasMetadata :: Bool
114
+ , claHasPlutusExtra :: Bool
115
+ , claHasOfflineData :: Bool
116
+ , claTurboMode :: Bool
117
+ , claFullMode :: Bool
118
+ , claMigrateConsumed :: Bool
119
+ , claPruneTxOut :: Bool
98
120
}
99
121
100
122
babbageConfigDir :: FilePath
@@ -203,14 +225,14 @@ setupTestsDir dir = do
203
225
0
204
226
Nothing
205
227
206
- mkConfig :: FilePath -> FilePath -> Maybe TxOutParam -> IO Config
207
- mkConfig staticDir mutableDir mTxOutParam = do
228
+ mkConfig :: FilePath -> FilePath -> CommandLineArgs -> IO Config
229
+ mkConfig staticDir mutableDir cmdLineArgs = do
208
230
config <- readSyncNodeConfig $ ConfigFile (staticDir </> " test-db-sync-config.json" )
209
231
genCfg <- either (error . Text. unpack . renderSyncNodeError) id <$> runExceptT (readCardanoGenesisConfig config)
210
232
let pInfoDbSync = mkProtocolInfoCardano genCfg []
211
233
creds <- mkShelleyCredentials $ staticDir </> " pools" </> " bulk1.creds"
212
234
let pInfoForger = mkProtocolInfoCardano genCfg creds
213
- syncPars <- mkSyncNodeParams staticDir mutableDir mTxOutParam
235
+ syncPars <- mkSyncNodeParams staticDir mutableDir cmdLineArgs
214
236
pure $ Config (Consensus. pInfoConfig pInfoDbSync) pInfoDbSync pInfoForger syncPars
215
237
216
238
mkShelleyCredentials :: FilePath -> IO [ShelleyLeaderCredentials StandardCrypto ]
@@ -228,35 +250,55 @@ mkShelleyCredentials bulkFile = do
228
250
}
229
251
230
252
-- | staticDir can be shared by tests running in parallel. mutableDir not.
231
- mkSyncNodeParams :: FilePath -> FilePath -> Maybe TxOutParam -> IO SyncNodeParams
232
- mkSyncNodeParams staticDir mutableDir mTxOutParam = do
253
+ mkSyncNodeParams :: FilePath -> FilePath -> CommandLineArgs -> IO SyncNodeParams
254
+ mkSyncNodeParams staticDir mutableDir CommandLineArgs { .. } = do
233
255
pgconfig <- orDie Db. renderPGPassError $ newExceptT Db. readPGPassDefault
234
256
pure $
235
257
SyncNodeParams
236
- { enpConfigFile = ConfigFile $ staticDir </> " test-db-sync-config.json"
258
+ { enpConfigFile = ConfigFile $ staticDir </> ( if claHasConfigFile then " test-db-sync-config.json" else " " )
237
259
, enpSocketPath = SocketPath $ mutableDir </> " .socket"
238
260
, enpMaybeLedgerStateDir = Just $ LedgerStateDir $ mutableDir </> " ledger-states"
239
261
, enpMigrationDir = MigrationDir " ../schema"
240
262
, enpPGPassSource = Db. PGPassCached pgconfig
241
- , enpExtended = True
242
- , enpHasCache = True
243
- , enpShouldUseLedger = True
244
- , enpSkipFix = True
245
- , enpOnlyFix = False
246
- , enpForceIndexes = False
247
- , enpHasMultiAssets = True
248
- , enpHasMetadata = True
263
+ , enpEpochDisabled = claEpochDisabled
264
+ , enpHasCache = claHasCache
265
+ , enpShouldUseLedger = claShouldUseLedger
266
+ , enpSkipFix = claSkipFix
267
+ , enpOnlyFix = claOnlyFix
268
+ , enpForceIndexes = claForceIndexes
269
+ , enpHasMultiAssets = claHasMultiAssets
270
+ , enpHasMetadata = claHasMetadata
249
271
, enpHasPlutusExtra = True
250
272
, enpHasOfflineData = True
251
273
, enpTurboMode = False
252
274
, enpFullMode = True
253
- , enpMigrateConsumed = maybe False paramMigrateConsumed mTxOutParam
254
- , enpPruneTxOut = maybe False paramPruneTxOut mTxOutParam
275
+ , enpMigrateConsumed = claMigrateConsumed
276
+ , enpPruneTxOut = claPruneTxOut
255
277
, enpSnEveryFollowing = 35
256
278
, enpSnEveryLagging = 35
257
279
, enpMaybeRollback = Nothing
258
280
}
259
281
282
+ initCommandLineArgs :: CommandLineArgs
283
+ initCommandLineArgs =
284
+ CommandLineArgs
285
+ { claHasConfigFile = True
286
+ , claEpochDisabled = True
287
+ , claHasCache = True
288
+ , claShouldUseLedger = True
289
+ , claSkipFix = True
290
+ , claOnlyFix = False
291
+ , claForceIndexes = False
292
+ , claHasMultiAssets = True
293
+ , claHasMetadata = True
294
+ , claHasPlutusExtra = True
295
+ , claHasOfflineData = True
296
+ , claTurboMode = False
297
+ , claFullMode = True
298
+ , claMigrateConsumed = True
299
+ , claPruneTxOut = True
300
+ }
301
+
260
302
emptyMetricsSetters :: MetricSetters
261
303
emptyMetricsSetters =
262
304
MetricSetters
@@ -273,37 +315,49 @@ withFullConfig ::
273
315
IOManager ->
274
316
[(Text , Text )] ->
275
317
IO a
276
- withFullConfig = withFullConfig' True Nothing
318
+ withFullConfig = withFullConfig' True False initCommandLineArgs
319
+
320
+ withCustomConfig ::
321
+ CommandLineArgs ->
322
+ FilePath ->
323
+ FilePath ->
324
+ (Interpreter -> ServerHandle IO CardanoBlock -> DBSyncEnv -> IO a ) ->
325
+ IOManager ->
326
+ [(Text , Text )] ->
327
+ IO a
328
+ withCustomConfig = withFullConfig' True False
277
329
278
- withTxOutParamConfig ::
279
- TxOutParam ->
330
+ -- when wanting to check for a failure in a test for some reason logging has to be enabled
331
+ withCustomConfigAndLogs ::
332
+ CommandLineArgs ->
280
333
FilePath ->
281
334
FilePath ->
282
335
(Interpreter -> ServerHandle IO CardanoBlock -> DBSyncEnv -> IO a ) ->
283
336
IOManager ->
284
337
[(Text , Text )] ->
285
338
IO a
286
- withTxOutParamConfig txOutParam = withFullConfig' True ( Just txOutParam)
339
+ withCustomConfigAndLogs = withFullConfig' True True
287
340
288
341
withFullConfig' ::
289
342
Bool ->
290
- Maybe TxOutParam ->
343
+ Bool ->
344
+ CommandLineArgs ->
291
345
FilePath ->
292
346
FilePath ->
293
347
(Interpreter -> ServerHandle IO CardanoBlock -> DBSyncEnv -> IO a ) ->
294
348
IOManager ->
295
349
[(Text , Text )] ->
296
350
IO a
297
- withFullConfig' hasFingerprint mTxOutParam config testLabel action iom migr = do
351
+ withFullConfig' hasFingerprint shouldLog cmdLineArgs config testLabel action iom migr = do
298
352
recreateDir mutableDir
299
- cfg <- mkConfig configDir mutableDir mTxOutParam
353
+ cfg <- mkConfig configDir mutableDir cmdLineArgs
300
354
fingerFile <- if hasFingerprint then Just <$> prepareFingerprintFile testLabel else pure Nothing
301
355
let dbsyncParams = syncNodeParams cfg
302
356
-- Set to True to disable logging, False to enable it.
303
357
trce <-
304
- if True
305
- then pure nullTracer
306
- else configureLogging dbsyncParams " db-sync-node "
358
+ if shouldLog
359
+ then configureLogging dbsyncParams " db-sync-node "
360
+ else pure nullTracer
307
361
let dbsyncRun = runDbSync emptyMetricsSetters migr iom trce dbsyncParams True
308
362
let initSt = Consensus. pInfoInitLedger $ protocolInfo cfg
309
363
withInterpreter (protocolInfoForging cfg) nullTracer fingerFile $ \ interpreter -> do
0 commit comments