Skip to content

Commit 421611f

Browse files
committed
Add variant for TxOut
Modified-by: Cmdv <[email protected]>
1 parent 97930bd commit 421611f

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

+3020
-2361
lines changed

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

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ module Test.Cardano.Db.Mock.Config (
4343
withCustomConfigAndLogs,
4444
withFullConfig',
4545
replaceConfigFile,
46+
txOutTableTypeFromConfig,
4647
) where
4748

4849
import Cardano.Api (NetworkMagic (..))
49-
import qualified Cardano.Db as Db
50+
import qualified Cardano.Db as DB
5051
import Cardano.DbSync
5152
import Cardano.DbSync.Config
5253
import Cardano.DbSync.Config.Cardano
54+
import Cardano.DbSync.Config.Types (SyncInsertOptions (..), TxOutConfig (..), UseTxOutAddress (..))
5355
import Cardano.DbSync.Error (runOrThrowIO)
5456
import Cardano.DbSync.Types (CardanoBlock, MetricSetters (..))
5557
import Cardano.Mock.ChainSync.Server
@@ -209,16 +211,16 @@ pollDBSync env = do
209211
withDBSyncEnv :: IO DBSyncEnv -> (DBSyncEnv -> IO a) -> IO a
210212
withDBSyncEnv mkEnv = bracket mkEnv stopDBSyncIfRunning
211213

212-
getDBSyncPGPass :: DBSyncEnv -> Db.PGPassSource
214+
getDBSyncPGPass :: DBSyncEnv -> DB.PGPassSource
213215
getDBSyncPGPass = enpPGPassSource . dbSyncParams
214216

215217
queryDBSync :: DBSyncEnv -> ReaderT SqlBackend (NoLoggingT IO) a -> IO a
216-
queryDBSync env = Db.runWithConnectionNoLogging (getDBSyncPGPass env)
218+
queryDBSync env = DB.runWithConnectionNoLogging (getDBSyncPGPass env)
217219

218220
getPoolLayer :: DBSyncEnv -> IO PoolDataLayer
219221
getPoolLayer env = do
220-
pgconfig <- runOrThrowIO $ Db.readPGPass (enpPGPassSource $ dbSyncParams env)
221-
pool <- runNoLoggingT $ createPostgresqlPool (Db.toConnectionString pgconfig) 1 -- Pool size of 1 for tests
222+
pgconfig <- runOrThrowIO $ DB.readPGPass (enpPGPassSource $ dbSyncParams env)
223+
pool <- runNoLoggingT $ createPostgresqlPool (DB.toConnectionString pgconfig) 1 -- Pool size of 1 for tests
222224
pure $
223225
postgresqlPoolDataLayer
224226
nullTracer
@@ -259,15 +261,15 @@ mkShelleyCredentials bulkFile = do
259261
-- | staticDir can be shared by tests running in parallel. mutableDir not.
260262
mkSyncNodeParams :: FilePath -> FilePath -> CommandLineArgs -> IO SyncNodeParams
261263
mkSyncNodeParams staticDir mutableDir CommandLineArgs {..} = do
262-
pgconfig <- runOrThrowIO Db.readPGPassDefault
264+
pgconfig <- runOrThrowIO DB.readPGPassDefault
263265

264266
pure $
265267
SyncNodeParams
266268
{ enpConfigFile = mkConfigFile staticDir claConfigFilename
267269
, enpSocketPath = SocketPath $ mutableDir </> ".socket"
268270
, enpMaybeLedgerStateDir = Just $ LedgerStateDir $ mutableDir </> "ledger-states"
269271
, enpMigrationDir = MigrationDir "../schema"
270-
, enpPGPassSource = Db.PGPassCached pgconfig
272+
, enpPGPassSource = DB.PGPassCached pgconfig
271273
, enpEpochDisabled = claEpochDisabled
272274
, enpHasCache = claHasCache
273275
, enpSkipFix = claSkipFix
@@ -503,12 +505,12 @@ withFullConfig' WithConfigArgs {..} cmdLineArgs mSyncNodeConfig configFilePath t
503505
-- we dont fork dbsync here. Just prepare it as an action
504506
withDBSyncEnv (mkDBSyncEnv dbsyncParams syncNodeConfig partialDbSyncRun) $ \dbSyncEnv -> do
505507
let pgPass = getDBSyncPGPass dbSyncEnv
506-
tableNames <- Db.getAllTablleNames pgPass
508+
tableNames <- DB.getAllTablleNames pgPass
507509
-- We only want to create the table schema once for the tests so here we check
508510
-- if there are any table names.
509511
if null tableNames || shouldDropDB
510-
then void . hSilence [stderr] $ Db.recreateDB pgPass
511-
else void . hSilence [stderr] $ Db.truncateTables pgPass tableNames
512+
then void . hSilence [stderr] $ DB.recreateDB pgPass
513+
else void . hSilence [stderr] $ DB.truncateTables pgPass tableNames
512514
action interpreter mockServer dbSyncEnv
513515
where
514516
mutableDir = mkMutableDir testLabelFilePath
@@ -534,3 +536,15 @@ replaceConfigFile newFilename dbSync@DBSyncEnv {..} = do
534536
configDir = mkConfigDir . takeDirectory . unConfigFile . enpConfigFile $ dbSyncParams
535537
newParams =
536538
dbSyncParams {enpConfigFile = ConfigFile $ configDir </> newFilename}
539+
540+
txOutTableTypeFromConfig :: DBSyncEnv -> DB.TxOutTableType
541+
txOutTableTypeFromConfig dbSyncEnv =
542+
case sioTxOut $ dncInsertOptions $ dbSyncConfig dbSyncEnv of
543+
TxOutDisable -> DB.TxOutCore
544+
TxOutEnable useTxOutAddress -> getTxOutTT useTxOutAddress
545+
TxOutConsumed _ useTxOutAddress -> getTxOutTT useTxOutAddress
546+
TxOutConsumedPrune _ useTxOutAddress -> getTxOutTT useTxOutAddress
547+
TxOutConsumedBootstrap _ useTxOutAddress -> getTxOutTT useTxOutAddress
548+
where
549+
getTxOutTT :: UseTxOutAddress -> DB.TxOutTableType
550+
getTxOutTT value = if unUseTxOutAddress value then DB.TxOutVariantAddress else DB.TxOutCore

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ insertConfig = do
3434
, sioPoolStats = PoolStatsConfig False
3535
, sioJsonType = JsonTypeDisable
3636
, sioRemoveJsonbFromSchema = RemoveJsonbFromSchemaConfig False
37-
, sioAddressDetail = AddressDetailConfig False
3837
}
3938

4039
dncInsertOptions cfg @?= expected

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ module Test.Cardano.Db.Mock.Unit.Alonzo.Plutus (
2929
) where
3030

3131
import qualified Cardano.Crypto.Hash as Crypto
32+
import Cardano.Db (TxOutTableType (..))
3233
import qualified Cardano.Db as DB
34+
import qualified Cardano.Db.Schema.Core.TxOut as C
35+
import qualified Cardano.Db.Schema.Variant.TxOut as V
3336
import Cardano.DbSync.Era.Shelley.Generic.Util (renderAddress)
3437
import Cardano.Ledger.Coin
3538
import Cardano.Ledger.Mary.Value (MaryValue (..), MultiAsset (..), PolicyID (..))
@@ -90,12 +93,26 @@ simpleScript =
9093
Alonzo.mkLockByScriptTx (UTxOIndex 0) [True] 20000 20000
9194

9295
assertBlockNoBackoff dbSync (fromIntegral $ length a + 2)
93-
assertEqQuery dbSync (fmap getOutFields <$> DB.queryScriptOutputs) [expectedFields] "Unexpected script outputs"
96+
assertEqQuery dbSync (fmap getOutFields <$> DB.queryScriptOutputs TxOutCore) [expectedFields] "Unexpected script outputs"
9497
where
9598
testLabel = "simpleScript-alonzo"
96-
getOutFields txOut = (DB.txOutAddress txOut, DB.txOutAddressHasScript txOut, DB.txOutValue txOut, DB.txOutDataHash txOut)
99+
getOutFields txOutW = case txOutW of
100+
DB.CTxOutW txOut ->
101+
( C.txOutAddress txOut
102+
, C.txOutAddressHasScript txOut
103+
, C.txOutValue txOut
104+
, C.txOutDataHash txOut
105+
)
106+
DB.VTxOutW txout mAddress -> case mAddress of
107+
Just address ->
108+
( V.addressAddress address
109+
, V.addressHasScript address
110+
, V.txOutValue txout
111+
, V.txOutDataHash txout
112+
)
113+
Nothing -> error "AlonzosimpleScript: expected an address"
97114
expectedFields =
98-
( Just $ renderAddress alwaysSucceedsScriptAddr
115+
( renderAddress alwaysSucceedsScriptAddr
99116
, True
100117
, DB.DbLovelace 20000
101118
, Just $ Crypto.hashToBytes (extractHash $ hashData @StandardAlonzo plutusDataList)

0 commit comments

Comments
 (0)