Skip to content

Commit 68d4163

Browse files
committed
test: Add a Conway parameter change governance test
1 parent 3ce782e commit 68d4163

File tree

6 files changed

+98
-7
lines changed

6 files changed

+98
-7
lines changed

cardano-chain-gen/cardano-chain-gen.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ test-suite cardano-chain-gen
195195
, esqueleto
196196
, extra
197197
, filepath
198+
, microlens
198199
, silently
199200
, stm
200201
, strict-stm

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

+12
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module Cardano.Mock.Forging.Tx.Conway (
5050
mkRegDelegTxCert,
5151
mkAddCommitteeTx,
5252
mkTreasuryWithdrawalTx,
53+
mkParamChangeTx,
5354
mkGovActionProposalTx,
5455
mkGovVoteTx,
5556
Babbage.mkParamUpdateTx,
@@ -71,6 +72,7 @@ import Cardano.Ledger.Babbage.TxOut (BabbageEraTxOut, BabbageTxOut (..))
7172
import Cardano.Ledger.BaseTypes
7273
import Cardano.Ledger.Binary (Sized (..))
7374
import Cardano.Ledger.Coin (Coin (..))
75+
import Cardano.Ledger.Conway.Core (ppuGovActionDepositL)
7476
import qualified Cardano.Ledger.Conway.Governance as Governance
7577
import Cardano.Ledger.Conway.Scripts
7678
import Cardano.Ledger.Conway.Tx (AlonzoTx (..))
@@ -107,6 +109,7 @@ import qualified Data.OSet.Strict as OSet
107109
import Data.Sequence.Strict (StrictSeq ())
108110
import qualified Data.Sequence.Strict as StrictSeq
109111
import qualified Data.Set as Set
112+
import Lens.Micro ((.~), (^.))
110113
import Ouroboros.Consensus.Cardano.Block (EraCrypto, LedgerState ())
111114
import Ouroboros.Consensus.Shelley.Eras (StandardConway (), StandardCrypto ())
112115
import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock)
@@ -563,6 +566,15 @@ mkTreasuryWithdrawalTx rewardAccount amount = mkGovActionProposalTx govAction
563566
withdrawals = Map.singleton rewardAccount amount
564567
hashProtection = SNothing
565568

569+
mkParamChangeTx ::
570+
Core.PParamsUpdate StandardConway ->
571+
AlonzoTx StandardConway
572+
mkParamChangeTx paramsUpdate = mkGovActionProposalTx govAction
573+
where
574+
govAction = Governance.ParameterChange prevGovAction paramsUpdate hashProtection
575+
prevGovAction = SNothing
576+
hashProtection = SNothing
577+
566578
mkGovActionProposalTx ::
567579
Governance.GovAction StandardConway ->
568580
AlonzoTx StandardConway

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

+14-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{-# LANGUAGE TypeApplications #-}
33

44
module Cardano.Mock.Query (
5+
queryParamFromEpoch,
56
queryVersionMajorFromEpoch,
67
queryParamProposalFromEpoch,
78
queryNullTxDepositExists,
@@ -19,6 +20,18 @@ import Cardano.Prelude hiding (from, on)
1920
import Database.Esqueleto.Experimental
2021
import Prelude ()
2122

23+
queryParamFromEpoch ::
24+
(MonadIO io, PersistField field) =>
25+
EntityField Db.EpochParam field ->
26+
Word64 ->
27+
ReaderT SqlBackend io (Maybe field)
28+
queryParamFromEpoch field epochNo = do
29+
res <- selectOne $ do
30+
prop <- from $ table @Db.EpochParam
31+
where_ (prop ^. Db.EpochParamEpochNo ==. val epochNo)
32+
pure (prop ^. field)
33+
pure $ unValue <$> res
34+
2235
-- | Query protocol parameters from @EpochParam@ by epoch number. Note that epoch
2336
-- parameters are inserted at the beginning of the next epoch.
2437
--
@@ -32,12 +45,7 @@ queryVersionMajorFromEpoch ::
3245
MonadIO io =>
3346
Word64 ->
3447
ReaderT SqlBackend io (Maybe Word16)
35-
queryVersionMajorFromEpoch epochNo = do
36-
res <- selectOne $ do
37-
prop <- from $ table @Db.EpochParam
38-
where_ (prop ^. Db.EpochParamEpochNo ==. val epochNo)
39-
pure (prop ^. Db.EpochParamProtocolMajor)
40-
pure $ unValue <$> res
48+
queryVersionMajorFromEpoch = queryParamFromEpoch Db.EpochParamProtocolMajor
4149

4250
-- | Query protocol parameter proposals from @ParamProposal@ by epoch number.
4351
queryParamProposalFromEpoch ::

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

+1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ unitTests iom knownMigrations =
221221
, test "new committee member" Governance.newCommittee
222222
, test "update constitution" Governance.updateConstitution
223223
, test "treasury withdrawal" Governance.treasuryWithdrawal
224+
, test "protocol parameter change" Governance.paramChange
224225
]
225226
]
226227
where

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

+69-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
module Test.Cardano.Db.Mock.Unit.Conway.Governance (
1212
drepDistr,
1313
newCommittee,
14+
paramChange,
1415
updateConstitution,
1516
treasuryWithdrawal,
1617
) where
@@ -22,7 +23,8 @@ import Cardano.Ledger.BaseTypes (AnchorData (..), Network (..), hashAnchorData,
2223
import Cardano.Ledger.Coin (Coin (..))
2324
import Cardano.Ledger.Conway.Governance (GovActionId (..), GovActionIx (..), Voter (..))
2425
import qualified Cardano.Ledger.Conway.Governance as Governance
25-
import Cardano.Ledger.Core (txIdTx)
26+
import Cardano.Ledger.Conway.PParams (ppuGovActionDepositL)
27+
import Cardano.Ledger.Core (emptyPParamsUpdate, txIdTx)
2628
import Cardano.Ledger.Credential (Credential (..))
2729
import Cardano.Ledger.Keys (KeyHash (..))
2830
import Cardano.Ledger.SafeHash (SafeToHash (..))
@@ -35,6 +37,8 @@ import qualified Cardano.Mock.Query as Query
3537
import Cardano.Prelude
3638
import Cardano.Slotting.Slot (EpochNo (..))
3739
import Data.Maybe (fromJust)
40+
import Data.Maybe.Strict (StrictMaybe (..))
41+
import Lens.Micro
3842
import qualified Ouroboros.Consensus.Shelley.Eras as Consensus
3943
import Test.Cardano.Db.Mock.Config
4044
import qualified Test.Cardano.Db.Mock.UnifiedApi as Api
@@ -252,3 +256,67 @@ treasuryWithdrawal =
252256
"Unexpected constution voting anchor"
253257
where
254258
testLabel = "conwayTreasuryWithdrawal"
259+
260+
paramChange :: IOManager -> [(Text, Text)] -> Assertion
261+
paramChange =
262+
withFullConfig conwayConfigDir testLabel $ \interpreter server dbSync -> do
263+
startDBSync dbSync
264+
265+
-- Add stake
266+
void (Api.registerAllStakeCreds interpreter server)
267+
268+
-- Register a DRep and delegate votes to it
269+
void (Api.registerDRepsAndDelegateVotes interpreter server)
270+
271+
-- DRep distribution is calculated at end of the current epoch
272+
epoch0 <- Api.fillUntilNextEpoch interpreter server
273+
274+
-- Register committee hot credentials
275+
-- TODO[sgillespie]: Let's get this in UnifiedApi or something
276+
void $
277+
Api.withConwayFindLeaderAndSubmit interpreter server $ \_ ->
278+
mapM (uncurry Conway.mkCommitteeAuthTx) Forging.bootstrapCommitteeCreds
279+
280+
-- Create and vote for a governance proposal
281+
void $
282+
Api.withConwayFindLeaderAndSubmit interpreter server $ \ledger -> do
283+
let proposalTx = Conway.mkParamChangeTx newParams
284+
newParams =
285+
emptyPParamsUpdate & ppuGovActionDepositL .~ SJust (Coin 100)
286+
287+
addVoteTx =
288+
Conway.mkGovVoteTx
289+
govActionId
290+
( [ DRepVoter (Prelude.head Forging.unregisteredDRepIds)
291+
, StakePoolVoter (Forging.resolvePool (PoolIndex 0) ledger)
292+
, StakePoolVoter (Forging.resolvePool (PoolIndex 1) ledger)
293+
, StakePoolVoter (Forging.resolvePool (PoolIndex 2) ledger)
294+
]
295+
++ map (CommitteeVoter . snd) Forging.bootstrapCommitteeCreds
296+
)
297+
298+
govActionId =
299+
GovActionId
300+
{ gaidTxId = txIdTx proposalTx
301+
, gaidGovActionIx = GovActionIx 0
302+
}
303+
304+
pure [proposalTx, addVoteTx]
305+
306+
-- It takes 2 epochs to enact a proposal--ratification will happen on the next
307+
-- epoch and enacted on the following.
308+
epoch1 <- Api.fillEpochs interpreter server 2
309+
310+
-- Wait for it to synch
311+
assertBlockNoBackoff dbSync (length (epoch0 <> epoch1) + 4)
312+
313+
epochNo <- unEpochNo <$> getCurrentEpoch interpreter
314+
315+
-- Should have updated epoch param
316+
assertEqQuery
317+
dbSync
318+
(join <$> Query.queryParamFromEpoch Db.EpochParamGovActionDeposit epochNo)
319+
(Just $ Db.DbWord64 100)
320+
"Unexpected constution voting anchor"
321+
where
322+
testLabel = "conwayParamChange"
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,538,541,544,546,550,567,573,576,577,579,580,586,589,595,597,603,605,609,616,618,619,623,624,634,636,643,644,659,664,665,672,678,692,705,711,712,719,726,730,739,740,743,747,749,751,754,759,762,763,765,767,773,777,786,788,789,794,801,806,807,829,830,832,849,851,853,869,871,874,875,878,882,888,893,895,896,898,899,903,906,908,911,912,913,922,930,932,938,941,944,950,960,963,966,968,972,977,985,986,988,990,991,994,997,1001,1005,1008,1014,1019,1020,1021,1026,1027,1031,1032,1033,1036,1037,1049,1050,1053,1057,1062,1067,1068,1070,1074,1083,1102,1104,1107,1111,1115,1117,1118,1120,1125,1127,1137,1149,1151,1155,1161,1164,1167,1174,1187,1200,1201,1206,1213,1218,1221,1237,1242,1248,1258,1263,1266,1272,1277,1286,1299,1300,1304,1309,1313,1317,1336,1338,1343,1356,1363,1366,1376,1377,1379,1390,1397,1401,1408,1409,1410,1418,1423,1424,1429,1432,1435,1438,1439,1442,1444,1449,1453,1454,1461,1462,1470,1473,1474,1481,1484,1486,1503]

0 commit comments

Comments
 (0)