Skip to content

Commit 66f9532

Browse files
committed
pass all tests
1 parent 7eb5124 commit 66f9532

File tree

19 files changed

+206
-151
lines changed

19 files changed

+206
-151
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ module Test.Cardano.Db.Mock.Config (
5151
withDBSyncEnv,
5252
withFullConfig,
5353
withFullConfigDropDb,
54+
withFullConfigDropDbLog,
5455
withFullConfigLog,
5556
withCustomConfigDropDbLog,
5657
withCustomConfig,
@@ -422,6 +423,26 @@ withFullConfigDropDb =
422423
initCommandLineArgs
423424
Nothing
424425

426+
withFullConfigDropDbLog ::
427+
-- | config filepath
428+
FilePath ->
429+
-- | test label
430+
FilePath ->
431+
(Interpreter -> ServerHandle IO CardanoBlock -> DBSyncEnv -> IO a) ->
432+
IOManager ->
433+
[(Text, Text)] ->
434+
IO a
435+
withFullConfigDropDbLog =
436+
withFullConfig'
437+
( WithConfigArgs
438+
{ hasFingerprint = True
439+
, shouldLog = True
440+
, shouldDropDB = True
441+
}
442+
)
443+
initCommandLineArgs
444+
Nothing
445+
425446
withFullConfigLog ::
426447
-- | config filepath
427448
FilePath ->

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ import Cardano.Mock.Forging.Interpreter (Interpreter, getCurrentEpoch)
3737
import qualified Cardano.Mock.Forging.Tx.Conway as Conway
3838
import qualified Cardano.Mock.Forging.Tx.Generic as Forging
3939
import Cardano.Mock.Forging.Types
40-
import Cardano.Prelude
40+
import Cardano.Prelude (MonadIO (..), void)
4141
import Cardano.Slotting.Slot (EpochNo (..))
4242
import qualified Data.Map as Map
43-
import Data.Maybe (fromJust)
43+
import Data.Maybe (fromJust, isJust, isNothing)
4444
import Data.Maybe.Strict (StrictMaybe (..))
45+
import Data.Text (Text)
4546
import qualified Ouroboros.Consensus.Shelley.Eras as Consensus
4647
import Ouroboros.Network.Block (blockPoint)
4748
import Test.Cardano.Db.Mock.Config
4849
import qualified Test.Cardano.Db.Mock.UnifiedApi as Api
4950
import Test.Cardano.Db.Mock.Validate
5051
import Test.Tasty.HUnit (Assertion, assertFailure)
51-
import qualified Prelude
5252

5353
drepDistr :: IOManager -> [(Text, Text)] -> Assertion
5454
drepDistr =
@@ -526,7 +526,7 @@ rollbackHardFork =
526526
mEpochParam <- DB.queryEpochParamWithEpochNo epochNo
527527
pure $ DB.epochParamProtocolMajor <$> mEpochParam
528528
)
529-
(Just 11)
529+
(Just 10)
530530
"Unexpected governance action counts"
531531

532532
-- Fast forward to next epoch

cardano-db/cardano-db.cabal

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -184,26 +184,26 @@ test-suite test-db
184184
, text
185185
, time
186186

187-
test-suite schema-rollback
188-
default-language: Haskell2010
189-
type: exitcode-stdio-1.0
190-
main-is: schema-rollback.hs
191-
hs-source-dirs: test
192-
193-
ghc-options: -Wall
194-
-Werror
195-
-Wcompat
196-
-Wredundant-constraints
197-
-Wincomplete-patterns
198-
-Wincomplete-record-updates
199-
-Wincomplete-uni-patterns
200-
-Wunused-imports
201-
-Wunused-packages
202-
203-
build-depends: base
204-
, ansi-terminal
205-
, bytestring
206-
, cardano-db
207-
, directory
208-
, filepath
209-
, text
187+
-- test-suite schema-rollback
188+
-- default-language: Haskell2010
189+
-- type: exitcode-stdio-1.0
190+
-- main-is: schema-rollback.hs
191+
-- hs-source-dirs: test
192+
193+
-- ghc-options: -Wall
194+
-- -Werror
195+
-- -Wcompat
196+
-- -Wredundant-constraints
197+
-- -Wincomplete-patterns
198+
-- -Wincomplete-record-updates
199+
-- -Wincomplete-uni-patterns
200+
-- -Wunused-imports
201+
-- -Wunused-packages
202+
203+
-- build-depends: base
204+
-- , ansi-terminal
205+
-- , bytestring
206+
-- , cardano-db
207+
-- , directory
208+
-- , filepath
209+
-- , text

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,19 @@ runMigrations pgconfig quiet migrationDir mLogfiledir mToRun txOutVariantType =
103103
ranAll <- case (mLogfiledir, allScripts) of
104104
(_, []) ->
105105
error $ "Empty schema dir " ++ show migrationDir
106-
(Nothing, schema : scripts) -> do
106+
(Nothing, scripts) -> do
107+
-- Remove the pattern match that separates first script
107108
putStrLn "Running:"
108-
applyMigration' Nothing stdout schema
109-
(scripts', ranAll) <- filterMigrations scripts
109+
(scripts', ranAll) <- filterMigrations scripts -- Filter ALL scripts including first
110110
forM_ scripts' $ applyMigration' Nothing stdout
111111
putStrLn "Success!"
112112
pure ranAll
113-
(Just logfiledir, schema : scripts) -> do
113+
(Just logfiledir, scripts) -> do
114+
-- Remove the pattern match here too
114115
logFilename <- genLogFilename logfiledir
115116
withFile logFilename AppendMode $ \logHandle -> do
116117
unless quiet $ putStrLn "Running:"
117-
applyMigration' (Just logFilename) logHandle schema
118-
(scripts', ranAll) <- filterMigrations scripts
118+
(scripts', ranAll) <- filterMigrations scripts -- Filter ALL scripts including first
119119
forM_ scripts' $ applyMigration' (Just logFilename) logHandle
120120
unless quiet $ putStrLn "Success!"
121121
pure ranAll
@@ -212,7 +212,7 @@ applyMigration (MigrationDir location) quiet pgconfig mLogFilename logHandle (ve
212212
exitFailure
213213

214214
-- | Create a database migration.
215-
-- NOTE: This functionality will need to be reimplemented without Persistent.
215+
-- TODO: Cmdv - This functionality will need to be reimplemented without Persistent.
216216
-- For now, this serves as a placeholder.
217217
createMigration :: PGPassSource -> MigrationDir -> TxOutVariantType -> IO (Maybe FilePath)
218218
createMigration _source (MigrationDir _migdir) _txOutVariantType = do

cardano-db/src/Cardano/Db/Schema/Core/EpochAndProtocol.hs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import Cardano.Db.Types (
2323
dbInt65Encoder,
2424
dbLovelaceDecoder,
2525
dbLovelaceEncoder,
26+
maybeDbLovelaceDecoder,
27+
maybeDbLovelaceEncoder,
2628
maybeDbWord64Decoder,
2729
maybeDbWord64Encoder,
2830
syncStateDecoder,
@@ -202,7 +204,7 @@ epochParamDecoder =
202204
<*> dbLovelaceDecoder -- epochParamMinUtxoValue
203205
<*> dbLovelaceDecoder -- epochParamMinPoolCost
204206
<*> D.column (D.nullable D.bytea) -- epochParamNonce
205-
<*> maybeIdDecoder CostModelId -- epochParamCostModelId (moved from position 20 to 19)
207+
<*> maybeIdDecoder CostModelId -- epochParamCostModelId
206208
<*> D.column (D.nullable D.float8) -- epochParamPriceMem
207209
<*> D.column (D.nullable D.float8) -- epochParamPriceStep
208210
<*> maybeDbWord64Decoder -- epochParamMaxTxExMem
@@ -214,7 +216,8 @@ epochParamDecoder =
214216
<*> D.column (D.nullable $ fromIntegral <$> D.int2) -- epochParamMaxCollateralInputs
215217
<*> idDecoder BlockId -- epochParamBlockId
216218
<*> D.column (D.nullable D.bytea) -- epochParamExtraEntropy
217-
<*> D.column (D.nullable $ DbLovelace . fromIntegral <$> D.int8) -- epochParamCoinsPerUtxoSize (moved from position 19 to 31)
219+
<*> maybeDbLovelaceDecoder -- epochParamCoinsPerUtxoSize
220+
-- <*> D.column (D.nullable $ DbLovelace . fromIntegral <$> D.int8) -- epochParamCoinsPerUtxoSize
218221
<*> D.column (D.nullable D.float8) -- epochParamPvtMotionNoConfidence
219222
<*> D.column (D.nullable D.float8) -- epochParamPvtCommitteeNormal
220223
<*> D.column (D.nullable D.float8) -- epochParamPvtCommitteeNoConfidence
@@ -235,7 +238,7 @@ epochParamDecoder =
235238
<*> maybeDbWord64Decoder -- epochParamGovActionDeposit
236239
<*> maybeDbWord64Decoder -- epochParamDrepDeposit
237240
<*> maybeDbWord64Decoder -- epochParamDrepActivity
238-
<*> D.column (D.nullable D.float8) -- epochParamPvtppSecurityGroup (moved from position 36 to 52)
241+
<*> D.column (D.nullable D.float8) -- epochParamPvtppSecurityGroup
239242
<*> D.column (D.nullable D.float8) -- epochParamMinFeeRefScriptCostPerByte
240243

241244
entityEpochParamEncoder :: E.Params (Entity EpochParam)
@@ -267,7 +270,7 @@ epochParamEncoder =
267270
, epochParamMinUtxoValue >$< dbLovelaceEncoder
268271
, epochParamMinPoolCost >$< dbLovelaceEncoder
269272
, epochParamNonce >$< E.param (E.nullable E.bytea)
270-
, epochParamCostModelId >$< maybeIdEncoder getCostModelId -- moved from position 20 to 19
273+
, epochParamCostModelId >$< maybeIdEncoder getCostModelId
271274
, epochParamPriceMem >$< E.param (E.nullable E.float8)
272275
, epochParamPriceStep >$< E.param (E.nullable E.float8)
273276
, epochParamMaxTxExMem >$< maybeDbWord64Encoder
@@ -279,7 +282,7 @@ epochParamEncoder =
279282
, epochParamMaxCollateralInputs >$< E.param (E.nullable $ fromIntegral >$< E.int2)
280283
, epochParamBlockId >$< idEncoder getBlockId
281284
, epochParamExtraEntropy >$< E.param (E.nullable E.bytea)
282-
, epochParamCoinsPerUtxoSize >$< E.param (E.nullable $ fromIntegral . unDbLovelace >$< E.int8) -- moved from position 19 to 31
285+
, epochParamCoinsPerUtxoSize >$< maybeDbLovelaceEncoder
283286
, epochParamPvtMotionNoConfidence >$< E.param (E.nullable E.float8)
284287
, epochParamPvtCommitteeNormal >$< E.param (E.nullable E.float8)
285288
, epochParamPvtCommitteeNoConfidence >$< E.param (E.nullable E.float8)
@@ -300,7 +303,7 @@ epochParamEncoder =
300303
, epochParamGovActionDeposit >$< maybeDbWord64Encoder
301304
, epochParamDrepDeposit >$< maybeDbWord64Encoder
302305
, epochParamDrepActivity >$< maybeDbWord64Encoder
303-
, epochParamPvtppSecurityGroup >$< E.param (E.nullable E.float8) -- moved from position 36 to 52
306+
, epochParamPvtppSecurityGroup >$< E.param (E.nullable E.float8)
304307
, epochParamMinFeeRefScriptCostPerByte >$< E.param (E.nullable E.float8)
305308
]
306309

@@ -434,9 +437,7 @@ data AdaPots = AdaPots
434437
deriving (Show, Eq, Generic)
435438

436439
type instance Key AdaPots = AdaPotsId
437-
438-
instance DbInfo AdaPots where
439-
uniqueFields _ = ["block_id"]
440+
instance DbInfo AdaPots
440441

441442
entityAdaPotsDecoder :: D.Row (Entity AdaPots)
442443
entityAdaPotsDecoder =

cardano-db/src/Cardano/Db/Schema/Core/GovernanceAndVoting.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ entityDrepRegistrationEncoder =
133133
drepRegistrationEncoder :: E.Params DrepRegistration
134134
drepRegistrationEncoder =
135135
mconcat
136-
[ drepRegistrationCertIndex >$< E.param (E.nonNullable $ fromIntegral >$< E.int2)
136+
[ drepRegistrationTxId >$< Id.idEncoder Id.getTxId
137+
, drepRegistrationCertIndex >$< E.param (E.nonNullable $ fromIntegral >$< E.int2)
137138
, drepRegistrationDeposit >$< E.param (E.nullable E.int8)
138139
, drepRegistrationDrepHashId >$< Id.idEncoder Id.getDrepHashId
139140
, drepRegistrationVotingAnchorId >$< Id.maybeIdEncoder Id.getVotingAnchorId
@@ -273,6 +274,7 @@ type instance Key GovActionProposal = Id.GovActionProposalId
273274

274275
instance DbInfo GovActionProposal where
275276
jsonbFields _ = ["description"]
277+
enumFields _ = [("type", "govactiontype")]
276278

277279
entityGovActionProposalDecoder :: D.Row (Entity GovActionProposal)
278280
entityGovActionProposalDecoder =
@@ -343,7 +345,9 @@ data VotingProcedure = VotingProcedure
343345
deriving (Eq, Show, Generic)
344346

345347
type instance Key VotingProcedure = Id.VotingProcedureId
346-
instance DbInfo VotingProcedure
348+
349+
instance DbInfo VotingProcedure where
350+
enumFields _ = [("voter_role", "voterrole"), ("vote", "vote")]
347351

348352
entityVotingProcedureDecoder :: D.Row (Entity VotingProcedure)
349353
entityVotingProcedureDecoder =

cardano-db/src/Cardano/Db/Schema/Variants/TxOutAddress.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ instance DbInfo TxOutAddress where
4444
[ ("tx_id", "bigint[]")
4545
, ("index", "bigint[]")
4646
, ("stake_address_id", "bigint[]")
47-
, ("value", "bigint[]")
47+
, ("value", "numeric[]")
4848
, ("data_hash", "bytea[]")
4949
, ("inline_datum_id", "bigint[]")
5050
, ("reference_script_id", "bigint[]")

cardano-db/src/Cardano/Db/Schema/Variants/TxOutCore.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ instance DbInfo TxOutCore where
6161
, ("address_has_script", "boolean[]")
6262
, ("payment_cred", "bytea[]")
6363
, ("stake_address_id", "bigint[]")
64-
, ("value", "bigint[]")
64+
, ("value", "numeric[]")
6565
, ("data_hash", "bytea[]")
6666
, ("inline_datum_id", "bigint[]")
6767
, ("reference_script_id", "bigint[]")

cardano-db/src/Cardano/Db/Statement/Base.hs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ deleteBlock txOutVariantType block = do
10071007
-- | INSERT --------------------------------------------------------------------
10081008
insertDatumStmt :: HsqlStmt.Statement SCB.Datum Id.DatumId
10091009
insertDatumStmt =
1010-
insert
1010+
insertCheckUnique
10111011
SCB.datumEncoder
10121012
(WithResult $ HsqlD.singleRow $ Id.idDecoder Id.DatumId)
10131013

@@ -1171,7 +1171,7 @@ insertExtraKeyWitness eKeyWitness = do
11711171
--------------------------------------------------------------------------------
11721172
insertMetaStmt :: HsqlStmt.Statement SCB.Meta Id.MetaId
11731173
insertMetaStmt =
1174-
insert
1174+
insertCheckUnique
11751175
SCB.metaEncoder
11761176
(WithResult $ HsqlD.singleRow $ Id.idDecoder Id.MetaId)
11771177

@@ -1197,7 +1197,7 @@ insertRedeemer redeemer = do
11971197
--------------------------------------------------------------------------------
11981198
insertRedeemerDataStmt :: HsqlStmt.Statement SCB.RedeemerData Id.RedeemerDataId
11991199
insertRedeemerDataStmt =
1200-
insert
1200+
insertCheckUnique
12011201
SCB.redeemerDataEncoder
12021202
(WithResult $ HsqlD.singleRow $ Id.idDecoder Id.RedeemerDataId)
12031203

@@ -1271,7 +1271,7 @@ querySchemaVersion =
12711271
-- | INSERTS
12721272
insertScriptStmt :: HsqlStmt.Statement SCB.Script Id.ScriptId
12731273
insertScriptStmt =
1274-
insert
1274+
insertCheckUnique
12751275
SCB.scriptEncoder
12761276
(WithResult $ HsqlD.singleRow $ Id.idDecoder Id.ScriptId)
12771277

@@ -1448,7 +1448,7 @@ queryFeesUpToSlotNo slotNo =
14481448
HsqlSes.statement slotNo queryFeesUpToSlotNoStmt
14491449

14501450
--------------------------------------------------------------------------------
1451-
queryInvalidTxStmt :: HsqlStmt.Statement () [SCB.Tx]
1451+
queryInvalidTxStmt :: HsqlStmt.Statement () [Entity SCB.Tx]
14521452
queryInvalidTxStmt =
14531453
HsqlStmt.Statement sql HsqlE.noParams decoder True
14541454
where
@@ -1460,12 +1460,14 @@ queryInvalidTxStmt =
14601460
, " FROM " <> txTableN
14611461
, " WHERE valid_contract = FALSE"
14621462
]
1463-
decoder = HsqlD.rowList SCB.txDecoder
1463+
decoder = HsqlD.rowList SCB.entityTxDecoder
14641464

14651465
queryInvalidTx :: MonadIO m => DbAction m [SCB.Tx]
1466-
queryInvalidTx =
1467-
runDbSession (mkDbCallStack "queryInvalidTx") $
1468-
HsqlSes.statement () queryInvalidTxStmt
1466+
queryInvalidTx = do
1467+
result <-
1468+
runDbSession (mkDbCallStack "queryInvalidTx") $
1469+
HsqlSes.statement () queryInvalidTxStmt
1470+
pure $ entityVal <$> result
14691471

14701472
--------------------------------------------------------------------------------
14711473
-- TxIn

0 commit comments

Comments
 (0)