@@ -43,13 +43,15 @@ module Test.Cardano.Db.Mock.Config (
43
43
withCustomConfigAndLogs ,
44
44
withFullConfig' ,
45
45
replaceConfigFile ,
46
+ txOutTableTypeFromConfig ,
46
47
) where
47
48
48
49
import Cardano.Api (NetworkMagic (.. ))
49
- import qualified Cardano.Db as Db
50
+ import qualified Cardano.Db as DB
50
51
import Cardano.DbSync
51
52
import Cardano.DbSync.Config
52
53
import Cardano.DbSync.Config.Cardano
54
+ import Cardano.DbSync.Config.Types (SyncInsertOptions (.. ), TxOutConfig (.. ), UseTxOutAddress (.. ))
53
55
import Cardano.DbSync.Error (runOrThrowIO )
54
56
import Cardano.DbSync.Types (CardanoBlock , MetricSetters (.. ))
55
57
import Cardano.Mock.ChainSync.Server
@@ -209,16 +211,16 @@ pollDBSync env = do
209
211
withDBSyncEnv :: IO DBSyncEnv -> (DBSyncEnv -> IO a ) -> IO a
210
212
withDBSyncEnv mkEnv = bracket mkEnv stopDBSyncIfRunning
211
213
212
- getDBSyncPGPass :: DBSyncEnv -> Db . PGPassSource
214
+ getDBSyncPGPass :: DBSyncEnv -> DB . PGPassSource
213
215
getDBSyncPGPass = enpPGPassSource . dbSyncParams
214
216
215
217
queryDBSync :: DBSyncEnv -> ReaderT SqlBackend (NoLoggingT IO ) a -> IO a
216
- queryDBSync env = Db . runWithConnectionNoLogging (getDBSyncPGPass env)
218
+ queryDBSync env = DB . runWithConnectionNoLogging (getDBSyncPGPass env)
217
219
218
220
getPoolLayer :: DBSyncEnv -> IO PoolDataLayer
219
221
getPoolLayer env = do
220
- pgconfig <- runOrThrowIO $ Db . readPGPass (enpPGPassSource $ dbSyncParams env)
221
- pool <- runNoLoggingT $ createPostgresqlPool (Db . toConnectionString pgconfig) 1 -- Pool size of 1 for tests
222
+ pgconfig <- runOrThrowIO $ DB . readPGPass (enpPGPassSource $ dbSyncParams env)
223
+ pool <- runNoLoggingT $ createPostgresqlPool (DB . toConnectionString pgconfig) 1 -- Pool size of 1 for tests
222
224
pure $
223
225
postgresqlPoolDataLayer
224
226
nullTracer
@@ -259,15 +261,15 @@ mkShelleyCredentials bulkFile = do
259
261
-- | staticDir can be shared by tests running in parallel. mutableDir not.
260
262
mkSyncNodeParams :: FilePath -> FilePath -> CommandLineArgs -> IO SyncNodeParams
261
263
mkSyncNodeParams staticDir mutableDir CommandLineArgs {.. } = do
262
- pgconfig <- runOrThrowIO Db . readPGPassDefault
264
+ pgconfig <- runOrThrowIO DB . readPGPassDefault
263
265
264
266
pure $
265
267
SyncNodeParams
266
268
{ enpConfigFile = mkConfigFile staticDir claConfigFilename
267
269
, enpSocketPath = SocketPath $ mutableDir </> " .socket"
268
270
, enpMaybeLedgerStateDir = Just $ LedgerStateDir $ mutableDir </> " ledger-states"
269
271
, enpMigrationDir = MigrationDir " ../schema"
270
- , enpPGPassSource = Db . PGPassCached pgconfig
272
+ , enpPGPassSource = DB . PGPassCached pgconfig
271
273
, enpEpochDisabled = claEpochDisabled
272
274
, enpHasCache = claHasCache
273
275
, enpSkipFix = claSkipFix
@@ -503,12 +505,12 @@ withFullConfig' WithConfigArgs {..} cmdLineArgs mSyncNodeConfig configFilePath t
503
505
-- we dont fork dbsync here. Just prepare it as an action
504
506
withDBSyncEnv (mkDBSyncEnv dbsyncParams syncNodeConfig partialDbSyncRun) $ \ dbSyncEnv -> do
505
507
let pgPass = getDBSyncPGPass dbSyncEnv
506
- tableNames <- Db . getAllTablleNames pgPass
508
+ tableNames <- DB . getAllTablleNames pgPass
507
509
-- We only want to create the table schema once for the tests so here we check
508
510
-- if there are any table names.
509
511
if null tableNames || shouldDropDB
510
- then void . hSilence [stderr] $ Db . recreateDB pgPass
511
- else void . hSilence [stderr] $ Db . truncateTables pgPass tableNames
512
+ then void . hSilence [stderr] $ DB . recreateDB pgPass
513
+ else void . hSilence [stderr] $ DB . truncateTables pgPass tableNames
512
514
action interpreter mockServer dbSyncEnv
513
515
where
514
516
mutableDir = mkMutableDir testLabelFilePath
@@ -534,3 +536,15 @@ replaceConfigFile newFilename dbSync@DBSyncEnv {..} = do
534
536
configDir = mkConfigDir . takeDirectory . unConfigFile . enpConfigFile $ dbSyncParams
535
537
newParams =
536
538
dbSyncParams {enpConfigFile = ConfigFile $ configDir </> newFilename}
539
+
540
+ txOutTableTypeFromConfig :: DBSyncEnv -> DB. TxOutTableType
541
+ txOutTableTypeFromConfig dbSyncEnv =
542
+ case sioTxOut $ dncInsertOptions $ dbSyncConfig dbSyncEnv of
543
+ TxOutDisable -> DB. TxOutCore
544
+ TxOutEnable useTxOutAddress -> getTxOutTT useTxOutAddress
545
+ TxOutConsumed _ useTxOutAddress -> getTxOutTT useTxOutAddress
546
+ TxOutConsumedPrune _ useTxOutAddress -> getTxOutTT useTxOutAddress
547
+ TxOutConsumedBootstrap _ useTxOutAddress -> getTxOutTT useTxOutAddress
548
+ where
549
+ getTxOutTT :: UseTxOutAddress -> DB. TxOutTableType
550
+ getTxOutTT value = if unUseTxOutAddress value then DB. TxOutVariantAddress else DB. TxOutCore
0 commit comments