Skip to content

Commit

Permalink
update test configs for consumed txout
Browse files Browse the repository at this point in the history
Modified-by: Cmdv <vincent@cmdv.me>
  • Loading branch information
Cmdv committed Sep 16, 2024
1 parent 559d441 commit e9b3ca1
Show file tree
Hide file tree
Showing 10 changed files with 691 additions and 1,444 deletions.
6 changes: 6 additions & 0 deletions cardano-chain-gen/test/Test/Cardano/Db/Mock/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Test.Cardano.Db.Mock.Config (
getPoolLayer,
mkConfig,
mkSyncNodeConfig,
mkCustomSyncNodeConfig,
mkConfigDir,
mkFingerPrint,
mkMutableDir,
Expand Down Expand Up @@ -242,6 +243,11 @@ 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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import Test.Tasty.HUnit (Assertion ())

configRemoveJsonbFromSchemaEnabled :: IOManager -> [(Text, Text)] -> Assertion
configRemoveJsonbFromSchemaEnabled ioManager metadata = do
syncNodeConfig <- mksNodeConfig
syncNodeConfig <- mkCustomSyncNodeConfig cfgDir args config
withCustomConfigAndDropDB args (Just syncNodeConfig) cfgDir testLabel action ioManager metadata
where
action = \_interpreter _mockServer dbSync -> do
action _interpreter _mockServer dbSync = do
startDBSync dbSync
threadDelay 7_000_000
assertEqQuery
Expand All @@ -36,88 +36,70 @@ configRemoveJsonbFromSchemaEnabled ioManager metadata = do

cfgDir = conwayConfigDir

mksNodeConfig :: IO SyncNodeConfig
mksNodeConfig = do
initConfigFile <- mkSyncNodeConfig cfgDir args
let dncInsertOptions' = dncInsertOptions initConfigFile
pure $
initConfigFile
{ dncInsertOptions = dncInsertOptions' {sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig True}
}
config :: SyncNodeConfig -> SyncNodeConfig
config cfg = do
cfg { dncInsertOptions = (dncInsertOptions cfg) {sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig True } }

configRemoveJsonbFromSchemaDisabled :: IOManager -> [(Text, Text)] -> Assertion
configRemoveJsonbFromSchemaDisabled ioManager metadata = do
syncNodeConfig <- mksNodeConfig
syncNodeConfig <- mkCustomSyncNodeConfig cfgDir args config
withCustomConfigAndDropDB args (Just syncNodeConfig) cfgDir testLabel action ioManager metadata
where
action = \_interpreter _mockServer dbSync -> do
startDBSync dbSync
threadDelay 7_000_000
assertEqQuery
dbSync
DB.queryJsonbInSchemaExists
True
"There should be jsonb types in database if option is disabled"
checkStillRuns dbSync

args = initCommandLineArgs {claFullMode = False}
testLabel = "conwayConfigRemoveJsonbFromSchemaDisabled"

cfgDir = conwayConfigDir
action _interpreter _mockServer dbSync = do
startDBSync dbSync
threadDelay 7_000_000
assertEqQuery
dbSync
DB.queryJsonbInSchemaExists
True
"There should be jsonb types in database if option is disabled"
checkStillRuns dbSync

mksNodeConfig :: IO SyncNodeConfig
mksNodeConfig = do
initConfigFile <- mkSyncNodeConfig cfgDir args
let dncInsertOptions' = dncInsertOptions initConfigFile
pure $
initConfigFile
{ dncInsertOptions = dncInsertOptions' {sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False}
}
args = initCommandLineArgs {claFullMode = False}
testLabel = "conwayConfigRemoveJsonbFromSchemaDisabled"
cfgDir = conwayConfigDir
config :: SyncNodeConfig -> SyncNodeConfig
config cfg =
cfg { dncInsertOptions = (dncInsertOptions cfg) { sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False } }

configJsonbInSchemaShouldRemoveThenAdd :: IOManager -> [(Text, Text)] -> Assertion
configJsonbInSchemaShouldRemoveThenAdd ioManager metadata = do
syncNodeConfig <- mksNodeConfig
syncNodeConfig <- mkCustomSyncNodeConfig cfgDir args config
withCustomConfigAndDropDB args (Just syncNodeConfig) cfgDir testLabel action ioManager metadata
where
action = \_interpreter _mockServer dbSync -> do
startDBSync dbSync
action _interpreter _mockServer dbSyncEnv = do
startDBSync dbSyncEnv
threadDelay 7_000_000
assertEqQuery
dbSync
dbSyncEnv
DB.queryJsonbInSchemaExists
False
"There should be no jsonb types in database if option has been enabled"
stopDBSync dbSync
stopDBSync dbSyncEnv
let newDbSyncEnv =
dbSync
dbSyncEnv
{ dbSyncConfig =
(dbSyncConfig dbSync)
(dbSyncConfig dbSyncEnv)
{ dncInsertOptions =
(dncInsertOptions $ dbSyncConfig dbSync)
(dncInsertOptions $ dbSyncConfig dbSyncEnv)
{ sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
}
}
}
startDBSync newDbSyncEnv
threadDelay 7_000_000
assertEqQuery
dbSync
dbSyncEnv
DB.queryJsonbInSchemaExists
True
"There should be jsonb types in database if option has been disabled"
-- Expected to fail
checkStillRuns dbSync
checkStillRuns dbSyncEnv

args = initCommandLineArgs {claFullMode = False}
testLabel = "configJsonbInSchemaShouldRemoveThenAdd"

cfgDir = conwayConfigDir

mksNodeConfig :: IO SyncNodeConfig
mksNodeConfig = do
initConfigFile <- mkSyncNodeConfig cfgDir args
let dncInsertOptions' = dncInsertOptions initConfigFile
pure $
initConfigFile
{ dncInsertOptions = dncInsertOptions' {sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig True}
}
config :: SyncNodeConfig -> SyncNodeConfig
config cfg =
cfg { dncInsertOptions = (dncInsertOptions cfg) { sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig True } }
Loading

0 comments on commit e9b3ca1

Please sign in to comment.