Skip to content

Commit 728a5c4

Browse files
committed
update tests for txout variants and running txout migrations
1 parent 421611f commit 728a5c4

File tree

18 files changed

+209
-487
lines changed

18 files changed

+209
-487
lines changed

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
@@ -29,10 +29,7 @@ module Test.Cardano.Db.Mock.Unit.Alonzo.Plutus (
2929
) where
3030

3131
import qualified Cardano.Crypto.Hash as Crypto
32-
import Cardano.Db (TxOutTableType (..))
3332
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
3633
import Cardano.DbSync.Era.Shelley.Generic.Util (renderAddress)
3734
import Cardano.Ledger.Coin
3835
import Cardano.Ledger.Mary.Value (MaryValue (..), MultiAsset (..), PolicyID (..))
@@ -76,6 +73,9 @@ import Test.Cardano.Db.Mock.Validate (
7673
assertScriptCert,
7774
)
7875
import Test.Tasty.HUnit (Assertion)
76+
import Cardano.Db (TxOutTableType(..))
77+
import qualified Cardano.Db.Schema.Core.TxOut as C
78+
import qualified Cardano.Db.Schema.Variant.TxOut as V
7979

8080
----------------------------------------------------------------------------------------------------------
8181
-- Plutus Spend Scripts
@@ -110,7 +110,7 @@ simpleScript =
110110
, V.txOutValue txout
111111
, V.txOutDataHash txout
112112
)
113-
Nothing -> error "AlonzosimpleScript: expected an address"
113+
Nothing -> error "AlonzoSimpleScript: expected an address"
114114
expectedFields =
115115
( renderAddress alwaysSucceedsScriptAddr
116116
, True

cardano-db-sync/src/Cardano/DbSync/Api.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ initPruneConsumeMigration :: Bool -> Bool -> Bool -> Bool -> DB.PruneConsumeMigr
168168
initPruneConsumeMigration consumed pruneTxOut bootstrap forceTxIn' =
169169
DB.PruneConsumeMigration
170170
{ DB.pcmPruneTxOut = pruneTxOut || bootstrap
171+
, DB.pcmConsumedTxOut = consumed
171172
, DB.pcmConsumeOrPruneTxOut = consumed || pruneTxOut || bootstrap
172173
, DB.pcmSkipTxIn = not forceTxIn' && (consumed || pruneTxOut || bootstrap)
173174
}

cardano-db-sync/src/Cardano/DbSync/Config/Types.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ optionsToList SyncInsertOptions {..} =
470470
, toJsonIfSet "offchain_pool_data" sioOffchainPoolData
471471
, toJsonIfSet "pool_stats" sioPoolStats
472472
, toJsonIfSet "json_type" sioJsonType
473+
, toJsonIfSet "remove_jsonb_from_schema" sioRemoveJsonbFromSchema
473474
]
474475

475476
toJsonIfSet :: ToJSON a => Text -> a -> Maybe Pair
@@ -562,8 +563,8 @@ instance ToJSON TxOutConfig where
562563
instance FromJSON TxOutConfig where
563564
parseJSON = Aeson.withObject "tx_out" $ \obj -> do
564565
val <- obj .: "value"
565-
useAddress' <- obj .: "use_address_table" .!= UseTxOutAddress False
566566
forceTxIn' <- obj .:? "force_tx_in" .!= ForceTxIn False
567+
useAddress' <- obj .:? "use_address_table" .!= UseTxOutAddress False
567568

568569
case val :: Text of
569570
"enable" -> pure (TxOutEnable useAddress')

cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Query.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module Cardano.DbSync.Era.Shelley.Query (
1212
) where
1313

1414
import Cardano.Db
15-
import qualified Cardano.DbSync.Api as Db
15+
import Cardano.DbSync.Api (getTxOutTableType)
1616
import Cardano.DbSync.Api.Types (SyncEnv)
1717
import qualified Cardano.DbSync.Era.Shelley.Generic as Generic
1818
import Cardano.DbSync.Util
@@ -28,16 +28,16 @@ resolveStakeAddress addr = queryStakeAddress addr renderByteArray
2828

2929
resolveInputTxOutId :: MonadIO m => SyncEnv -> Generic.TxIn -> ReaderT SqlBackend m (Either LookupFail (TxId, TxOutIdW))
3030
resolveInputTxOutId syncEnv txIn =
31-
queryTxOutId (Db.getTxOutTableType syncEnv) (Generic.toTxHash txIn, fromIntegral (Generic.txInIndex txIn))
31+
queryTxOutId (getTxOutTableType syncEnv) (Generic.toTxHash txIn, fromIntegral (Generic.txInIndex txIn))
3232

3333
resolveInputValue :: MonadIO m => SyncEnv -> Generic.TxIn -> ReaderT SqlBackend m (Either LookupFail (TxId, DbLovelace))
3434
resolveInputValue syncEnv txIn =
35-
queryTxOutValue (Db.getTxOutTableType syncEnv) (Generic.toTxHash txIn, fromIntegral (Generic.txInIndex txIn))
35+
queryTxOutValue (getTxOutTableType syncEnv) (Generic.toTxHash txIn, fromIntegral (Generic.txInIndex txIn))
3636

3737
resolveInputTxOutIdValue :: MonadIO m => SyncEnv -> Generic.TxIn -> ReaderT SqlBackend m (Either LookupFail (TxId, TxOutIdW, DbLovelace))
3838
resolveInputTxOutIdValue syncEnv txIn =
39-
queryTxOutIdValue (Db.getTxOutTableType syncEnv) (Generic.toTxHash txIn, fromIntegral (Generic.txInIndex txIn))
39+
queryTxOutIdValue (getTxOutTableType syncEnv) (Generic.toTxHash txIn, fromIntegral (Generic.txInIndex txIn))
4040

4141
queryResolveInputCredentials :: MonadIO m => SyncEnv -> Generic.TxIn -> ReaderT SqlBackend m (Either LookupFail (Maybe ByteString, Bool))
4242
queryResolveInputCredentials syncEnv txIn = do
43-
queryTxOutCredentials (Db.getTxOutTableType syncEnv) (Generic.toTxHash txIn, fromIntegral (Generic.txInIndex txIn))
43+
queryTxOutCredentials (getTxOutTableType syncEnv) (Generic.toTxHash txIn, fromIntegral (Generic.txInIndex txIn))

cardano-db-sync/src/Cardano/DbSync/Fix/ConsumedBy.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import qualified Cardano.Chain.Block as Byron hiding (blockHash)
77
import qualified Cardano.Chain.UTxO as Byron
88
import qualified Cardano.Crypto as Crypto (serializeCborHash)
99
import qualified Cardano.Db as DB
10+
import Cardano.DbSync.Api (getTrace, getTxOutTableType)
11+
import Cardano.DbSync.Api.Types (SyncEnv)
1012
import Cardano.DbSync.Era.Byron.Insert
1113
import Cardano.DbSync.Era.Byron.Util (blockPayload, unTxHash)
1214
import Cardano.DbSync.Era.Util
@@ -16,8 +18,6 @@ import Cardano.Prelude hiding (length, (.))
1618
import Database.Persist.SqlBackend.Internal
1719
import Ouroboros.Consensus.Byron.Ledger (ByronBlock (..))
1820
import Ouroboros.Consensus.Cardano.Block (HardForkBlock (..))
19-
import Cardano.DbSync.Api.Types (SyncEnv)
20-
import Cardano.DbSync.Api (getTxOutTableType, getTrace)
2121

2222
type FixEntry = (DB.TxOutIdW, DB.TxId)
2323

cardano-db-sync/test/Cardano/DbSync/Config/TypesTest.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ tests =
3232
prop_syncInsertConfigFromJSON :: Property
3333
prop_syncInsertConfigFromJSON = property $ do
3434
json <- forAll genDefaultJson
35-
3635
Aeson.fromJSON json === Aeson.Success (def :: SyncInsertConfig)
3736

3837
prop_syncInsertConfigRoundtrip :: Property
@@ -118,7 +117,9 @@ genDefaultJson =
118117
[ [aesonQQ|
119118
{
120119
"tx_out": {
121-
"value": "enable"
120+
"value": "enable",
121+
"use_address_table": false,
122+
"force_tx_in": false
122123
},
123124
"ledger": "enable",
124125
"shelley": {
@@ -148,7 +149,8 @@ genDefaultJson =
148149
, [aesonQQ|
149150
{
150151
"tx_out": {
151-
"value": "enable"
152+
"value": "enable",
153+
"use_address_table": false
152154
},
153155
"ledger": "enable",
154156
"shelley": {

cardano-db-tool/app/cardano-db-tool.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ runCommand cmd =
6464
void $
6565
runMigrations pgConfig False mdir mldir Fix
6666
CmdTxOutMigration txOutTableType -> do
67-
runWithConnectionNoLogging PGPassDefaultEnv $ migrateTxOut Nothing txOutTableType
67+
runWithConnectionNoLogging PGPassDefaultEnv $ migrateTxOutTests txOutTableType
6868
CmdUtxoSetAtBlock blkid txOutAddressType -> utxoSetAtSlot txOutAddressType blkid
6969
CmdPrepareSnapshot pargs -> runPrepareSnapshot pargs
7070
CmdValidateDb txOutAddressType -> runDbValidation txOutAddressType

cardano-db/app/gen-schema-docs.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ docHeader branchName =
6060
, "** which may not accurately reflect the version number)"
6161
]
6262
, "\n"
63-
, "**Note:** This file is auto-generated from the documentation in cardano-db/src/Cardano/Db/Schema.hs\
63+
, "**Note:** This file is auto-generated from the documentation in cardano-db/src/Cardano/Db/Schema/BaseSchema.hs\
6464
\ by the command `cabal run -- gen-schema-docs doc/schema.md`. This document should only be updated\
6565
\ during the release process and updated on the release branch."
6666
, "\n"

cardano-db/src/Cardano/Db.hs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ module Cardano.Db (
66
Tx (..),
77
TxIn (..),
88
gitRev,
9-
-- CTX.migrateTxOut,
10-
-- CTX.runExtraMigrations,
11-
-- CTX.queryTxConsumedColumnExists,
12-
-- CTX.queryTxOutConsumedNullCount,
13-
-- CTX.queryTxOutConsumedCount,
14-
-- CTX.querySetNullTxOut,
159
) where
1610

1711
import Cardano.Db.Error as X
@@ -25,11 +19,7 @@ import Cardano.Db.Operations.Core.MinId as X
2519
import Cardano.Db.Operations.Core.Query as X
2620
import Cardano.Db.Operations.Core.QueryHelper as X
2721
import Cardano.Db.Operations.Types as X
28-
29-
-- import qualified Cardano.Db.Operations.Variant.ConsumedTxOut as CTX
3022
import Cardano.Db.Operations.Variant.ConsumedTxOut as X
31-
32-
-- (migrateTxOut, queryTxConsumedColumnExists, queryTxOutConsumedCount, queryTxOutConsumedNullCount, runExtraMigrations, querySetNullTxOut)
3323
import Cardano.Db.Operations.Variant.JsonbQuery as X
3424
import Cardano.Db.Operations.Variant.TxOutDelete as X
3525
import Cardano.Db.Operations.Variant.TxOutInsert as X

cardano-db/src/Cardano/Db/Migration.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import Cardano.Db.Operations.Core.Query
3232
import Cardano.Db.PGConfig
3333
import Cardano.Db.Run
3434
import Cardano.Db.Schema.BaseSchema
35+
import Cardano.Db.Schema.Core.TxOut (migrateCoreTxOutCardanoDb)
3536
import Cardano.Prelude (Typeable, textShow)
3637
import Control.Exception (Exception, SomeException, handle)
3738
import Control.Monad.Extra
@@ -238,7 +239,9 @@ createMigration source (MigrationDir migdir) = do
238239
create :: ReaderT SqlBackend (NoLoggingT IO) (Maybe (MigrationVersion, Text))
239240
create = do
240241
ver <- getSchemaVersion
241-
statements <- getMigration migrateBaseCardanoDb
242+
statementsBase <- getMigration migrateBaseCardanoDb
243+
statementsTxOut <- getMigration migrateCoreTxOutCardanoDb
244+
let statements = statementsBase <> statementsTxOut
242245
if null statements
243246
then pure Nothing
244247
else do

0 commit comments

Comments
 (0)