Skip to content

Commit 296109b

Browse files
Cmdvkderme
authored andcommitted
1588 - remove jsonb from Schema & add config
1 parent dc8b8cc commit 296109b

File tree

30 files changed

+482
-96
lines changed

30 files changed

+482
-96
lines changed

cardano-chain-gen/cardano-chain-gen.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ test-suite cardano-chain-gen
156156
Test.Cardano.Db.Mock.Unit.Conway.CommandLineArg.ConfigFile
157157
Test.Cardano.Db.Mock.Unit.Conway.CommandLineArg.EpochDisabled
158158
Test.Cardano.Db.Mock.Unit.Conway.CommandLineArg.ForceIndex
159+
Test.Cardano.Db.Mock.Unit.Conway.Config.JsonbInSchema
159160
Test.Cardano.Db.Mock.Unit.Conway.Config.Parse
160161
Test.Cardano.Db.Mock.Unit.Conway.Config.MigrateConsumedPruneTxOut
161162
Test.Cardano.Db.Mock.Unit.Conway.Governance
@@ -200,7 +201,6 @@ test-suite cardano-chain-gen
200201
, stm
201202
, strict-stm
202203
, tasty
203-
, tasty-expected-failure
204204
, tasty-quickcheck
205205
, text
206206
, transformers

cardano-chain-gen/test/Test/Cardano/Db/Mock/Config.hs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module Test.Cardano.Db.Mock.Config (
3737
withFullConfig,
3838
withFullConfigAndDropDB,
3939
withFullConfigAndLogs,
40+
withCustomConfigAndLogsAndDropDB,
4041
withCustomConfig,
4142
withCustomConfigAndDropDB,
4243
withCustomConfigAndLogs,
@@ -438,6 +439,27 @@ withCustomConfigAndLogs =
438439
}
439440
)
440441

442+
withCustomConfigAndLogsAndDropDB ::
443+
CommandLineArgs ->
444+
-- | custom SyncNodeConfig
445+
Maybe SyncNodeConfig ->
446+
-- | config filepath
447+
FilePath ->
448+
-- | test label
449+
FilePath ->
450+
(Interpreter -> ServerHandle IO CardanoBlock -> DBSyncEnv -> IO a) ->
451+
IOManager ->
452+
[(Text, Text)] ->
453+
IO a
454+
withCustomConfigAndLogsAndDropDB =
455+
withFullConfig'
456+
( WithConfigArgs
457+
{ hasFingerprint = True
458+
, shouldLog = True
459+
, shouldDropDB = True
460+
}
461+
)
462+
441463
withFullConfig' ::
442464
WithConfigArgs ->
443465
CommandLineArgs ->

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Alonzo/Config.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ insertConfig = do
3131
, sioGovernance = GovernanceConfig False
3232
, sioOffchainPoolData = OffchainPoolDataConfig False
3333
, sioJsonType = JsonTypeDisable
34+
, sioAddJsonbToSchema = AddJsonbToSchemaConfig False
3435
}
3536

3637
dncInsertOptions cfg @?= expected

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ module Test.Cardano.Db.Mock.Unit.Babbage (
99
import Cardano.Mock.ChainSync.Server (IOManager)
1010
import Data.Text (Text)
1111
import Test.Tasty (TestTree, testGroup)
12-
import Test.Tasty.ExpectedFailure (expectFail)
1312
import Test.Tasty.HUnit (Assertion, testCase)
1413

1514
import qualified Test.Cardano.Db.Mock.Unit.Babbage.CommandLineArg.ConfigFile as ConfigFile
@@ -25,6 +24,7 @@ import qualified Test.Cardano.Db.Mock.Unit.Babbage.Rollback as BabRollback
2524
import qualified Test.Cardano.Db.Mock.Unit.Babbage.Simple as BabSimple
2625
import qualified Test.Cardano.Db.Mock.Unit.Babbage.Stake as BabStake
2726
import qualified Test.Cardano.Db.Mock.Unit.Babbage.Tx as BabTx
27+
import Test.Cardano.Db.Mock.Validate (expectFailSilent)
2828

2929
unitTests :: IOManager -> [(Text, Text)] -> TestTree
3030
unitTests iom knownMigrations =
@@ -45,9 +45,9 @@ unitTests iom knownMigrations =
4545
, test "no pruning and rollback" MigrateConsumedPruneTxOut.noPruneAndRollBack
4646
, test "prune same block" MigrateConsumedPruneTxOut.pruneSameBlock
4747
, test "no pruning same block" MigrateConsumedPruneTxOut.noPruneSameBlock
48-
, expectFail $ test "restart with new consumed set to false" MigrateConsumedPruneTxOut.migrateAndPruneRestart
49-
, expectFail $ test "set prune flag, restart missing prune flag" MigrateConsumedPruneTxOut.pruneRestartMissingFlag
50-
, expectFail $ test "set bootstrap flag, restart missing bootstrap flag" MigrateConsumedPruneTxOut.bootstrapRestartMissingFlag
48+
, expectFailSilent "restart with new consumed set to false" $ MigrateConsumedPruneTxOut.migrateAndPruneRestart iom knownMigrations
49+
, expectFailSilent "set prune flag, restart missing prune flag" $ MigrateConsumedPruneTxOut.pruneRestartMissingFlag iom knownMigrations
50+
, expectFailSilent "set bootstrap flag, restart missing bootstrap flag" $ MigrateConsumedPruneTxOut.bootstrapRestartMissingFlag iom knownMigrations
5151
]
5252
]
5353
, testGroup
@@ -63,7 +63,7 @@ unitTests iom knownMigrations =
6363
"Command Line Arguments"
6464
[ testGroup
6565
"config"
66-
[ expectFail $ test "fails if incorrect config file given" ConfigFile.checkConfigFileArg
66+
[ expectFailSilent "fails if incorrect config file given" $ ConfigFile.checkConfigFileArg iom knownMigrations
6767
]
6868
, testGroup
6969
"disable-epoch"

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage/Config/Parse.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ insertConfig = do
3131
, sioGovernance = GovernanceConfig False
3232
, sioOffchainPoolData = OffchainPoolDataConfig False
3333
, sioJsonType = JsonTypeDisable
34+
, sioAddJsonbToSchema = AddJsonbToSchemaConfig False
3435
}
3536

3637
dncInsertOptions cfg @?= expected

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway.hs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Cardano.Prelude
55
import qualified Test.Cardano.Db.Mock.Unit.Conway.CommandLineArg.ConfigFile as ConfigFile
66
import qualified Test.Cardano.Db.Mock.Unit.Conway.CommandLineArg.EpochDisabled as EpochDisabled
77
import qualified Test.Cardano.Db.Mock.Unit.Conway.CommandLineArg.ForceIndex as ForceIndex
8+
import qualified Test.Cardano.Db.Mock.Unit.Conway.Config.JsonbInSchema as Config
89
import qualified Test.Cardano.Db.Mock.Unit.Conway.Config.MigrateConsumedPruneTxOut as MigrateConsumedPruneTxOut
910
import qualified Test.Cardano.Db.Mock.Unit.Conway.Config.Parse as Config
1011
import qualified Test.Cardano.Db.Mock.Unit.Conway.Governance as Governance
@@ -16,8 +17,8 @@ import qualified Test.Cardano.Db.Mock.Unit.Conway.Rollback as Rollback
1617
import qualified Test.Cardano.Db.Mock.Unit.Conway.Simple as Simple
1718
import qualified Test.Cardano.Db.Mock.Unit.Conway.Stake as Stake
1819
import qualified Test.Cardano.Db.Mock.Unit.Conway.Tx as Tx
20+
import Test.Cardano.Db.Mock.Validate (expectFailSilent)
1921
import Test.Tasty (TestTree (), testGroup)
20-
import Test.Tasty.ExpectedFailure (expectFail)
2122
import Test.Tasty.HUnit (Assertion (), testCase)
2223
import Prelude (String ())
2324

@@ -34,6 +35,13 @@ unitTests iom knownMigrations =
3435
, testCase "mismatched conway genesis hash" Config.wrongConwayGenesisHash
3536
, testCase "default insert config" Config.defaultInsertConfig
3637
, testCase "insert config" Config.insertConfig
38+
, testGroup
39+
"jsonb-in-schema"
40+
[ test "jsonb in schema true" Config.configJsonbInSchemaTrue
41+
, test "jsonb in schema false" Config.configJsonbInSchemaFalse
42+
, expectFailSilent "jsonb in schema should Error" $
43+
Config.configJsonbInSchemaShouldError iom knownMigrations
44+
]
3745
, testGroup
3846
"tx-out"
3947
[ test "consumed_by_tx_id column check" MigrateConsumedPruneTxOut.txConsumedColumnCheck
@@ -45,18 +53,15 @@ unitTests iom knownMigrations =
4553
, test "no pruning and rollback" MigrateConsumedPruneTxOut.noPruneAndRollBack
4654
, test "prune same block" MigrateConsumedPruneTxOut.pruneSameBlock
4755
, test "no pruning same block" MigrateConsumedPruneTxOut.noPruneSameBlock
48-
, expectFail $
49-
test
50-
"restart with new consumed set to false"
51-
MigrateConsumedPruneTxOut.migrateAndPruneRestart
52-
, expectFail $
53-
test
54-
"set prune flag, restart missing prune flag"
55-
MigrateConsumedPruneTxOut.pruneRestartMissingFlag
56-
, expectFail $
57-
test
58-
"set bootstrap flag, restart missing bootstrap flag"
59-
MigrateConsumedPruneTxOut.bootstrapRestartMissingFlag
56+
, expectFailSilent
57+
"restart with new consumed set to false"
58+
$ MigrateConsumedPruneTxOut.migrateAndPruneRestart iom knownMigrations
59+
, expectFailSilent
60+
"set prune flag, restart missing prune flag"
61+
$ MigrateConsumedPruneTxOut.pruneRestartMissingFlag iom knownMigrations
62+
, expectFailSilent
63+
"set bootstrap flag, restart missing bootstrap flag"
64+
$ MigrateConsumedPruneTxOut.bootstrapRestartMissingFlag iom knownMigrations
6065
]
6166
]
6267
, testGroup
@@ -72,10 +77,9 @@ unitTests iom knownMigrations =
7277
"Command Line Arguments"
7378
[ testGroup
7479
"config"
75-
[ expectFail $
76-
test
77-
"fails if incorrect config file given"
78-
ConfigFile.checkConfigFileArg
80+
[ expectFailSilent
81+
"fails if incorrect config file given"
82+
$ ConfigFile.checkConfigFileArg iom knownMigrations
7983
]
8084
, testGroup
8185
"disable-epoch"
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{-# LANGUAGE NumericUnderscores #-}
2+
{-# LANGUAGE OverloadedStrings #-}
3+
4+
module Test.Cardano.Db.Mock.Unit.Conway.Config.JsonbInSchema (
5+
configJsonbInSchemaTrue,
6+
configJsonbInSchemaFalse,
7+
configJsonbInSchemaShouldError,
8+
) where
9+
10+
import qualified Cardano.Db as DB
11+
import Cardano.DbSync.Config (SyncNodeConfig (..))
12+
import Cardano.DbSync.Config.Types (AddJsonbToSchemaConfig (..), SyncInsertOptions (..))
13+
import Cardano.Mock.ChainSync.Server (IOManager ())
14+
import Cardano.Prelude hiding (head)
15+
import Test.Cardano.Db.Mock.Config
16+
import Test.Cardano.Db.Mock.Validate
17+
import Test.Tasty.HUnit (Assertion ())
18+
19+
configJsonbInSchemaTrue :: IOManager -> [(Text, Text)] -> Assertion
20+
configJsonbInSchemaTrue ioManager metadata = do
21+
syncNodeConfig <- mksNodeConfig
22+
withCustomConfigAndDropDB args (Just syncNodeConfig) cfgDir testLabel action ioManager metadata
23+
where
24+
action = \_interpreter _mockServer dbSync -> do
25+
startDBSync dbSync
26+
threadDelay 2_000_000
27+
assertEqQuery
28+
dbSync
29+
DB.queryJsonbInSchemaExists
30+
True
31+
"There should be jsonb data types in database if option is active"
32+
checkStillRuns dbSync
33+
34+
args = initCommandLineArgs {claFullMode = False}
35+
testLabel = "conwayConfigJsonbInSchemaTrue"
36+
37+
cfgDir = conwayConfigDir
38+
39+
mksNodeConfig :: IO SyncNodeConfig
40+
mksNodeConfig = do
41+
initConfigFile <- mkSyncNodeConfig cfgDir args
42+
let dncInsertOptions' = dncInsertOptions initConfigFile
43+
pure $
44+
initConfigFile
45+
{ dncInsertOptions = dncInsertOptions' {sioAddJsonbToSchema = AddJsonbToSchemaConfig True}
46+
}
47+
48+
configJsonbInSchemaFalse :: IOManager -> [(Text, Text)] -> Assertion
49+
configJsonbInSchemaFalse ioManager metadata = do
50+
syncNodeConfig <- mksNodeConfig
51+
withCustomConfigAndDropDB args (Just syncNodeConfig) cfgDir testLabel action ioManager metadata
52+
where
53+
action = \_interpreter _mockServer dbSync -> do
54+
startDBSync dbSync
55+
threadDelay 2_000_000
56+
assertEqQuery
57+
dbSync
58+
DB.queryJsonbInSchemaExists
59+
False
60+
"There should be no jsonb types in database if option isn't active"
61+
checkStillRuns dbSync
62+
63+
args = initCommandLineArgs {claFullMode = False}
64+
testLabel = "conwayConfigJsonbInSchemaFalse"
65+
66+
cfgDir = conwayConfigDir
67+
68+
mksNodeConfig :: IO SyncNodeConfig
69+
mksNodeConfig = do
70+
initConfigFile <- mkSyncNodeConfig cfgDir args
71+
let dncInsertOptions' = dncInsertOptions initConfigFile
72+
pure $
73+
initConfigFile
74+
{ dncInsertOptions = dncInsertOptions' {sioAddJsonbToSchema = AddJsonbToSchemaConfig False}
75+
}
76+
77+
configJsonbInSchemaShouldError :: IOManager -> [(Text, Text)] -> Assertion
78+
configJsonbInSchemaShouldError ioManager metadata = do
79+
syncNodeConfig <- mksNodeConfig
80+
withCustomConfigAndDropDB args (Just syncNodeConfig) cfgDir testLabel action ioManager metadata
81+
where
82+
action = \_interpreter _mockServer dbSync -> do
83+
startDBSync dbSync
84+
threadDelay 2_000_000
85+
stopDBSync dbSync
86+
let newDbSyncEnv =
87+
dbSync
88+
{ dbSyncConfig =
89+
(dbSyncConfig dbSync)
90+
{ dncInsertOptions =
91+
(dncInsertOptions $ dbSyncConfig dbSync)
92+
{ sioAddJsonbToSchema = AddJsonbToSchemaConfig False
93+
}
94+
}
95+
}
96+
startDBSync newDbSyncEnv
97+
threadDelay 2_000_000
98+
-- Expected to fail
99+
checkStillRuns dbSync
100+
101+
args = initCommandLineArgs {claFullMode = False}
102+
testLabel = "conwayConfigJsonbInSchemaShouldError"
103+
104+
cfgDir = conwayConfigDir
105+
106+
mksNodeConfig :: IO SyncNodeConfig
107+
mksNodeConfig = do
108+
initConfigFile <- mkSyncNodeConfig cfgDir args
109+
let dncInsertOptions' = dncInsertOptions initConfigFile
110+
pure $
111+
initConfigFile
112+
{ dncInsertOptions = dncInsertOptions' {sioAddJsonbToSchema = AddJsonbToSchemaConfig True}
113+
}

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway/Config/Parse.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ insertConfig = do
101101
, sioGovernance = GovernanceConfig False
102102
, sioOffchainPoolData = OffchainPoolDataConfig False
103103
, sioJsonType = JsonTypeDisable
104+
, sioAddJsonbToSchema = AddJsonbToSchemaConfig False
104105
}
105106

106107
dncInsertOptions cfg @?= expected

0 commit comments

Comments
 (0)