Skip to content

Commit

Permalink
Initialize ImpTest state with current guardrail constitution
Browse files Browse the repository at this point in the history
and adjust tests
  • Loading branch information
teodanciu committed Nov 14, 2024
1 parent c9ef3e9 commit 48335ee
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 79 deletions.
1 change: 1 addition & 0 deletions eras/conway/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### `testlib`

* Add `minFeeUpdateGovAction`
* Add `mkTreasuryWithdrawalsGovAction` and `mkParameterChangeGovAction`
* Switch to using `ImpSpec` package
* Remove `withImpStateWithProtVer`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,16 @@ actionPrioritySpec =
nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . committeeGovStateL
committee `shouldBe` SNothing

let val1 = Coin 1_000_001
let val2 = Coin 1_000_002
let val3 = Coin 1_000_003

-- distinct constitutional values for minFee
let genMinFeeVals =
(\x y z -> (Coin x, Coin y, Coin z))
<$> uniformRM (30, 330)
<*> uniformRM (330, 660)
<*> uniformRM (660, 1000)
it "proposals of same priority are enacted in order of submission" $ do
modifyPParams $ ppPoolVotingThresholdsL . pvtPPSecurityGroupL .~ 1 %! 1
whenPostBootstrap (modifyPParams $ ppDRepVotingThresholdsL . dvtPPEconomicGroupL .~ def)
(val1, val2, val3) <- genMinFeeVals

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

committeeCs <- registerInitialCommittee
(spoC, _, _) <- setupPoolWithStake $ Coin 42_000_000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,10 @@ proposalsSpec =

initialValue <- getsNES (nesEsL . curPParamsEpochStateL . ppMinFeeAL)

policy <-
getsNES $
nesEpochStateL . epochStateGovStateL . constitutionGovStateL . constitutionScriptL
parameterChangeAction <- mkMinFeeUpdateGovAction SNothing
govActionId <-
mkProposalWithRewardAccount
(ParameterChange SNothing (def & ppuMinFeeAL .~ SJust (Coin 3000)) policy)
parameterChangeAction
rewardAccount
>>= submitProposal
expectPresentGovActionId govActionId
Expand Down Expand Up @@ -138,15 +136,15 @@ proposalsSpec =
let ratifyState = extractDRepPulsingState (govStateFinal ^. cgsDRepPulsingStateL)
rsExpired ratifyState `shouldBe` Set.singleton govActionId
where
submitParameterChangeTree = submitGovActionTree $ paramAction >=> submitGovAction
paramAction p = mkParameterChangeGovAction p (def & ppuMinFeeAL .~ SJust (Coin 10))
submitParameterChangeTree = submitGovActionTree $ mkMinFeeUpdateGovAction >=> submitGovAction

dRepSpec ::
forall era.
ConwayEraImp era =>
SpecWith (ImpInit (LedgerSpec era))
dRepSpec =
describe "DRep" $ do
let submitParamChangeProposal = mkMinFeeUpdateGovAction SNothing >>= submitGovAction_
it "expiry is updated based on the number of dormant epochs" $ do
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 2
(drep, _, _) <- setupSingleDRep 1_000_000
Expand All @@ -155,12 +153,10 @@ dRepSpec =
let
-- compute the epoch number that is an offset from starting epoch number
offDRepActivity = addEpochInterval startEpochNo . EpochInterval
submitParamChangeProposal =
submitParameterChange SNothing $ def & ppuMinFeeAL .~ SJust (Coin 3000)
expectNumDormantEpochs 0

-- epoch 0: we submit a proposal
_ <- submitParamChangeProposal
submitParamChangeProposal
passNEpochsChecking 2 $ do
expectNumDormantEpochs 0
expectDRepExpiry drep $ offDRepActivity 100
Expand All @@ -178,7 +174,7 @@ dRepSpec =
expectNumDormantEpochs 3
expectDRepExpiry drep $ offDRepActivity 100

_ <- submitParamChangeProposal
submitParamChangeProposal
-- number of dormant epochs is added to the drep expiry and reset to 0
expectNumDormantEpochs 0
expectDRepExpiry drep $ offDRepActivity 103
Expand All @@ -201,12 +197,10 @@ dRepSpec =
offDRepActivity offset =
addEpochInterval startEpochNo $ EpochInterval (drepActivity + offset)

let submitParamChangeProposal =
submitParameterChange SNothing $ def & ppuMinFeeAL .~ SJust (Coin 3000)
expectNumDormantEpochs 0

-- epoch 0: we submit a proposal
_ <- submitParamChangeProposal
submitParamChangeProposal
passNEpochsChecking 2 $ do
expectNumDormantEpochs 0
expectDRepExpiry drep $ offDRepActivity 0
Expand All @@ -228,7 +222,7 @@ dRepSpec =
expectDRepExpiry drep $ offDRepActivity 0
expectActualDRepExpiry drep $ offDRepActivity 3

_ <- submitParamChangeProposal
submitParamChangeProposal
-- number of dormant epochs is added to the drep, considering they are not actually expired,
-- and is reset to 0
expectNumDormantEpochs 0
Expand Down Expand Up @@ -462,7 +456,11 @@ depositMovesToTreasuryWhenStakingAddressUnregisters = do
govPolicy <- getGovPolicy
gaid <-
mkProposalWithRewardAccount
(ParameterChange SNothing (emptyPParamsUpdate & ppuGovActionDepositL .~ SJust (Coin 10)) govPolicy)
( ParameterChange
SNothing
(emptyPParamsUpdate & ppuGovActionDepositL .~ SJust (Coin 1000000))
govPolicy
)
returnAddr
>>= submitProposal
expectPresentGovActionId gaid
Expand Down Expand Up @@ -502,7 +500,7 @@ eventsSpec = describe "Events" $ do
propDeposit <- getsNES $ nesEsL . curPParamsEpochStateL . ppGovActionDepositL
let
proposeParameterChange = do
newVal <- arbitrary
newVal <- CoinPerByte . Coin <$> choose (3000, 6500)
proposal <- submitParameterChange SNothing $ def & ppuCoinsPerUTxOByteL .~ SJust newVal
pure
(proposal, getsNES (nesEsL . curPParamsEpochStateL . ppCoinsPerUTxOByteL) `shouldReturn` newVal)
Expand All @@ -511,7 +509,7 @@ eventsSpec = describe "Events" $ do
rewardAccount@(RewardAccount _ rewardCred) <- registerRewardAccount
passEpoch -- prevent proposalC expiry and force it's deletion due to conflit.
proposalC <- impAnn "proposalC" $ do
newVal <- arbitrary
newVal <- CoinPerByte . Coin <$> choose (3000, 6500)
paramChange <- mkParameterChangeGovAction SNothing $ (def & ppuCoinsPerUTxOByteL .~ SJust newVal)
mkProposalWithRewardAccount
paramChange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,15 @@ proposalsSpec = do
()
[ Node () []
]
parameterChangeAction <-
mkParameterChangeGovAction
(SJust $ mkCorruptGovActionId p1)
(def & ppuMinFeeAL .~ SJust (Coin 3000))
parameterChangeAction <- mkMinFeeUpdateGovAction (SJust $ mkCorruptGovActionId p1)
parameterChangeProposal <- mkProposal parameterChangeAction
submitFailingProposal
parameterChangeProposal
[ injectFailure $ InvalidPrevGovActionId parameterChangeProposal
]
it "Subtrees are pruned when proposals expire" $ do
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 4
p1 <- submitParameterChange SNothing (def & ppuMinFeeAL .~ SJust (Coin 3000))
p1 <- mkMinFeeUpdateGovAction SNothing >>= submitGovAction
passNEpochs 3
a <-
submitParameterChangeTree
Expand Down Expand Up @@ -305,7 +302,7 @@ proposalsSpec = do
, Node SNothing []
]
it "Subtrees are pruned when proposals expire over multiple rounds" $ do
let ppupdate = def & ppuMinFeeAL .~ SJust (Coin 3000)
let ppupdate = def & ppuMinFeeAL .~ SJust (Coin 1000)
let submitInitialProposal = submitParameterChange SNothing ppupdate
let submitChildProposal parent = submitParameterChange (SJust parent) ppupdate
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 4
Expand Down Expand Up @@ -744,7 +741,7 @@ proposalsSpec = do
submitParameterChangeForest = submitGovActionForest $ paramAction >=> submitGovAction
submitParameterChangeTree = submitGovActionTree (paramAction >=> submitGovAction)
submitConstitutionForest = submitGovActionForest $ submitConstitution . fmap GovPurposeId
paramAction p = mkParameterChangeGovAction p (def & ppuMinFeeAL .~ SJust (Coin 10))
paramAction p = mkParameterChangeGovAction p (def & ppuMinFeeAL .~ SJust (Coin 500))

votingSpec ::
forall era.
Expand Down Expand Up @@ -1254,7 +1251,7 @@ bootstrapPhaseSpec ::
bootstrapPhaseSpec =
describe "Proposing and voting" $ do
it "Parameter change" $ do
gid <- submitParameterChange SNothing (def & ppuMinFeeAL .~ SJust (Coin 3000))
gid <- mkMinFeeUpdateGovAction SNothing >>= submitGovAction
(committee :| _) <- registerInitialCommittee
(drep, _, _) <- setupSingleDRep 1_000_000
(spo, _, _) <- setupPoolWithStake $ Coin 42_000_000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import qualified Cardano.Ledger.Shelley.HardForks as HF (bootstrapPhase)
import Cardano.Ledger.Shelley.LedgerState
import Cardano.Ledger.Shelley.Rules (ShelleyLedgersEnv (..), ShelleyLedgersEvent (..))
import Control.State.Transition.Extended
import Data.Default (def)
import qualified Data.Sequence as Seq
import qualified Data.Set as Set
import Lens.Micro ((&), (.~), (^.))
Expand Down Expand Up @@ -162,7 +161,7 @@ spec = do
(drep, _, _) <- setupSingleDRep 1_000_000

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

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

-- expire the drep after delegation
void $ submitParameterChange SNothing $ def & ppuMinFeeAL .~ SJust (Coin 3000)
mkMinFeeUpdateGovAction SNothing >>= submitGovAction_

passNEpochs 4
isDRepExpired drep `shouldReturn` True

Expand Down
Loading

0 comments on commit 48335ee

Please sign in to comment.