Skip to content

Commit 1d8a84a

Browse files
committed
test: Add a rollback new committee proposal
1 parent b7e2f4e commit 1d8a84a

File tree

5 files changed

+80
-6
lines changed

5 files changed

+80
-6
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Cardano.Mock.Query (
1515
queryTreasuryDonations,
1616
queryVoteCounts,
1717
queryEpochStateCount,
18+
queryCommitteeByTxHash,
1819
) where
1920

2021
import qualified Cardano.Db as Db
@@ -214,3 +215,25 @@ queryEpochStateCount epochNo = do
214215
pure countRows
215216

216217
pure (maybe 0 unValue res)
218+
219+
queryCommitteeByTxHash ::
220+
MonadIO io =>
221+
ByteString ->
222+
ReaderT SqlBackend io (Maybe Db.Committee)
223+
queryCommitteeByTxHash txHash = do
224+
res <- selectOne $ do
225+
(committee :& _ :& tx) <-
226+
from
227+
$ table @Db.Committee
228+
`innerJoin` table @Db.GovActionProposal
229+
`on` ( \(committee :& govAction) ->
230+
committee ^. Db.CommitteeGovActionProposalId ==. just (govAction ^. Db.GovActionProposalId)
231+
)
232+
`innerJoin` table @Db.Tx
233+
`on` ( \(_ :& govAction :& tx) ->
234+
govAction ^. Db.GovActionProposalTxId ==. tx ^. Db.TxId
235+
)
236+
where_ (tx ^. Db.TxHash ==. val txHash)
237+
pure committee
238+
239+
pure (entityVal <$> res)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ unitTests iom knownMigrations =
247247
, test "hard fork" Governance.hardFork
248248
, test "info action" Governance.infoAction
249249
, test "rollback new committee member" Governance.rollbackNewCommittee
250+
, test "rollback new committee member proposal" Governance.rollbackNewCommitteeProposal
250251
]
251252
]
252253
where

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

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ module Test.Cardano.Db.Mock.Unit.Conway.Governance (
1717
hardFork,
1818
infoAction,
1919
rollbackNewCommittee,
20+
rollbackNewCommitteeProposal,
2021
) where
2122

2223
import qualified Cardano.Db as Db
2324
import Cardano.DbSync.Era.Shelley.Generic.Util (unCredentialHash, unTxHash)
2425
import Cardano.Ledger.Address (RewardAccount (..))
26+
import Cardano.Ledger.Alonzo.Tx (AlonzoTx)
2527
import Cardano.Ledger.BaseTypes (AnchorData (..), Network (..), hashAnchorData, textToUrl)
2628
import Cardano.Ledger.Coin (Coin (..))
2729
import Cardano.Ledger.Conway.Governance (GovActionId (..), GovActionIx (..))
@@ -142,17 +144,56 @@ rollbackNewCommittee =
142144
where
143145
testLabel = "conwayRollbackNewCommittee"
144146

147+
rollbackNewCommitteeProposal :: IOManager -> [(Text, Text)] -> Assertion
148+
rollbackNewCommitteeProposal =
149+
withFullConfig conwayConfigDir testLabel $ \interpreter server dbSync -> do
150+
startDBSync dbSync
151+
152+
blks <-
153+
sequence
154+
[ -- Add stake
155+
Api.registerAllStakeCreds interpreter server
156+
, -- Register a DRep and delegate votes to it
157+
Api.registerDRepsAndDelegateVotes interpreter server
158+
]
159+
160+
-- Propose a new committee member
161+
let proposal = proposeNewCommittee
162+
proposalTxHash = unTxHash (txIdTx proposal)
163+
void $ Api.withConwayFindLeaderAndSubmit interpreter server $ \_ ->
164+
Right [proposal]
165+
166+
-- Wait for it to sync
167+
assertBlockNoBackoff dbSync (length blks + 1)
168+
-- Should have a new committee
169+
assertBackoff
170+
dbSync
171+
(Query.queryCommitteeByTxHash proposalTxHash)
172+
defaultDelays
173+
isJust
174+
(const "Expected at least one new committee")
175+
176+
-- Rollback one block
177+
blks' <- rollbackBlocks interpreter server 1 blks
178+
-- Wait for it to sync
179+
assertBlockNoBackoff dbSync (length blks' + 1)
180+
-- Should NOT have a new committee
181+
assertBackoff
182+
dbSync
183+
(Query.queryCommitteeByTxHash proposalTxHash)
184+
defaultDelays
185+
isNothing
186+
(const "Unexpected new committee")
187+
where
188+
testLabel = "conwayRollbackNewCommitteeProposal"
189+
145190
enactNewCommittee :: Interpreter -> ServerHandle IO CardanoBlock -> IO [CardanoBlock]
146191
enactNewCommittee interpreter server = do
147-
-- Create and vote for gov action
148-
let committeeHash = "e0a714319812c3f773ba04ec5d6b3ffcd5aad85006805b047b082541"
149-
committeeCred = KeyHashObj (KeyHash committeeHash)
150-
151192
blk <-
152193
Api.withConwayFindLeaderAndSubmit interpreter server $ \ledger -> do
153194
let
154195
-- Create gov action tx
155-
addCcTx = Conway.mkAddCommitteeTx committeeCred
196+
addCcTx = proposeNewCommittee
156197
-- Create votes for all stake pools. We start in the Conway bootstrap phase, so
157198
-- DRep votes are not yet required.
158199
addVoteTx =
@@ -173,6 +214,13 @@ enactNewCommittee interpreter server = do
173214
epochs <- Api.fillEpochs interpreter server 2
174215
pure (blk : epochs)
175216

217+
proposeNewCommittee :: AlonzoTx Consensus.StandardConway
218+
proposeNewCommittee =
219+
Conway.mkAddCommitteeTx committeeCred
220+
where
221+
committeeHash = "e0a714319812c3f773ba04ec5d6b3ffcd5aad85006805b047b082541"
222+
committeeCred = KeyHashObj (KeyHash committeeHash)
223+
176224
rollbackBlocks ::
177225
Interpreter ->
178226
ServerHandle IO CardanoBlock ->
@@ -183,7 +231,7 @@ rollbackBlocks interpreter server n blocks = do
183231
(rollbackPoint, blocks') <-
184232
case drop n (reverse blocks) of
185233
(blk : blks) -> pure (blockPoint blk, blks)
186-
[] -> assertFailure "Expected at least 3 blocks"
234+
[] -> assertFailure $ "Expected at least " <> show n <> " blocks"
187235

188236
-- Rollback to the previous epoch
189237
Api.rollbackTo interpreter server rollbackPoint

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module Test.Cardano.Db.Mock.Validate (
4040
assertPoolCounters,
4141
poolCountersQuery,
4242
checkStillRuns,
43+
defaultDelays,
4344
) where
4445

4546
import Cardano.Db
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[12,16,18,16]

0 commit comments

Comments
 (0)