Skip to content

Commit

Permalink
remove config files and hardcode the content
Browse files Browse the repository at this point in the history
  • Loading branch information
Cmdv authored and kderme committed Sep 18, 2024
1 parent c3c61d6 commit 161db86
Show file tree
Hide file tree
Showing 13 changed files with 705 additions and 1,478 deletions.
95 changes: 80 additions & 15 deletions cardano-chain-gen/test/Test/Cardano/Db/Mock/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,24 @@ module Test.Cardano.Db.Mock.Config (
fingerprintRoot,
getDBSyncPGPass,
getPoolLayer,

-- * Configs
mkConfig,
mkSyncNodeConfig,
mkCustomSyncNodeConfig,
mkConfigDir,
configPruneForceTxIn,
configPrune,
configConsume,
configBootstrap,
configPlutusDisable,
configMultiAssetsDisable,
configShelleyDisable,
configRemoveJsonFromSchema,
configRemoveJsonFromSchemaFalse,
configLedgerIgnore,
configMetadataEnable,
configMetadataDisable,
configMetadataKeys,
mkFingerPrint,
mkMutableDir,
mkDBSyncEnv,
Expand Down Expand Up @@ -51,13 +65,14 @@ import qualified Cardano.Db as Db
import Cardano.DbSync
import Cardano.DbSync.Config
import Cardano.DbSync.Config.Cardano
import Cardano.DbSync.Config.Types
import Cardano.DbSync.Error (runOrThrowIO)
import Cardano.DbSync.Types (CardanoBlock, MetricSetters (..))
import Cardano.Mock.ChainSync.Server
import Cardano.Mock.Forging.Interpreter
import Cardano.Node.Protocol.Shelley (readLeaderCredentials)
import Cardano.Node.Types (ProtocolFilepaths (..))
import Cardano.Prelude (ReaderT, panic, stderr, textShow)
import Cardano.Prelude (NonEmpty ((:|)), ReaderT, panic, stderr, textShow)
import Cardano.SMASH.Server.PoolDataLayer
import Control.Concurrent.Async (Async, async, cancel, poll)
import Control.Concurrent.STM (atomically)
Expand Down Expand Up @@ -117,7 +132,6 @@ data CommandLineArgs = CommandLineArgs
, claFullMode :: Bool
, claMigrateConsumed :: Bool
, claPruneTxOut :: Bool
, claBootstrap :: Bool
}

data WithConfigArgs = WithConfigArgs
Expand Down Expand Up @@ -243,11 +257,6 @@ mkSyncNodeConfig configFilePath cmdLineArgs =
configFilename = claConfigFilename cmdLineArgs
configDir = mkConfigDir configFilePath

mkCustomSyncNodeConfig :: FilePath -> CommandLineArgs -> (SyncNodeConfig -> SyncNodeConfig) -> IO SyncNodeConfig
mkCustomSyncNodeConfig cfgDir args updateFn = do
initConfigFile <- mkSyncNodeConfig cfgDir args
pure $ updateFn initConfigFile

mkShelleyCredentials :: FilePath -> IO [ShelleyLeaderCredentials StandardCrypto]
mkShelleyCredentials bulkFile = do
eitherM (panic . textShow) pure $ runExceptT $ readLeaderCredentials (Just protFiles)
Expand Down Expand Up @@ -285,10 +294,65 @@ mkSyncNodeParams staticDir mutableDir CommandLineArgs {..} = do
, enpMaybeRollback = Nothing
}

------------------------------------------------------------------------------
-- Custom Configs
------------------------------------------------------------------------------
mkConfigFile :: FilePath -> FilePath -> ConfigFile
mkConfigFile staticDir cliConfigFilename =
ConfigFile $ staticDir </> cliConfigFilename

configPruneForceTxIn :: SyncNodeConfig -> SyncNodeConfig
configPruneForceTxIn cfg = do
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioTxOut = TxOutPrune (ForceTxIn True)}}

configPrune :: SyncNodeConfig -> SyncNodeConfig
configPrune cfg = do
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioTxOut = TxOutPrune (ForceTxIn False)}}

configConsume :: SyncNodeConfig -> SyncNodeConfig
configConsume cfg = do
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioTxOut = TxOutConsumed (ForceTxIn False)}}

configBootstrap :: SyncNodeConfig -> SyncNodeConfig
configBootstrap cfg = do
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioTxOut = TxOutBootstrap (ForceTxIn False)}}

configPlutusDisable :: SyncNodeConfig -> SyncNodeConfig
configPlutusDisable cfg = do
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioPlutus = PlutusDisable}}

configMultiAssetsDisable :: SyncNodeConfig -> SyncNodeConfig
configMultiAssetsDisable cfg = do
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioMultiAsset = MultiAssetDisable}}

configShelleyDisable :: SyncNodeConfig -> SyncNodeConfig
configShelleyDisable cfg = do
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioShelley = ShelleyDisable}}

configRemoveJsonFromSchema :: SyncNodeConfig -> SyncNodeConfig
configRemoveJsonFromSchema cfg = do
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig True}}

configRemoveJsonFromSchemaFalse :: SyncNodeConfig -> SyncNodeConfig
configRemoveJsonFromSchemaFalse cfg = do
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False}}

configLedgerIgnore :: SyncNodeConfig -> SyncNodeConfig
configLedgerIgnore cfg = do
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioLedger = LedgerIgnore}}

configMetadataEnable :: SyncNodeConfig -> SyncNodeConfig
configMetadataEnable cfg = do
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioMetadata = MetadataEnable}}

configMetadataDisable :: SyncNodeConfig -> SyncNodeConfig
configMetadataDisable cfg = do
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioMetadata = MetadataDisable}}

configMetadataKeys :: SyncNodeConfig -> SyncNodeConfig
configMetadataKeys cfg = do
cfg {dncInsertOptions = (dncInsertOptions cfg) {sioMetadata = MetadataKeys $ 1 :| []}}

initCommandLineArgs :: CommandLineArgs
initCommandLineArgs =
CommandLineArgs
Expand All @@ -307,7 +371,6 @@ initCommandLineArgs =
, claFullMode = True
, claMigrateConsumed = False
, claPruneTxOut = False
, claBootstrap = False
}

emptyMetricsSetters :: MetricSetters
Expand Down Expand Up @@ -383,7 +446,7 @@ withFullConfigAndLogs =
withCustomConfig ::
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -404,7 +467,7 @@ withCustomConfig =
withCustomConfigAndDropDB ::
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -426,7 +489,7 @@ withCustomConfigAndDropDB =
withCustomConfigAndLogs ::
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -447,7 +510,7 @@ withCustomConfigAndLogs =
withCustomConfigAndLogsAndDropDB ::
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -469,7 +532,7 @@ withFullConfig' ::
WithConfigArgs ->
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -483,7 +546,9 @@ withFullConfig' WithConfigArgs {..} cmdLineArgs mSyncNodeConfig configFilePath t
-- check if custom syncNodeConfigs have been passed or not
syncNodeConfig <-
case mSyncNodeConfig of
Just snc -> pure snc
Just updateFn -> do
initConfigFile <- mkSyncNodeConfig configFilePath cmdLineArgs
pure $ updateFn initConfigFile
Nothing -> mkSyncNodeConfig configFilePath cmdLineArgs

cfg <- mkConfig configFilePath mutableDir cmdLineArgs syncNodeConfig
Expand Down
Loading

0 comments on commit 161db86

Please sign in to comment.