Skip to content

Commit 024fd28

Browse files
committed
add back tests
1 parent ff66b63 commit 024fd28

File tree

21 files changed

+207
-4116
lines changed

21 files changed

+207
-4116
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,21 @@ test-suite cardano-chain-gen
130130
other-modules: Test.Cardano.Db.Mock.Config
131131
Test.Cardano.Db.Mock.Examples
132132
Test.Cardano.Db.Mock.Property.Property
133+
Test.Cardano.Db.Mock.UnifiedApi
134+
Test.Cardano.Db.Mock.Unit.Alonzo
135+
Test.Cardano.Db.Mock.Unit.Alonzo.Config
136+
Test.Cardano.Db.Mock.Unit.Alonzo.Simple
137+
Test.Cardano.Db.Mock.Unit.Alonzo.Tx
138+
Test.Cardano.Db.Mock.Unit.Babbage
139+
Test.Cardano.Db.Mock.Unit.Babbage.Reward
140+
Test.Cardano.Db.Mock.Unit.Babbage.Simple
141+
Test.Cardano.Db.Mock.Unit.Babbage.Tx
133142
Test.Cardano.Db.Mock.Unit.Conway
134143
Test.Cardano.Db.Mock.Unit.Conway.CommandLineArg.ConfigFile
135144
Test.Cardano.Db.Mock.Unit.Conway.CommandLineArg.EpochDisabled
136145
Test.Cardano.Db.Mock.Unit.Conway.Config.JsonbInSchema
137-
Test.Cardano.Db.Mock.Unit.Conway.Config.Parse
138146
Test.Cardano.Db.Mock.Unit.Conway.Config.MigrateConsumedPruneTxOut
147+
Test.Cardano.Db.Mock.Unit.Conway.Config.Parse
139148
Test.Cardano.Db.Mock.Unit.Conway.Governance
140149
Test.Cardano.Db.Mock.Unit.Conway.InlineAndReference
141150
Test.Cardano.Db.Mock.Unit.Conway.Other
@@ -145,7 +154,6 @@ test-suite cardano-chain-gen
145154
Test.Cardano.Db.Mock.Unit.Conway.Simple
146155
Test.Cardano.Db.Mock.Unit.Conway.Stake
147156
Test.Cardano.Db.Mock.Unit.Conway.Tx
148-
Test.Cardano.Db.Mock.UnifiedApi
149157
Test.Cardano.Db.Mock.Validate
150158

151159
build-depends: aeson

cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Babbage.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ mkUTxOBabbage :: AlonzoTx StandardBabbage -> [(TxIn StandardCrypto, BabbageTxOut
462462
mkUTxOBabbage = mkUTxOAlonzo
463463

464464
mkUTxOCollBabbage ::
465-
(BabbageEraTxBody era) =>
465+
BabbageEraTxBody era =>
466466
AlonzoTx era ->
467467
[(TxIn (EraCrypto era), TxOut era)]
468468
mkUTxOCollBabbage tx = Map.toList $ unUTxO $ collOuts $ getField @"body" tx

cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Conway.hs

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,17 @@ mkPaymentTx' inputIndex outputIndices fees donation state' = do
227227
NoDatum
228228
SNothing
229229

230-
pure $
231-
mkSimpleTx True $
232-
consPaymentTxBody
233-
inputs
234-
mempty
235-
mempty
236-
(StrictSeq.fromList $ outputs <> [change])
237-
SNothing
238-
(Coin fees)
239-
mempty
240-
(Coin donation)
230+
pure
231+
$ mkSimpleTx True
232+
$ consPaymentTxBody
233+
inputs
234+
mempty
235+
mempty
236+
(StrictSeq.fromList $ outputs <> [change])
237+
SNothing
238+
(Coin fees)
239+
mempty
240+
(Coin donation)
241241
where
242242
mkOutputs (outIx, val) = do
243243
addr <- resolveAddress outIx state'
@@ -268,17 +268,17 @@ mkLockByScriptTx inputIndex txOutTypes amount fees state' = do
268268
NoDatum
269269
SNothing
270270

271-
pure $
272-
mkSimpleTx True $
273-
consPaymentTxBody
274-
inputs
275-
mempty
276-
mempty
277-
(StrictSeq.fromList $ outputs <> [change])
278-
SNothing
279-
(Coin fees)
280-
mempty
281-
(Coin 0)
271+
pure
272+
$ mkSimpleTx True
273+
$ consPaymentTxBody
274+
inputs
275+
mempty
276+
mempty
277+
(StrictSeq.fromList $ outputs <> [change])
278+
SNothing
279+
(Coin fees)
280+
mempty
281+
(Coin 0)
282282

283283
mkUnlockScriptTx ::
284284
[ConwayUTxOIndex] ->
@@ -348,9 +348,9 @@ mkDCertPoolTx consDCert state' = do
348348

349349
mkDCertTxPools :: ConwayLedgerState -> Either ForgingError (AlonzoTx StandardConway)
350350
mkDCertTxPools state' =
351-
Right $
352-
mkSimpleTx True $
353-
consCertTxBody Nothing (allPoolStakeCert' state') (Withdrawals mempty)
351+
Right
352+
$ mkSimpleTx True
353+
$ consCertTxBody Nothing (allPoolStakeCert' state') (Withdrawals mempty)
354354

355355
mkSimpleTx :: Bool -> ConwayTxBody StandardConway -> AlonzoTx StandardConway
356356
mkSimpleTx isValid' txBody =
@@ -394,9 +394,9 @@ mkScriptDCertTx consCert isValid' state' = do
394394
cred <- resolveStakeCreds stakeIndex state'
395395
pure $ mkDCert cred
396396

397-
pure $
398-
mkScriptTx isValid' (mapMaybe prepareRedeemer . zip [0 ..] $ consCert) $
399-
consCertTxBody Nothing dcerts (Withdrawals mempty)
397+
pure
398+
$ mkScriptTx isValid' (mapMaybe prepareRedeemer . zip [0 ..] $ consCert)
399+
$ consCertTxBody Nothing dcerts (Withdrawals mempty)
400400
where
401401
prepareRedeemer (n, (StakeIndexScript bl, shouldAddRedeemer, _))
402402
| not shouldAddRedeemer = Nothing
@@ -428,24 +428,24 @@ mkMultiAssetsScriptTx inputIx colInputIx outputIx refInput minted succeeds fees
428428
refInputs' = Set.fromList $ map (fst . fst) refs
429429
colInputs' = Set.singleton $ fst colInput
430430

431-
pure $
432-
mkScriptTx succeeds (mkScriptInps (map fst inputs) ++ mkScriptMint' minted) $
433-
consTxBody
434-
inputs'
435-
colInputs'
436-
refInputs'
437-
(StrictSeq.fromList outputs)
438-
SNothing
439-
(Coin fees)
440-
mempty
441-
mempty -- TODO[sgillespie]: minted?
442-
(Withdrawals mempty)
443-
(Coin 0)
431+
pure
432+
$ mkScriptTx succeeds (mkScriptInps (map fst inputs) ++ mkScriptMint' minted)
433+
$ consTxBody
434+
inputs'
435+
colInputs'
436+
refInputs'
437+
(StrictSeq.fromList outputs)
438+
SNothing
439+
(Coin fees)
440+
mempty
441+
mempty -- TODO[sgillespie]: minted?
442+
(Withdrawals mempty)
443+
(Coin 0)
444444
where
445445
mkOuts (outIx, val) = do
446446
addr <- resolveAddress outIx state'
447-
pure $
448-
BabbageTxOut
447+
pure
448+
$ BabbageTxOut
449449
addr
450450
val
451451
(DatumHash $ hashData @StandardConway plutusDataList)
@@ -468,19 +468,19 @@ mkDepositTxPools inputIndex deposit state' = do
468468
NoDatum
469469
SNothing
470470

471-
pure $
472-
mkSimpleTx True $
473-
consTxBody
474-
input
475-
mempty
476-
mempty
477-
(StrictSeq.fromList [change])
478-
SNothing
479-
(Coin 0)
480-
mempty
481-
(allPoolStakeCert' state')
482-
(Withdrawals mempty)
483-
(Coin 0)
471+
pure
472+
$ mkSimpleTx True
473+
$ consTxBody
474+
input
475+
mempty
476+
mempty
477+
(StrictSeq.fromList [change])
478+
SNothing
479+
(Coin 0)
480+
mempty
481+
(allPoolStakeCert' state')
482+
(Withdrawals mempty)
483+
(Coin 0)
484484

485485
mkRegisterDRepTx ::
486486
Credential 'DRepRole StandardCrypto ->
@@ -663,8 +663,8 @@ mkFullTx n m state' = do
663663
refInputPairs <- fmap fst <$> mapM (`resolveUTxOIndex` state') refInputs
664664
collateralInput <- Set.singleton . fst . fst <$> resolveUTxOIndex collateralInputs state'
665665

666-
pure $
667-
AlonzoTx
666+
pure
667+
$ AlonzoTx
668668
{ body =
669669
txBody
670670
(mkInputs inputPairs)
@@ -748,8 +748,8 @@ mkFullTx n m state' = do
748748
, ConwayTxCertPool $ Core.RegPool poolParams1
749749
, ConwayTxCertPool $ Core.RetirePool (Prelude.head unregisteredPools) (EpochNo 0)
750750
, ConwayTxCertDeleg $ ConwayUnRegCert (unregisteredStakeCredentials !! 2) SNothing
751-
, ConwayTxCertDeleg $
752-
ConwayDelegCert
751+
, ConwayTxCertDeleg
752+
$ ConwayDelegCert
753753
(unregisteredStakeCredentials !! 1)
754754
(DelegStake $ unregisteredPools !! 2)
755755
]
@@ -766,8 +766,8 @@ mkFullTx n m state' = do
766766

767767
-- Withdrawals
768768
withdrawals =
769-
Withdrawals $
770-
Map.fromList
769+
Withdrawals
770+
$ Map.fromList
771771
[ (RewardAccount Testnet (unregisteredStakeCredentials !! 1), Coin 100)
772772
, (RewardAccount Testnet (unregisteredStakeCredentials !! 1), Coin 100)
773773
]
@@ -899,17 +899,17 @@ mkUnlockScriptTx' inputIndex colInputIndex outputIndex refInput colOut succeeds
899899
NoDatum
900900
SNothing
901901

902-
pure $
903-
mkScriptTx succeeds (mkScriptInps inputPairs) $
904-
consPaymentTxBody
905-
inputs
906-
colInputs
907-
refInputs
908-
(StrictSeq.singleton output)
909-
(maybeToStrictMaybe colOut)
910-
(Coin fees)
911-
mempty
912-
(Coin 0)
902+
pure
903+
$ mkScriptTx succeeds (mkScriptInps inputPairs)
904+
$ consPaymentTxBody
905+
inputs
906+
colInputs
907+
refInputs
908+
(StrictSeq.singleton output)
909+
(maybeToStrictMaybe colOut)
910+
(Coin fees)
911+
mempty
912+
(Coin 0)
913913

914914
allPoolStakeCert' :: ConwayLedgerState -> [ConwayTxCert StandardConway]
915915
allPoolStakeCert' st = map (mkRegTxCert SNothing) (getCreds st)

cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Conway/Scenarios.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ forgeBlocksChunked interpreter vs f = forM (chunksOf 500 vs) $ \blockCreds -> do
9797
registerDRepsAndDelegateVotes :: Interpreter -> IO CardanoBlock
9898
registerDRepsAndDelegateVotes interpreter = do
9999
blockTxs <-
100-
withConwayLedgerState interpreter $
101-
registerDRepAndDelegateVotes'
100+
withConwayLedgerState interpreter
101+
$ registerDRepAndDelegateVotes'
102102
(Prelude.head unregisteredDRepIds)
103103
(StakeIndex 4)
104104

cardano-chain-gen/src/Cardano/Mock/Query.hs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ queryDRepDistrAmount drepHash epochNo = do
9898
(distr :& hash) <-
9999
from
100100
$ table @Db.DrepDistr
101-
`innerJoin` table @Db.DrepHash
102-
`on` (\(distr :& hash) -> (hash ^. Db.DrepHashId) ==. (distr ^. Db.DrepDistrHashId))
101+
`innerJoin` table @Db.DrepHash
102+
`on` (\(distr :& hash) -> (hash ^. Db.DrepHashId) ==. (distr ^. Db.DrepDistrHashId))
103103

104104
where_ $ hash ^. Db.DrepHashRaw ==. just (val drepHash)
105105
where_ $ distr ^. Db.DrepDistrEpochNo ==. val epochNo
@@ -140,14 +140,14 @@ queryConstitutionAnchor epochNo = do
140140
(_ :& anchor :& epochState) <-
141141
from
142142
$ table @Db.Constitution
143-
`innerJoin` table @Db.VotingAnchor
144-
`on` ( \(constit :& anchor) ->
145-
(constit ^. Db.ConstitutionVotingAnchorId) ==. (anchor ^. Db.VotingAnchorId)
146-
)
147-
`innerJoin` table @Db.EpochState
148-
`on` ( \(constit :& _ :& epoch) ->
149-
just (constit ^. Db.ConstitutionId) ==. (epoch ^. Db.EpochStateConstitutionId)
150-
)
143+
`innerJoin` table @Db.VotingAnchor
144+
`on` ( \(constit :& anchor) ->
145+
(constit ^. Db.ConstitutionVotingAnchorId) ==. (anchor ^. Db.VotingAnchorId)
146+
)
147+
`innerJoin` table @Db.EpochState
148+
`on` ( \(constit :& _ :& epoch) ->
149+
just (constit ^. Db.ConstitutionId) ==. (epoch ^. Db.EpochStateConstitutionId)
150+
)
151151

152152
where_ (epochState ^. Db.EpochStateEpochNo ==. val epochNo)
153153

@@ -193,11 +193,13 @@ queryVoteCounts txHash idx = do
193193
(vote :& tx) <-
194194
from
195195
$ table @Db.VotingProcedure
196-
`innerJoin` table @Db.Tx
197-
`on` (\(vote :& tx) -> vote ^. Db.VotingProcedureTxId ==. tx ^. Db.TxId)
198-
where_ $
199-
vote ^. Db.VotingProcedureVote ==. val v
200-
&&. tx ^. Db.TxHash ==. val txHash
201-
&&. vote ^. Db.VotingProcedureIndex ==. val idx
196+
`innerJoin` table @Db.Tx
197+
`on` (\(vote :& tx) -> vote ^. Db.VotingProcedureTxId ==. tx ^. Db.TxId)
198+
where_
199+
$ vote
200+
^. Db.VotingProcedureVote
201+
==. val v
202+
&&. tx ^. Db.TxHash ==. val txHash
203+
&&. vote ^. Db.VotingProcedureIndex ==. val idx
202204
pure countRows
203205
pure (maybe 0 unValue res)

cardano-chain-gen/test/Main.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import System.Directory (getCurrentDirectory)
77
import System.Environment (lookupEnv, setEnv)
88
import System.FilePath ((</>))
99
import qualified Test.Cardano.Db.Mock.Property.Property as Property
10+
import qualified Test.Cardano.Db.Mock.Unit.Alonzo as Alonzo
11+
import qualified Test.Cardano.Db.Mock.Unit.Babbage as Babbage
1012
import qualified Test.Cardano.Db.Mock.Unit.Conway as Conway
1113
import Test.Tasty
1214
import Test.Tasty.QuickCheck (testProperty)
@@ -27,7 +29,9 @@ tests iom = do
2729
pure $
2830
testGroup
2931
"cardano-chain-gen"
30-
[ Conway.unitTests iom knownMigrationsPlain
32+
[ Babbage.unitTests iom knownMigrationsPlain
33+
, Alonzo.unitTests iom knownMigrationsPlain
34+
, Conway.unitTests iom knownMigrationsPlain
3135
, testProperty "QSM" $ Property.prop_empty_blocks iom knownMigrationsPlain
3236
]
3337
where
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE OverloadedStrings #-}
3+
4+
module Test.Cardano.Db.Mock.Unit.Alonzo (
5+
unitTests,
6+
) where
7+
8+
import Cardano.Mock.ChainSync.Server (IOManager)
9+
import Data.Text (Text)
10+
import Test.Tasty (TestTree, testGroup)
11+
import Test.Tasty.HUnit (Assertion, testCase)
12+
13+
import qualified Test.Cardano.Db.Mock.Unit.Alonzo.Config as AlzConfig
14+
import qualified Test.Cardano.Db.Mock.Unit.Alonzo.Simple as AlzSimple
15+
import qualified Test.Cardano.Db.Mock.Unit.Alonzo.Tx as AlzTx
16+
17+
{- HLINT ignore "Reduce duplication" -}
18+
19+
unitTests :: IOManager -> [(Text, Text)] -> TestTree
20+
unitTests iom knownMigrations =
21+
testGroup
22+
"Alonzo unit tests"
23+
[ testGroup
24+
"config"
25+
[ testCase "default insert config" AlzConfig.defaultInsertConfig
26+
, testCase "insert config" AlzConfig.insertConfig
27+
]
28+
, testGroup
29+
"simple"
30+
[ test "simple forge blocks" AlzSimple.forgeBlocks
31+
, test "sync one block" AlzSimple.addSimple
32+
, test "restart db-sync" AlzSimple.restartDBSync
33+
, test "sync small chain" AlzSimple.addSimpleChain
34+
]
35+
, testGroup
36+
"blocks with txs"
37+
[ test "simple tx" AlzTx.addSimpleTx
38+
, test "consume utxo same block" AlzTx.consumeSameBlock
39+
]
40+
]
41+
where
42+
test :: String -> (IOManager -> [(Text, Text)] -> Assertion) -> TestTree
43+
test str action = testCase str (action iom knownMigrations)

0 commit comments

Comments
 (0)