Skip to content

Commit ec24a4e

Browse files
committed
start working way through test to check conversion correct
1 parent 320423c commit ec24a4e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+4276
-1638
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ test-suite cardano-chain-gen
145145
Test.Cardano.Db.Mock.Unit.Conway.Config.JsonbInSchema
146146
Test.Cardano.Db.Mock.Unit.Conway.Config.MigrateConsumedPruneTxOut
147147
Test.Cardano.Db.Mock.Unit.Conway.Config.Parse
148+
Test.Cardano.Db.Mock.Unit.Conway.Config.Schema
148149
Test.Cardano.Db.Mock.Unit.Conway.Governance
149150
Test.Cardano.Db.Mock.Unit.Conway.InlineAndReference
150151
Test.Cardano.Db.Mock.Unit.Conway.Other

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

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ module Test.Cardano.Db.Mock.Config (
5050
startDBSync,
5151
withDBSyncEnv,
5252
withFullConfig,
53-
withFullConfigAndDropDB,
54-
withFullConfigAndLogs,
55-
withCustomConfigAndLogsAndDropDB,
53+
withFullConfigDropDb,
54+
withFullConfigLog,
55+
withCustomConfigDropDbLog,
5656
withCustomConfig,
57-
withCustomConfigAndDropDB,
58-
withCustomConfigAndLogs,
57+
withCustomConfigDropDb,
58+
withCustomConfigLog,
5959
withFullConfig',
6060
replaceConfigFile,
6161
txOutVariantTypeFromConfig,
@@ -210,7 +210,7 @@ startDBSync env = do
210210
Just _a -> error "db-sync already running"
211211
Nothing -> do
212212
let appliedRunDbSync = partialRunDbSync env (dbSyncParams env) (dbSyncConfig env)
213-
-- we async the fully applied runDbSync here ad put it into the thread
213+
-- we async the fully applied runDbSync here and put it into the thread
214214
asyncApplied <- async appliedRunDbSync
215215
void . atomically $ tryPutTMVar (dbSyncThreadVar env) asyncApplied
216216

@@ -228,7 +228,8 @@ getDBSyncPGPass :: DBSyncEnv -> DB.PGPassSource
228228
getDBSyncPGPass = enpPGPassSource . dbSyncParams
229229

230230
queryDBSync :: DBSyncEnv -> DB.DbAction (NoLoggingT IO) a -> IO a
231-
queryDBSync env = DB.runWithConnectionNoLogging (getDBSyncPGPass env)
231+
queryDBSync env = do
232+
DB.runWithConnectionNoLogging (getDBSyncPGPass env)
232233

233234
getPoolLayer :: DBSyncEnv -> IO PoolDataLayer
234235
getPoolLayer env = do
@@ -404,7 +405,7 @@ withFullConfig =
404405
Nothing
405406

406407
-- this function needs to be used where the schema needs to be rebuilt
407-
withFullConfigAndDropDB ::
408+
withFullConfigDropDb ::
408409
-- | config filepath
409410
FilePath ->
410411
-- | test label
@@ -413,7 +414,7 @@ withFullConfigAndDropDB ::
413414
IOManager ->
414415
[(Text, Text)] ->
415416
IO a
416-
withFullConfigAndDropDB =
417+
withFullConfigDropDb =
417418
withFullConfig'
418419
( WithConfigArgs
419420
{ hasFingerprint = True
@@ -424,7 +425,7 @@ withFullConfigAndDropDB =
424425
initCommandLineArgs
425426
Nothing
426427

427-
withFullConfigAndLogs ::
428+
withFullConfigLog ::
428429
-- | config filepath
429430
FilePath ->
430431
-- | test label
@@ -433,7 +434,7 @@ withFullConfigAndLogs ::
433434
IOManager ->
434435
[(Text, Text)] ->
435436
IO a
436-
withFullConfigAndLogs =
437+
withFullConfigLog =
437438
withFullConfig'
438439
( WithConfigArgs
439440
{ hasFingerprint = True
@@ -465,7 +466,7 @@ withCustomConfig =
465466
}
466467
)
467468

468-
withCustomConfigAndDropDB ::
469+
withCustomConfigDropDb ::
469470
CommandLineArgs ->
470471
-- | custom SyncNodeConfig
471472
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
@@ -477,7 +478,7 @@ withCustomConfigAndDropDB ::
477478
IOManager ->
478479
[(Text, Text)] ->
479480
IO a
480-
withCustomConfigAndDropDB =
481+
withCustomConfigDropDb =
481482
withFullConfig'
482483
( WithConfigArgs
483484
{ hasFingerprint = True
@@ -487,7 +488,7 @@ withCustomConfigAndDropDB =
487488
)
488489

489490
-- This is a usefull function to be able to see logs from DBSync when writing/debuging tests
490-
withCustomConfigAndLogs ::
491+
withCustomConfigLog ::
491492
CommandLineArgs ->
492493
-- | custom SyncNodeConfig
493494
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
@@ -499,7 +500,7 @@ withCustomConfigAndLogs ::
499500
IOManager ->
500501
[(Text, Text)] ->
501502
IO a
502-
withCustomConfigAndLogs =
503+
withCustomConfigLog =
503504
withFullConfig'
504505
( WithConfigArgs
505506
{ hasFingerprint = True
@@ -508,7 +509,7 @@ withCustomConfigAndLogs =
508509
}
509510
)
510511

511-
withCustomConfigAndLogsAndDropDB ::
512+
withCustomConfigDropDbLog ::
512513
CommandLineArgs ->
513514
-- | custom SyncNodeConfig
514515
Maybe (SyncNodeConfig -> SyncNodeConfig) ->
@@ -520,7 +521,7 @@ withCustomConfigAndLogsAndDropDB ::
520521
IOManager ->
521522
[(Text, Text)] ->
522523
IO a
523-
withCustomConfigAndLogsAndDropDB =
524+
withCustomConfigDropDbLog =
524525
withFullConfig'
525526
( WithConfigArgs
526527
{ hasFingerprint = True
@@ -560,7 +561,7 @@ withFullConfig' WithConfigArgs {..} cmdLineArgs mSyncNodeConfig configFilePath t
560561
then configureLogging syncNodeConfig "db-sync-node"
561562
else pure nullTracer
562563
-- runDbSync is partially applied so we can pass in syncNodeParams at call site / within tests
563-
let partialDbSyncRun params cfg' = runDbSync emptyMetricsSetters migr iom trce params cfg' True
564+
let partialDbSyncRun params cfg' = runDbSync emptyMetricsSetters iom trce params cfg' True
564565
initSt = Consensus.pInfoInitLedger $ protocolInfo cfg
565566

566567
withInterpreter (protocolInfoForging cfg) (protocolInfoForger cfg) nullTracer fingerFile $ \interpreter -> do
@@ -581,6 +582,14 @@ withFullConfig' WithConfigArgs {..} cmdLineArgs mSyncNodeConfig configFilePath t
581582
if null tableNames || shouldDropDB
582583
then void . hSilence [stderr] $ DB.recreateDB pgPass
583584
else void . hSilence [stderr] $ DB.truncateTables pgPass tableNames
585+
586+
-- Run migrations synchronously first
587+
runMigrationsOnly
588+
migr
589+
trce
590+
(syncNodeParams cfg)
591+
syncNodeConfig
592+
584593
action interpreter mockServer dbSyncEnv
585594
where
586595
mutableDir = mkMutableDir testLabelFilePath

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import Control.Monad (void)
6161
import qualified Data.Map as Map
6262
import Data.Text (Text)
6363
import Ouroboros.Consensus.Cardano.Block (StandardAlonzo)
64-
import Test.Cardano.Db.Mock.Config (alonzoConfigDir, startDBSync, withFullConfig, withFullConfigAndDropDB)
64+
import Test.Cardano.Db.Mock.Config (alonzoConfigDir, startDBSync, withFullConfig, withFullConfigDropDb)
6565
import Test.Cardano.Db.Mock.UnifiedApi (
6666
fillUntilNextEpoch,
6767
forgeNextAndSubmit,
@@ -82,7 +82,7 @@ import Test.Tasty.HUnit (Assertion)
8282
----------------------------------------------------------------------------------------------------------
8383
simpleScript :: IOManager -> [(Text, Text)] -> Assertion
8484
simpleScript =
85-
withFullConfigAndDropDB alonzoConfigDir testLabel $ \interpreter mockServer dbSync -> do
85+
withFullConfigDropDb alonzoConfigDir testLabel $ \interpreter mockServer dbSync -> do
8686
startDBSync dbSync
8787
void $ registerAllStakeCreds interpreter mockServer
8888

@@ -271,7 +271,7 @@ multipleScriptsFailedSameBlock =
271271

272272
registrationScriptTx :: IOManager -> [(Text, Text)] -> Assertion
273273
registrationScriptTx =
274-
withFullConfigAndDropDB alonzoConfigDir testLabel $ \interpreter mockServer dbSync -> do
274+
withFullConfigDropDb alonzoConfigDir testLabel $ \interpreter mockServer dbSync -> do
275275
startDBSync dbSync
276276

277277
void $
@@ -394,7 +394,7 @@ deregistrationsScriptTx'' =
394394

395395
mintMultiAsset :: IOManager -> [(Text, Text)] -> Assertion
396396
mintMultiAsset =
397-
withFullConfigAndDropDB alonzoConfigDir testLabel $ \interpreter mockServer dbSync -> do
397+
withFullConfigDropDb alonzoConfigDir testLabel $ \interpreter mockServer dbSync -> do
398398
startDBSync dbSync
399399
void $ withAlonzoFindLeaderAndSubmitTx interpreter mockServer $ \st -> do
400400
let val0 = MultiAsset $ Map.singleton (PolicyID alwaysMintScriptHash) (Map.singleton (head assetNames) 1)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ import Control.Concurrent.Class.MonadSTM.Strict (MonadSTM (atomically))
1212
import Control.Monad (void)
1313
import Data.Text (Text)
1414
import Ouroboros.Network.Block (blockNo)
15-
import Test.Cardano.Db.Mock.Config (alonzoConfigDir, startDBSync, stopDBSync, withFullConfig, withFullConfigAndDropDB)
15+
import Test.Cardano.Db.Mock.Config (alonzoConfigDir, startDBSync, stopDBSync, withFullConfig, withFullConfigDropDb)
1616
import Test.Cardano.Db.Mock.Examples (mockBlock0, mockBlock1, mockBlock2)
1717
import Test.Cardano.Db.Mock.UnifiedApi (forgeNextAndSubmit)
1818
import Test.Cardano.Db.Mock.Validate (assertBlockNoBackoff)
1919
import Test.Tasty.HUnit (Assertion, assertBool)
2020

2121
forgeBlocks :: IOManager -> [(Text, Text)] -> Assertion
2222
forgeBlocks = do
23-
withFullConfigAndDropDB alonzoConfigDir testLabel $ \interpreter _mockServer _dbSync -> do
23+
withFullConfigDropDb alonzoConfigDir testLabel $ \interpreter _mockServer _dbSync -> do
2424
_block0 <- forgeNext interpreter mockBlock0
2525
_block1 <- forgeNext interpreter mockBlock1
2626
block2 <- forgeNext interpreter mockBlock2

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Test.Cardano.Db.Mock.Config (
1818
alonzoConfigDir,
1919
startDBSync,
2020
withFullConfig,
21-
withFullConfigAndDropDB,
21+
withFullConfigDropDb,
2222
)
2323
import Test.Cardano.Db.Mock.UnifiedApi (
2424
withAlonzoFindLeaderAndSubmit,
@@ -29,7 +29,7 @@ import Test.Tasty.HUnit (Assertion)
2929

3030
addSimpleTx :: IOManager -> [(Text, Text)] -> Assertion
3131
addSimpleTx =
32-
withFullConfigAndDropDB alonzoConfigDir testLabel $ \interpreter mockServer dbSync -> do
32+
withFullConfigDropDb alonzoConfigDir testLabel $ \interpreter mockServer dbSync -> do
3333
-- translate the block to a real Cardano block.
3434
void $
3535
withAlonzoFindLeaderAndSubmitTx interpreter mockServer $

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import qualified Data.Map as Map
6363
import Data.Text (Text)
6464
import Ouroboros.Consensus.Cardano.Block (StandardBabbage)
6565
import Ouroboros.Network.Block (genesisPoint)
66-
import Test.Cardano.Db.Mock.Config (babbageConfigDir, startDBSync, txOutVariantTypeFromConfig, withFullConfig, withFullConfigAndDropDB)
66+
import Test.Cardano.Db.Mock.Config (babbageConfigDir, startDBSync, txOutVariantTypeFromConfig, withFullConfig, withFullConfigDropDb)
6767
import Test.Cardano.Db.Mock.UnifiedApi (
6868
fillUntilNextEpoch,
6969
forgeNextAndSubmit,
@@ -88,7 +88,7 @@ import Test.Tasty.HUnit (Assertion)
8888

8989
simpleScript :: IOManager -> [(Text, Text)] -> Assertion
9090
simpleScript =
91-
withFullConfigAndDropDB babbageConfigDir testLabel $ \interpreter mockServer dbSync -> do
91+
withFullConfigDropDb babbageConfigDir testLabel $ \interpreter mockServer dbSync -> do
9292
startDBSync dbSync
9393

9494
let txOutVariantType = txOutVariantTypeFromConfig dbSync
@@ -310,7 +310,7 @@ multipleScriptsFailedSameBlock =
310310

311311
registrationScriptTx :: IOManager -> [(Text, Text)] -> Assertion
312312
registrationScriptTx =
313-
withFullConfigAndDropDB babbageConfigDir testLabel $ \interpreter mockServer dbSync -> do
313+
withFullConfigDropDb babbageConfigDir testLabel $ \interpreter mockServer dbSync -> do
314314
startDBSync dbSync
315315

316316
void $
@@ -433,7 +433,7 @@ deregistrationsScriptTx'' =
433433

434434
mintMultiAsset :: IOManager -> [(Text, Text)] -> Assertion
435435
mintMultiAsset =
436-
withFullConfigAndDropDB babbageConfigDir testLabel $ \interpreter mockServer dbSync -> do
436+
withFullConfigDropDb babbageConfigDir testLabel $ \interpreter mockServer dbSync -> do
437437
startDBSync dbSync
438438
void $ withBabbageFindLeaderAndSubmitTx interpreter mockServer $ \st -> do
439439
let val0 = MultiAsset $ Map.singleton (PolicyID alwaysMintScriptHash) (Map.singleton (head assetNames) 1)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import Control.Monad (forM_, void)
3434
import qualified Data.Map as Map
3535
import Data.Text (Text)
3636
import Ouroboros.Network.Block (blockPoint)
37-
import Test.Cardano.Db.Mock.Config (babbageConfigDir, startDBSync, stopDBSync, withFullConfig, withFullConfigAndDropDB)
37+
import Test.Cardano.Db.Mock.Config (babbageConfigDir, startDBSync, stopDBSync, withFullConfig, withFullConfigDropDb)
3838
import Test.Cardano.Db.Mock.UnifiedApi (
3939
fillEpochPercentage,
4040
fillEpochs,
@@ -59,7 +59,7 @@ import Test.Tasty.HUnit (Assertion)
5959

6060
simpleRewards :: IOManager -> [(Text, Text)] -> Assertion
6161
simpleRewards =
62-
withFullConfigAndDropDB babbageConfigDir testLabel $ \interpreter mockServer dbSync -> do
62+
withFullConfigDropDb babbageConfigDir testLabel $ \interpreter mockServer dbSync -> do
6363
startDBSync dbSync
6464
void $ registerAllStakeCreds interpreter mockServer
6565

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import Control.Concurrent.Class.MonadSTM.Strict (atomically)
1414
import Control.Monad (void)
1515
import Data.Text (Text)
1616
import Ouroboros.Network.Block (blockNo)
17-
import Test.Cardano.Db.Mock.Config (babbageConfigDir, startDBSync, stopDBSync, withFullConfig, withFullConfigAndDropDB)
17+
import Test.Cardano.Db.Mock.Config (babbageConfigDir, startDBSync, stopDBSync, withFullConfig, withFullConfigDropDb)
1818
import Test.Cardano.Db.Mock.Examples (mockBlock0, mockBlock1, mockBlock2)
1919
import Test.Cardano.Db.Mock.UnifiedApi (fillUntilNextEpoch, forgeAndSubmitBlocks, forgeNextAndSubmit)
2020
import Test.Cardano.Db.Mock.Validate (assertBlockNoBackoff)
2121
import Test.Tasty.HUnit (Assertion, assertBool)
2222

2323
forgeBlocks :: IOManager -> [(Text, Text)] -> Assertion
2424
forgeBlocks = do
25-
withFullConfigAndDropDB babbageConfigDir testLabel $ \interpreter _mockServer _dbSync -> do
25+
withFullConfigDropDb babbageConfigDir testLabel $ \interpreter _mockServer _dbSync -> do
2626
_block0 <- forgeNext interpreter mockBlock0
2727
_block1 <- forgeNext interpreter mockBlock1
2828
block2 <- forgeNext interpreter mockBlock2

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import qualified Test.Cardano.Db.Mock.Unit.Conway.CommandLineArg.EpochDisabled a
77
import qualified Test.Cardano.Db.Mock.Unit.Conway.Config.JsonbInSchema as Config
88
import qualified Test.Cardano.Db.Mock.Unit.Conway.Config.MigrateConsumedPruneTxOut as MigrateConsumedPruneTxOut
99
import qualified Test.Cardano.Db.Mock.Unit.Conway.Config.Parse as Config
10+
import qualified Test.Cardano.Db.Mock.Unit.Conway.Config.Schema as Schema
1011
import qualified Test.Cardano.Db.Mock.Unit.Conway.Governance as Governance
1112
import qualified Test.Cardano.Db.Mock.Unit.Conway.InlineAndReference as InlineRef
1213
import qualified Test.Cardano.Db.Mock.Unit.Conway.Other as Other
@@ -42,6 +43,11 @@ unitTests iom knownMigrations =
4243
"remove jsonb from schema and add back"
4344
Config.configJsonbInSchemaShouldRemoveThenAdd
4445
]
46+
, testGroup
47+
"Schema"
48+
[ test "validate schema table columns" Schema.validateSchemaColumns
49+
, test "validate schema table columns address variant" Schema.validateVariantAddressSchemaColumns
50+
]
4551
, testGroup
4652
"tx-out"
4753
[ test "basic prune" MigrateConsumedPruneTxOut.basicPrune

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Prelude ()
1818

1919
checkEpochDisabledArg :: IOManager -> [(Text, Text)] -> Assertion
2020
checkEpochDisabledArg =
21-
withCustomConfigAndDropDB cliArgs Nothing conwayConfigDir testLabel $ \interpreter mockServer dbSync -> do
21+
withCustomConfigDropDb cliArgs Nothing conwayConfigDir testLabel $ \interpreter mockServer dbSync -> do
2222
startDBSync dbSync
2323

2424
-- Forge some blocks

0 commit comments

Comments
 (0)