Skip to content

Commit 1b6a411

Browse files
committed
test: Add another new committee test
1 parent 39f2df6 commit 1b6a411

File tree

5 files changed

+98
-10
lines changed

5 files changed

+98
-10
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/Query.hs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ module Cardano.Mock.Query (
1616
queryVoteCounts,
1717
queryEpochStateCount,
1818
queryCommitteeByTxHash,
19+
queryCommitteeMemberCountByTxHash,
1920
) where
2021

2122
import qualified Cardano.Db as Db
22-
import Cardano.Prelude hiding (from, on)
23+
import Cardano.Prelude hiding (from, isNothing, on)
2324
import Database.Esqueleto.Experimental
2425
import Prelude ()
2526

@@ -237,3 +238,35 @@ queryCommitteeByTxHash txHash = do
237238
pure committee
238239

239240
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,15 @@ 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
248-
, test "info action" Governance.infoAction
249-
, test "rollback new committee member" Governance.rollbackNewCommittee
250-
, test "rollback new committee member proposal" Governance.rollbackNewCommitteeProposal
251251
, test "rollback hardfork" Governance.rollbackHardFork
252+
, test "info action" Governance.infoAction
252253
]
253254
]
254255
where

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

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
module Test.Cardano.Db.Mock.Unit.Conway.Governance (
1212
drepDistr,
1313
newCommittee,
14+
rollbackNewCommittee,
15+
rollbackNewCommitteeProposal,
1416
updateConstitution,
1517
treasuryWithdrawal,
1618
parameterChange,
19+
chainedNewCommittee,
1720
hardFork,
18-
infoAction,
19-
rollbackNewCommittee,
20-
rollbackNewCommitteeProposal,
2121
rollbackHardFork,
22+
infoAction,
2223
) where
2324

2425
import qualified Cardano.Db as Db
@@ -148,6 +149,56 @@ rollbackNewCommittee =
148149
where
149150
testLabel = "conwayRollbackNewCommittee"
150151

152+
chainedNewCommittee :: IOManager -> [(Text, Text)] -> Assertion
153+
chainedNewCommittee =
154+
withFullConfig conwayConfigDir testLabel $ \interpreter server dbSync -> do
155+
startDBSync dbSync
156+
157+
-- Register SPOs, DReps, and committee to vote
158+
epoch1 <- initGovernance interpreter server
159+
160+
-- Wait for it to sync
161+
assertBlockNoBackoff dbSync (length epoch1)
162+
-- Should start with 4 committee members
163+
assertEqQuery
164+
dbSync
165+
(Query.queryCommitteeMemberCountByTxHash Nothing)
166+
4
167+
"Unexpected committee member count"
168+
169+
let
170+
-- Propose a new committee member
171+
committee1Hash = "e0a714319812c3f773ba04ec5d6b3ffcd5aad85006805b047b082541"
172+
committee1Cred = KeyHashObj (KeyHash committee1Hash)
173+
proposal1 = Conway.mkAddCommitteeTx Nothing committee1Cred
174+
175+
-- Propose another, using proposal1 as the prev governance action
176+
committee2Hash = "f15d3cfda3ac52c86d2d98925419795588e74f4e270a3c17beabeaff"
177+
committee2Cred = KeyHashObj (KeyHash committee2Hash)
178+
proposal2 = Conway.mkAddCommitteeTx (Just prevGovActionId) committee2Cred
179+
proposal2TxHash = unTxHash (txIdTx proposal2)
180+
181+
prevGovActionId =
182+
Governance.GovPurposeId $
183+
Governance.GovActionId
184+
{ gaidTxId = txIdTx proposal1
185+
, gaidGovActionIx = GovActionIx 0
186+
}
187+
188+
void $ Api.withConwayFindLeaderAndSubmit interpreter server $ \_ ->
189+
Right [proposal1, proposal2]
190+
191+
-- Wait for it to sync
192+
assertBlockNoBackoff dbSync (length epoch1 + 1)
193+
-- Should now have 6 members
194+
assertEqQuery
195+
dbSync
196+
(Query.queryCommitteeMemberCountByTxHash $ Just proposal2TxHash)
197+
6
198+
"Unexpected committee member count"
199+
where
200+
testLabel = "conwayChainedNewCommittee"
201+
151202
rollbackNewCommitteeProposal :: IOManager -> [(Text, Text)] -> Assertion
152203
rollbackNewCommitteeProposal =
153204
withFullConfig conwayConfigDir testLabel $ \interpreter server dbSync -> do
@@ -215,7 +266,7 @@ enactNewCommittee interpreter server = do
215266

216267
proposeNewCommittee :: AlonzoTx Consensus.StandardConway
217268
proposeNewCommittee =
218-
Conway.mkAddCommitteeTx committeeCred
269+
Conway.mkAddCommitteeTx Nothing committeeCred
219270
where
220271
committeeHash = "e0a714319812c3f773ba04ec5d6b3ffcd5aad85006805b047b082541"
221272
committeeCred = KeyHashObj (KeyHash committeeHash)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[12,16,18,21,24,30,31,32,33,40,41,42,43,47,52,60,62,70,80,84,86,92,98,100,106,109,110,111,112,127,134,138,146,149,154,166,168,178,183,188,193,194,198,200,202,220,222,223,224,225,231,239,242,247,261,282,283,288,289,301,302,303,308,313,315,316,320,331,334,344,345,363,364,368,369,375,377,381,389,394,407,418,422,425,430,437,438,439,440,447,450,453,454,456,458,461,467,492,499,507,516,524]

0 commit comments

Comments
 (0)