Skip to content

Commit 48335ee

Browse files
committed
Initialize ImpTest state with current guardrail constitution
and adjust tests
1 parent c9ef3e9 commit 48335ee

File tree

9 files changed

+90
-79
lines changed

9 files changed

+90
-79
lines changed

eras/conway/impl/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
### `testlib`
1010

11+
* Add `minFeeUpdateGovAction`
1112
* Add `mkTreasuryWithdrawalsGovAction` and `mkParameterChangeGovAction`
1213
* Switch to using `ImpSpec` package
1314
* Remove `withImpStateWithProtVer`

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/EnactSpec.hs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,16 @@ actionPrioritySpec =
460460
nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . committeeGovStateL
461461
committee `shouldBe` SNothing
462462

463-
let val1 = Coin 1_000_001
464-
let val2 = Coin 1_000_002
465-
let val3 = Coin 1_000_003
466-
463+
-- distinct constitutional values for minFee
464+
let genMinFeeVals =
465+
(\x y z -> (Coin x, Coin y, Coin z))
466+
<$> uniformRM (30, 330)
467+
<*> uniformRM (330, 660)
468+
<*> uniformRM (660, 1000)
467469
it "proposals of same priority are enacted in order of submission" $ do
468470
modifyPParams $ ppPoolVotingThresholdsL . pvtPPSecurityGroupL .~ 1 %! 1
469471
whenPostBootstrap (modifyPParams $ ppDRepVotingThresholdsL . dvtPPEconomicGroupL .~ def)
472+
(val1, val2, val3) <- genMinFeeVals
470473

471474
committeeCs <- registerInitialCommittee
472475
(spoC, _, _) <- setupPoolWithStake $ Coin 42_000_000
@@ -498,6 +501,7 @@ actionPrioritySpec =
498501
it "only the first action of a transaction gets enacted" $ do
499502
modifyPParams $ ppPoolVotingThresholdsL . pvtPPSecurityGroupL .~ 1 %! 1
500503
whenPostBootstrap (modifyPParams $ ppDRepVotingThresholdsL . dvtPPEconomicGroupL .~ def)
504+
(val1, val2, val3) <- genMinFeeVals
501505

502506
committeeCs <- registerInitialCommittee
503507
(spoC, _, _) <- setupPoolWithStake $ Coin 42_000_000

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/EpochSpec.hs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,10 @@ proposalsSpec =
9191

9292
initialValue <- getsNES (nesEsL . curPParamsEpochStateL . ppMinFeeAL)
9393

94-
policy <-
95-
getsNES $
96-
nesEpochStateL . epochStateGovStateL . constitutionGovStateL . constitutionScriptL
94+
parameterChangeAction <- mkMinFeeUpdateGovAction SNothing
9795
govActionId <-
9896
mkProposalWithRewardAccount
99-
(ParameterChange SNothing (def & ppuMinFeeAL .~ SJust (Coin 3000)) policy)
97+
parameterChangeAction
10098
rewardAccount
10199
>>= submitProposal
102100
expectPresentGovActionId govActionId
@@ -138,15 +136,15 @@ proposalsSpec =
138136
let ratifyState = extractDRepPulsingState (govStateFinal ^. cgsDRepPulsingStateL)
139137
rsExpired ratifyState `shouldBe` Set.singleton govActionId
140138
where
141-
submitParameterChangeTree = submitGovActionTree $ paramAction >=> submitGovAction
142-
paramAction p = mkParameterChangeGovAction p (def & ppuMinFeeAL .~ SJust (Coin 10))
139+
submitParameterChangeTree = submitGovActionTree $ mkMinFeeUpdateGovAction >=> submitGovAction
143140

144141
dRepSpec ::
145142
forall era.
146143
ConwayEraImp era =>
147144
SpecWith (ImpInit (LedgerSpec era))
148145
dRepSpec =
149146
describe "DRep" $ do
147+
let submitParamChangeProposal = mkMinFeeUpdateGovAction SNothing >>= submitGovAction_
150148
it "expiry is updated based on the number of dormant epochs" $ do
151149
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 2
152150
(drep, _, _) <- setupSingleDRep 1_000_000
@@ -155,12 +153,10 @@ dRepSpec =
155153
let
156154
-- compute the epoch number that is an offset from starting epoch number
157155
offDRepActivity = addEpochInterval startEpochNo . EpochInterval
158-
submitParamChangeProposal =
159-
submitParameterChange SNothing $ def & ppuMinFeeAL .~ SJust (Coin 3000)
160156
expectNumDormantEpochs 0
161157

162158
-- epoch 0: we submit a proposal
163-
_ <- submitParamChangeProposal
159+
submitParamChangeProposal
164160
passNEpochsChecking 2 $ do
165161
expectNumDormantEpochs 0
166162
expectDRepExpiry drep $ offDRepActivity 100
@@ -178,7 +174,7 @@ dRepSpec =
178174
expectNumDormantEpochs 3
179175
expectDRepExpiry drep $ offDRepActivity 100
180176

181-
_ <- submitParamChangeProposal
177+
submitParamChangeProposal
182178
-- number of dormant epochs is added to the drep expiry and reset to 0
183179
expectNumDormantEpochs 0
184180
expectDRepExpiry drep $ offDRepActivity 103
@@ -201,12 +197,10 @@ dRepSpec =
201197
offDRepActivity offset =
202198
addEpochInterval startEpochNo $ EpochInterval (drepActivity + offset)
203199

204-
let submitParamChangeProposal =
205-
submitParameterChange SNothing $ def & ppuMinFeeAL .~ SJust (Coin 3000)
206200
expectNumDormantEpochs 0
207201

208202
-- epoch 0: we submit a proposal
209-
_ <- submitParamChangeProposal
203+
submitParamChangeProposal
210204
passNEpochsChecking 2 $ do
211205
expectNumDormantEpochs 0
212206
expectDRepExpiry drep $ offDRepActivity 0
@@ -228,7 +222,7 @@ dRepSpec =
228222
expectDRepExpiry drep $ offDRepActivity 0
229223
expectActualDRepExpiry drep $ offDRepActivity 3
230224

231-
_ <- submitParamChangeProposal
225+
submitParamChangeProposal
232226
-- number of dormant epochs is added to the drep, considering they are not actually expired,
233227
-- and is reset to 0
234228
expectNumDormantEpochs 0
@@ -462,7 +456,11 @@ depositMovesToTreasuryWhenStakingAddressUnregisters = do
462456
govPolicy <- getGovPolicy
463457
gaid <-
464458
mkProposalWithRewardAccount
465-
(ParameterChange SNothing (emptyPParamsUpdate & ppuGovActionDepositL .~ SJust (Coin 10)) govPolicy)
459+
( ParameterChange
460+
SNothing
461+
(emptyPParamsUpdate & ppuGovActionDepositL .~ SJust (Coin 1000000))
462+
govPolicy
463+
)
466464
returnAddr
467465
>>= submitProposal
468466
expectPresentGovActionId gaid
@@ -502,7 +500,7 @@ eventsSpec = describe "Events" $ do
502500
propDeposit <- getsNES $ nesEsL . curPParamsEpochStateL . ppGovActionDepositL
503501
let
504502
proposeParameterChange = do
505-
newVal <- arbitrary
503+
newVal <- CoinPerByte . Coin <$> choose (3000, 6500)
506504
proposal <- submitParameterChange SNothing $ def & ppuCoinsPerUTxOByteL .~ SJust newVal
507505
pure
508506
(proposal, getsNES (nesEsL . curPParamsEpochStateL . ppCoinsPerUTxOByteL) `shouldReturn` newVal)
@@ -511,7 +509,7 @@ eventsSpec = describe "Events" $ do
511509
rewardAccount@(RewardAccount _ rewardCred) <- registerRewardAccount
512510
passEpoch -- prevent proposalC expiry and force it's deletion due to conflit.
513511
proposalC <- impAnn "proposalC" $ do
514-
newVal <- arbitrary
512+
newVal <- CoinPerByte . Coin <$> choose (3000, 6500)
515513
paramChange <- mkParameterChangeGovAction SNothing $ (def & ppuCoinsPerUTxOByteL .~ SJust newVal)
516514
mkProposalWithRewardAccount
517515
paramChange

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/GovSpec.hs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,18 +259,15 @@ proposalsSpec = do
259259
()
260260
[ Node () []
261261
]
262-
parameterChangeAction <-
263-
mkParameterChangeGovAction
264-
(SJust $ mkCorruptGovActionId p1)
265-
(def & ppuMinFeeAL .~ SJust (Coin 3000))
262+
parameterChangeAction <- mkMinFeeUpdateGovAction (SJust $ mkCorruptGovActionId p1)
266263
parameterChangeProposal <- mkProposal parameterChangeAction
267264
submitFailingProposal
268265
parameterChangeProposal
269266
[ injectFailure $ InvalidPrevGovActionId parameterChangeProposal
270267
]
271268
it "Subtrees are pruned when proposals expire" $ do
272269
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 4
273-
p1 <- submitParameterChange SNothing (def & ppuMinFeeAL .~ SJust (Coin 3000))
270+
p1 <- mkMinFeeUpdateGovAction SNothing >>= submitGovAction
274271
passNEpochs 3
275272
a <-
276273
submitParameterChangeTree
@@ -305,7 +302,7 @@ proposalsSpec = do
305302
, Node SNothing []
306303
]
307304
it "Subtrees are pruned when proposals expire over multiple rounds" $ do
308-
let ppupdate = def & ppuMinFeeAL .~ SJust (Coin 3000)
305+
let ppupdate = def & ppuMinFeeAL .~ SJust (Coin 1000)
309306
let submitInitialProposal = submitParameterChange SNothing ppupdate
310307
let submitChildProposal parent = submitParameterChange (SJust parent) ppupdate
311308
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 4
@@ -744,7 +741,7 @@ proposalsSpec = do
744741
submitParameterChangeForest = submitGovActionForest $ paramAction >=> submitGovAction
745742
submitParameterChangeTree = submitGovActionTree (paramAction >=> submitGovAction)
746743
submitConstitutionForest = submitGovActionForest $ submitConstitution . fmap GovPurposeId
747-
paramAction p = mkParameterChangeGovAction p (def & ppuMinFeeAL .~ SJust (Coin 10))
744+
paramAction p = mkParameterChangeGovAction p (def & ppuMinFeeAL .~ SJust (Coin 500))
748745

749746
votingSpec ::
750747
forall era.
@@ -1254,7 +1251,7 @@ bootstrapPhaseSpec ::
12541251
bootstrapPhaseSpec =
12551252
describe "Proposing and voting" $ do
12561253
it "Parameter change" $ do
1257-
gid <- submitParameterChange SNothing (def & ppuMinFeeAL .~ SJust (Coin 3000))
1254+
gid <- mkMinFeeUpdateGovAction SNothing >>= submitGovAction
12581255
(committee :| _) <- registerInitialCommittee
12591256
(drep, _, _) <- setupSingleDRep 1_000_000
12601257
(spo, _, _) <- setupPoolWithStake $ Coin 42_000_000

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/LedgerSpec.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import qualified Cardano.Ledger.Shelley.HardForks as HF (bootstrapPhase)
2727
import Cardano.Ledger.Shelley.LedgerState
2828
import Cardano.Ledger.Shelley.Rules (ShelleyLedgersEnv (..), ShelleyLedgersEvent (..))
2929
import Control.State.Transition.Extended
30-
import Data.Default (def)
3130
import qualified Data.Sequence as Seq
3231
import qualified Data.Set as Set
3332
import Lens.Micro ((&), (.~), (^.))
@@ -162,7 +161,7 @@ spec = do
162161
(drep, _, _) <- setupSingleDRep 1_000_000
163162

164163
-- expire the drep before delegation
165-
void $ submitParameterChange SNothing $ def & ppuMinFeeAL .~ SJust (Coin 3000)
164+
mkMinFeeUpdateGovAction SNothing >>= submitGovAction_
166165
passNEpochs 4
167166
isDRepExpired drep `shouldReturn` True
168167

@@ -191,7 +190,8 @@ spec = do
191190
_ <- delegateToDRep cred (Coin 1_000_000) (DRepCredential drep)
192191

193192
-- expire the drep after delegation
194-
void $ submitParameterChange SNothing $ def & ppuMinFeeAL .~ SJust (Coin 3000)
193+
mkMinFeeUpdateGovAction SNothing >>= submitGovAction_
194+
195195
passNEpochs 4
196196
isDRepExpired drep `shouldReturn` True
197197

0 commit comments

Comments
 (0)