@@ -17,11 +17,13 @@ module Test.Cardano.Db.Mock.Unit.Conway.Governance (
17
17
hardFork ,
18
18
infoAction ,
19
19
rollbackNewCommittee ,
20
+ rollbackNewCommitteeProposal ,
20
21
) where
21
22
22
23
import qualified Cardano.Db as Db
23
24
import Cardano.DbSync.Era.Shelley.Generic.Util (unCredentialHash , unTxHash )
24
25
import Cardano.Ledger.Address (RewardAccount (.. ))
26
+ import Cardano.Ledger.Alonzo.Tx (AlonzoTx )
25
27
import Cardano.Ledger.BaseTypes (AnchorData (.. ), Network (.. ), hashAnchorData , textToUrl )
26
28
import Cardano.Ledger.Coin (Coin (.. ))
27
29
import Cardano.Ledger.Conway.Governance (GovActionId (.. ), GovActionIx (.. ))
@@ -142,17 +144,56 @@ rollbackNewCommittee =
142
144
where
143
145
testLabel = " conwayRollbackNewCommittee"
144
146
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
+
145
190
enactNewCommittee :: Interpreter -> ServerHandle IO CardanoBlock -> IO [CardanoBlock ]
146
191
enactNewCommittee interpreter server = do
147
- -- Create and vote for gov action
148
- let committeeHash = " e0a714319812c3f773ba04ec5d6b3ffcd5aad85006805b047b082541"
149
- committeeCred = KeyHashObj (KeyHash committeeHash)
150
-
151
192
blk <-
152
193
Api. withConwayFindLeaderAndSubmit interpreter server $ \ ledger -> do
153
194
let
154
195
-- Create gov action tx
155
- addCcTx = Conway. mkAddCommitteeTx committeeCred
196
+ addCcTx = proposeNewCommittee
156
197
-- Create votes for all stake pools. We start in the Conway bootstrap phase, so
157
198
-- DRep votes are not yet required.
158
199
addVoteTx =
@@ -173,6 +214,13 @@ enactNewCommittee interpreter server = do
173
214
epochs <- Api. fillEpochs interpreter server 2
174
215
pure (blk : epochs)
175
216
217
+ proposeNewCommittee :: AlonzoTx Consensus. StandardConway
218
+ proposeNewCommittee =
219
+ Conway. mkAddCommitteeTx committeeCred
220
+ where
221
+ committeeHash = " e0a714319812c3f773ba04ec5d6b3ffcd5aad85006805b047b082541"
222
+ committeeCred = KeyHashObj (KeyHash committeeHash)
223
+
176
224
rollbackBlocks ::
177
225
Interpreter ->
178
226
ServerHandle IO CardanoBlock ->
@@ -183,7 +231,7 @@ rollbackBlocks interpreter server n blocks = do
183
231
(rollbackPoint, blocks') <-
184
232
case drop n (reverse blocks) of
185
233
(blk : blks) -> pure (blockPoint blk, blks)
186
- [] -> assertFailure " Expected at least 3 blocks"
234
+ [] -> assertFailure $ " Expected at least " <> show n <> " blocks"
187
235
188
236
-- Rollback to the previous epoch
189
237
Api. rollbackTo interpreter server rollbackPoint
0 commit comments