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 committed Sep 17, 2024
1 parent d11aaff commit e752362
Show file tree
Hide file tree
Showing 13 changed files with 717 additions and 1,470 deletions.
88 changes: 75 additions & 13 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,23 @@ module Test.Cardano.Db.Mock.Config (
fingerprintRoot,
getDBSyncPGPass,
getPoolLayer,

-- * Configs
mkConfig,
mkSyncNodeConfig,
mkCustomSyncNodeConfig,
mkConfigDir,
configPruneForceTxIn,
configPrune,
configConsume,
configBootstrap,
configPlutusDisable,
configMultiAssetsDisable,
configShelleyDisable,
configRemoveJsonFromSchema,
configLedgerIgnore,
configMetadataEnable,
configMetadataDisable,
configMetadataKeys,
mkFingerPrint,
mkMutableDir,
mkDBSyncEnv,
Expand Down Expand Up @@ -51,13 +64,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 @@ -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,61 @@ 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}}

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 Down Expand Up @@ -383,7 +443,7 @@ withFullConfigAndLogs =
withCustomConfig ::
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -404,7 +464,7 @@ withCustomConfig =
withCustomConfigAndDropDB ::
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -426,7 +486,7 @@ withCustomConfigAndDropDB =
withCustomConfigAndLogs ::
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -447,7 +507,7 @@ withCustomConfigAndLogs =
withCustomConfigAndLogsAndDropDB ::
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -469,7 +529,7 @@ withFullConfig' ::
WithConfigArgs ->
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -483,7 +543,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 e752362

Please sign in to comment.