Skip to content

Commit

Permalink
Merge pull request #1898 from sgillespie/test/gov-rollback
Browse files Browse the repository at this point in the history
Test: Governance rollback tests
  • Loading branch information
kderme authored Jan 21, 2025
2 parents 662acc9 + 5fc5339 commit e4a0980
Show file tree
Hide file tree
Showing 12 changed files with 406 additions and 131 deletions.
6 changes: 4 additions & 2 deletions cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Conway.hs
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,13 @@ mkTxDelegCert ::
mkTxDelegCert f = ConwayTxCertDeleg . f

mkAddCommitteeTx ::
Maybe (Governance.GovPurposeId 'Governance.CommitteePurpose StandardConway) ->
Credential 'ColdCommitteeRole StandardCrypto ->
AlonzoTx StandardConway
mkAddCommitteeTx cred = mkGovActionProposalTx govAction
mkAddCommitteeTx prevGovAction cred = mkGovActionProposalTx govAction
where
govAction = Governance.UpdateCommittee SNothing mempty newMembers threshold
govAction = Governance.UpdateCommittee prevGovAction' mempty newMembers threshold
prevGovAction' = maybeToStrictMaybe prevGovAction
newMembers = Map.singleton cred (EpochNo 20)
threshold = fromJust $ boundRational (1 % 1)

Expand Down
7 changes: 7 additions & 0 deletions cardano-chain-gen/src/Cardano/Mock/Forging/Tx/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Cardano.Mock.Forging.Tx.Generic (
registeredByronGenesisKeys,
registeredShelleyGenesisKeys,
bootstrapCommitteeCreds,
unregisteredCommitteeCreds,
unregisteredDRepIds,
consPoolParams,
getPoolStakeCreds,
Expand Down Expand Up @@ -292,6 +293,12 @@ bootstrapCommitteeCreds =
)
]

unregisteredCommitteeCreds :: [Credential 'ColdCommitteeRole StandardCrypto]
unregisteredCommitteeCreds =
[ KeyHashObj $ KeyHash "e0a714319812c3f773ba04ec5d6b3ffcd5aad85006805b047b082541"
, KeyHashObj $ KeyHash "f15d3cfda3ac52c86d2d98925419795588e74f4e270a3c17beabeaff"
]

unregisteredDRepIds :: [Credential 'DRepRole StandardCrypto]
unregisteredDRepIds =
[KeyHashObj $ KeyHash "0d94e174732ef9aae73f395ab44507bfa983d65023c11a951f0c32e4"]
Expand Down
71 changes: 70 additions & 1 deletion cardano-chain-gen/src/Cardano/Mock/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ module Cardano.Mock.Query (
queryRewardRests,
queryTreasuryDonations,
queryVoteCounts,
queryEpochStateCount,
queryCommitteeByTxHash,
queryCommitteeMemberCountByTxHash,
) where

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

Expand Down Expand Up @@ -201,3 +204,69 @@ queryVoteCounts txHash idx = do
&&. vote ^. Db.VotingProcedureIndex ==. val idx
pure countRows
pure (maybe 0 unValue res)

queryEpochStateCount ::
MonadIO io =>
Word64 ->
ReaderT SqlBackend io Word64
queryEpochStateCount epochNo = do
res <- selectOne $ do
epochState <- from (table @Db.EpochState)
where_ (epochState ^. Db.EpochStateEpochNo ==. val epochNo)
pure countRows

pure (maybe 0 unValue res)

queryCommitteeByTxHash ::
MonadIO io =>
ByteString ->
ReaderT SqlBackend io (Maybe Db.Committee)
queryCommitteeByTxHash txHash = do
res <- selectOne $ do
(committee :& _ :& tx) <-
from
$ table @Db.Committee
`innerJoin` table @Db.GovActionProposal
`on` ( \(committee :& govAction) ->
committee ^. Db.CommitteeGovActionProposalId ==. just (govAction ^. Db.GovActionProposalId)
)
`innerJoin` table @Db.Tx
`on` ( \(_ :& govAction :& tx) ->
govAction ^. Db.GovActionProposalTxId ==. tx ^. Db.TxId
)
where_ (tx ^. Db.TxHash ==. val txHash)
pure committee

pure (entityVal <$> res)

queryCommitteeMemberCountByTxHash ::
MonadIO io =>
Maybe ByteString ->
ReaderT SqlBackend io Word64
queryCommitteeMemberCountByTxHash txHash = do
res <- selectOne $ do
(_ :& committee :& _ :& tx) <-
from
$ table @Db.CommitteeMember
`innerJoin` table @Db.Committee
`on` ( \(member :& committee) ->
member ^. Db.CommitteeMemberCommitteeId ==. committee ^. Db.CommitteeId
)
`leftJoin` table @Db.GovActionProposal
`on` ( \(_ :& committee :& govAction) ->
committee ^. Db.CommitteeGovActionProposalId ==. govAction ?. Db.GovActionProposalId
)
`leftJoin` table @Db.Tx
`on` ( \(_ :& _ :& govAction :& tx) ->
govAction ?. Db.GovActionProposalTxId ==. tx ?. Db.TxId
)

where_ $
case txHash of
-- Search by Tx hash, if specified
Just _ -> tx ?. Db.TxHash ==. val txHash
-- Otherwise, get the initial committee
Nothing -> isNothing (committee ^. Db.CommitteeGovActionProposalId)
pure countRows

pure (maybe 0 unValue res)
4 changes: 4 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 @@ -241,10 +241,14 @@ unitTests iom knownMigrations =
"Governance"
[ test "drep distribution" Governance.drepDistr
, test "new committee member" Governance.newCommittee
, test "chained committee proposals" Governance.chainedNewCommittee
, test "rollback new committee member" Governance.rollbackNewCommittee
, test "rollback new committee member proposal" Governance.rollbackNewCommitteeProposal
, test "update constitution" Governance.updateConstitution
, test "treasury withdrawal" Governance.treasuryWithdrawal
, test "parameter change" Governance.parameterChange
, test "hard fork" Governance.hardFork
, test "rollback hardfork" Governance.rollbackHardFork
, test "info action" Governance.infoAction
]
]
Expand Down
Loading

0 comments on commit e4a0980

Please sign in to comment.