Skip to content

Commit

Permalink
test(cardano-chain-gen): Add a DRep registration test
Browse files Browse the repository at this point in the history
  • Loading branch information
sgillespie committed May 7, 2024
1 parent fbe13d0 commit 61bc1f0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions cardano-chain-gen/cardano-chain-gen.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ test-suite cardano-chain-gen
Test.Cardano.Db.Mock.Unit.Conway.CommandLineArg.ForceIndex
Test.Cardano.Db.Mock.Unit.Conway.Config.Parse
Test.Cardano.Db.Mock.Unit.Conway.Config.MigrateConsumedPruneTxOut
Test.Cardano.Db.Mock.Unit.Conway.Governance
Test.Cardano.Db.Mock.Unit.Conway.InlineAndReference
Test.Cardano.Db.Mock.Unit.Conway.Other
Test.Cardano.Db.Mock.Unit.Conway.Plutus
Expand Down
10 changes: 10 additions & 0 deletions cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Conway.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
Expand Down Expand Up @@ -31,6 +32,7 @@ module Cardano.Mock.Forging.Tx.Conway (
mkDepositTxPools,
mkDummyRegisterTx,
mkDummyTxBody,
mkRegDRepTx,
mkTxDelegCert,
mkRegTxCert,
mkUnRegTxCert,
Expand Down Expand Up @@ -447,6 +449,14 @@ mkDummyRegisterTx n m = mkDCertTx consDelegCert (Withdrawals mempty) Nothing
. fromIntegral
<$> [n, m]

mkRegDRepTx ::
Credential 'DRepRole StandardCrypto ->
Either ForgingError (AlonzoTx StandardConway)
mkRegDRepTx credential = mkDCertTx [mkCert] (Withdrawals mempty) Nothing
where
mkCert = ConwayTxCertGov (ConwayRegDRep credential deposit SNothing)
deposit = Coin 500_000_000

mkRegTxCert ::
StrictMaybe Coin ->
StakeCredential StandardCrypto ->
Expand Down
16 changes: 15 additions & 1 deletion cardano-chain-gen/src/Cardano/Mock/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ module Cardano.Mock.Query (
queryNullTxDepositExists,
queryMultiAssetCount,
queryTxMetadataCount,
queryDRepRegistrationHashes,
) where

import qualified Cardano.Db as Db
import Cardano.Prelude hiding (from)
import Cardano.Prelude hiding (from, on)
import Database.Esqueleto.Experimental
import Prelude ()

Expand Down Expand Up @@ -68,3 +69,16 @@ queryTxMetadataCount = do
pure countRows

pure $ maybe 0 unValue res

queryDRepRegistrationHashes :: MonadIO io => ReaderT SqlBackend io [ByteString]
queryDRepRegistrationHashes = do
res <- select $ do
(hash :& _) <-
from
( table @Db.DrepHash
`innerJoin` table @Db.DrepRegistration
`on` \(hash :& reg) -> reg ^. Db.DrepRegistrationDrepHashId ==. hash ^. Db.DrepHashId
)
pure (hash ^. Db.DrepHashRaw)

pure $ mapMaybe unValue res
5 changes: 5 additions & 0 deletions cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Conway.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import qualified Test.Cardano.Db.Mock.Unit.Conway.CommandLineArg.EpochDisabled a
import qualified Test.Cardano.Db.Mock.Unit.Conway.CommandLineArg.ForceIndex as ForceIndex
import qualified Test.Cardano.Db.Mock.Unit.Conway.Config.MigrateConsumedPruneTxOut as MigrateConsumedPruneTxOut
import qualified Test.Cardano.Db.Mock.Unit.Conway.Config.Parse as Config
import qualified Test.Cardano.Db.Mock.Unit.Conway.Governance as Governance
import qualified Test.Cardano.Db.Mock.Unit.Conway.InlineAndReference as InlineRef
import qualified Test.Cardano.Db.Mock.Unit.Conway.Other as Other
import qualified Test.Cardano.Db.Mock.Unit.Conway.Plutus as Plutus
Expand Down Expand Up @@ -214,6 +215,10 @@ unitTests iom knownMigrations =
, test "fork from Babbage to Conway and rollback" Other.rollbackFork
, test "fork with protocol change proposal" Other.forkParam
]
, testGroup
"Governance"
[ test "drep registration" Governance.drepRegistration
]
]
where
test :: String -> (IOManager -> [(Text, Text)] -> Assertion) -> TestTree
Expand Down

0 comments on commit 61bc1f0

Please sign in to comment.