Skip to content

Commit e4a0980

Browse files
authored
Merge pull request #1898 from sgillespie/test/gov-rollback
Test: Governance rollback tests
2 parents 662acc9 + 5fc5339 commit e4a0980

File tree

12 files changed

+406
-131
lines changed

12 files changed

+406
-131
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,13 @@ mkTxDelegCert ::
542542
mkTxDelegCert f = ConwayTxCertDeleg . f
543543

544544
mkAddCommitteeTx ::
545+
Maybe (Governance.GovPurposeId 'Governance.CommitteePurpose StandardConway) ->
545546
Credential 'ColdCommitteeRole StandardCrypto ->
546547
AlonzoTx StandardConway
547-
mkAddCommitteeTx cred = mkGovActionProposalTx govAction
548+
mkAddCommitteeTx prevGovAction cred = mkGovActionProposalTx govAction
548549
where
549-
govAction = Governance.UpdateCommittee SNothing mempty newMembers threshold
550+
govAction = Governance.UpdateCommittee prevGovAction' mempty newMembers threshold
551+
prevGovAction' = maybeToStrictMaybe prevGovAction
550552
newMembers = Map.singleton cred (EpochNo 20)
551553
threshold = fromJust $ boundRational (1 % 1)
552554

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module Cardano.Mock.Forging.Tx.Generic (
2525
registeredByronGenesisKeys,
2626
registeredShelleyGenesisKeys,
2727
bootstrapCommitteeCreds,
28+
unregisteredCommitteeCreds,
2829
unregisteredDRepIds,
2930
consPoolParams,
3031
getPoolStakeCreds,
@@ -292,6 +293,12 @@ bootstrapCommitteeCreds =
292293
)
293294
]
294295

296+
unregisteredCommitteeCreds :: [Credential 'ColdCommitteeRole StandardCrypto]
297+
unregisteredCommitteeCreds =
298+
[ KeyHashObj $ KeyHash "e0a714319812c3f773ba04ec5d6b3ffcd5aad85006805b047b082541"
299+
, KeyHashObj $ KeyHash "f15d3cfda3ac52c86d2d98925419795588e74f4e270a3c17beabeaff"
300+
]
301+
295302
unregisteredDRepIds :: [Credential 'DRepRole StandardCrypto]
296303
unregisteredDRepIds =
297304
[KeyHashObj $ KeyHash "0d94e174732ef9aae73f395ab44507bfa983d65023c11a951f0c32e4"]

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

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ module Cardano.Mock.Query (
1414
queryRewardRests,
1515
queryTreasuryDonations,
1616
queryVoteCounts,
17+
queryEpochStateCount,
18+
queryCommitteeByTxHash,
19+
queryCommitteeMemberCountByTxHash,
1720
) where
1821

1922
import qualified Cardano.Db as Db
20-
import Cardano.Prelude hiding (from, on)
23+
import Cardano.Prelude hiding (from, isNothing, on)
2124
import Database.Esqueleto.Experimental
2225
import Prelude ()
2326

@@ -201,3 +204,69 @@ queryVoteCounts txHash idx = do
201204
&&. vote ^. Db.VotingProcedureIndex ==. val idx
202205
pure countRows
203206
pure (maybe 0 unValue res)
207+
208+
queryEpochStateCount ::
209+
MonadIO io =>
210+
Word64 ->
211+
ReaderT SqlBackend io Word64
212+
queryEpochStateCount epochNo = do
213+
res <- selectOne $ do
214+
epochState <- from (table @Db.EpochState)
215+
where_ (epochState ^. Db.EpochStateEpochNo ==. val epochNo)
216+
pure countRows
217+
218+
pure (maybe 0 unValue res)
219+
220+
queryCommitteeByTxHash ::
221+
MonadIO io =>
222+
ByteString ->
223+
ReaderT SqlBackend io (Maybe Db.Committee)
224+
queryCommitteeByTxHash txHash = do
225+
res <- selectOne $ do
226+
(committee :& _ :& tx) <-
227+
from
228+
$ table @Db.Committee
229+
`innerJoin` table @Db.GovActionProposal
230+
`on` ( \(committee :& govAction) ->
231+
committee ^. Db.CommitteeGovActionProposalId ==. just (govAction ^. Db.GovActionProposalId)
232+
)
233+
`innerJoin` table @Db.Tx
234+
`on` ( \(_ :& govAction :& tx) ->
235+
govAction ^. Db.GovActionProposalTxId ==. tx ^. Db.TxId
236+
)
237+
where_ (tx ^. Db.TxHash ==. val txHash)
238+
pure committee
239+
240+
pure (entityVal <$> res)
241+
242+
queryCommitteeMemberCountByTxHash ::
243+
MonadIO io =>
244+
Maybe ByteString ->
245+
ReaderT SqlBackend io Word64
246+
queryCommitteeMemberCountByTxHash txHash = do
247+
res <- selectOne $ do
248+
(_ :& committee :& _ :& tx) <-
249+
from
250+
$ table @Db.CommitteeMember
251+
`innerJoin` table @Db.Committee
252+
`on` ( \(member :& committee) ->
253+
member ^. Db.CommitteeMemberCommitteeId ==. committee ^. Db.CommitteeId
254+
)
255+
`leftJoin` table @Db.GovActionProposal
256+
`on` ( \(_ :& committee :& govAction) ->
257+
committee ^. Db.CommitteeGovActionProposalId ==. govAction ?. Db.GovActionProposalId
258+
)
259+
`leftJoin` table @Db.Tx
260+
`on` ( \(_ :& _ :& govAction :& tx) ->
261+
govAction ?. Db.GovActionProposalTxId ==. tx ?. Db.TxId
262+
)
263+
264+
where_ $
265+
case txHash of
266+
-- Search by Tx hash, if specified
267+
Just _ -> tx ?. Db.TxHash ==. val txHash
268+
-- Otherwise, get the initial committee
269+
Nothing -> isNothing (committee ^. Db.CommitteeGovActionProposalId)
270+
pure countRows
271+
272+
pure (maybe 0 unValue res)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,14 @@ unitTests iom knownMigrations =
241241
"Governance"
242242
[ test "drep distribution" Governance.drepDistr
243243
, test "new committee member" Governance.newCommittee
244+
, test "chained committee proposals" Governance.chainedNewCommittee
245+
, test "rollback new committee member" Governance.rollbackNewCommittee
246+
, test "rollback new committee member proposal" Governance.rollbackNewCommitteeProposal
244247
, test "update constitution" Governance.updateConstitution
245248
, test "treasury withdrawal" Governance.treasuryWithdrawal
246249
, test "parameter change" Governance.parameterChange
247250
, test "hard fork" Governance.hardFork
251+
, test "rollback hardfork" Governance.rollbackHardFork
248252
, test "info action" Governance.infoAction
249253
]
250254
]

0 commit comments

Comments
 (0)