Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test configs for consumed txout #1858

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 80 additions & 9 deletions cardano-chain-gen/test/Test/Cardano/Db/Mock/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,24 @@ module Test.Cardano.Db.Mock.Config (
fingerprintRoot,
getDBSyncPGPass,
getPoolLayer,

-- * Configs
mkConfig,
mkSyncNodeConfig,
mkConfigDir,
configPruneForceTxIn,
configPrune,
configConsume,
configBootstrap,
configPlutusDisable,
configMultiAssetsDisable,
configShelleyDisable,
configRemoveJsonFromSchema,
configRemoveJsonFromSchemaFalse,
configLedgerIgnore,
configMetadataEnable,
configMetadataDisable,
configMetadataKeys,
mkFingerPrint,
mkMutableDir,
mkDBSyncEnv,
Expand Down Expand Up @@ -50,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 @@ -116,7 +132,6 @@ data CommandLineArgs = CommandLineArgs
, claFullMode :: Bool
, claMigrateConsumed :: Bool
, claPruneTxOut :: Bool
, claBootstrap :: Bool
}

data WithConfigArgs = WithConfigArgs
Expand Down Expand Up @@ -279,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 @@ -301,7 +371,6 @@ initCommandLineArgs =
, claFullMode = True
, claMigrateConsumed = False
, claPruneTxOut = False
, claBootstrap = False
}

emptyMetricsSetters :: MetricSetters
Expand Down Expand Up @@ -377,7 +446,7 @@ withFullConfigAndLogs =
withCustomConfig ::
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -398,7 +467,7 @@ withCustomConfig =
withCustomConfigAndDropDB ::
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -420,7 +489,7 @@ withCustomConfigAndDropDB =
withCustomConfigAndLogs ::
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -441,7 +510,7 @@ withCustomConfigAndLogs =
withCustomConfigAndLogsAndDropDB ::
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -463,7 +532,7 @@ withFullConfig' ::
WithConfigArgs ->
CommandLineArgs ->
-- | custom SyncNodeConfig
Maybe SyncNodeConfig ->
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
-- | config filepath
FilePath ->
-- | test label
Expand All @@ -477,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
Loading