Skip to content

Commit

Permalink
Consolidate setting of pparams in Imp tests
Browse files Browse the repository at this point in the history
* set sensible values when initializing NewEpochState
* remove duplicated modifications of the same parameters
  • Loading branch information
teodanciu committed Apr 25, 2024
1 parent 1ac5f36 commit 5d5b461
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ treasuryWithdrawalsSpec =
it "Withdrawals exceeding treasury submitted in a single proposal" $ do
(committeeC :| _) <- registerInitialCommittee
(drepC, _, _) <- setupSingleDRep 1_000_000
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 5
initialTreasury <- getTreasury
numWithdrawals <- choose (1, 10)
withdrawals <- genWithdrawalsExceeding initialTreasury numWithdrawals
Expand All @@ -129,7 +128,6 @@ treasuryWithdrawalsSpec =
it "Withdrawals exceeding maxBound Word64 submitted in a single proposal" $ do
(committeeC :| _) <- registerInitialCommittee
(drepC, _, _) <- setupSingleDRep 1_000_000
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 5
initialTreasury <- getTreasury
numWithdrawals <- choose (1, 10)
withdrawals <- genWithdrawalsExceeding (Coin (fromIntegral (maxBound :: Word64))) numWithdrawals
Expand All @@ -139,7 +137,6 @@ treasuryWithdrawalsSpec =
it "Withdrawals exceeding treasury submitted in several proposals within the same epoch" $ do
(committeeC :| _) <- registerInitialCommittee
(drepC, _, _) <- setupSingleDRep 1_000_000
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 5
initialTreasury <- getTreasury
numWithdrawals <- choose (1, 10)
withdrawals <- genWithdrawalsExceeding initialTreasury numWithdrawals
Expand Down Expand Up @@ -347,7 +344,6 @@ actionPrioritySpec =
$ do
(drepC, _, _) <- setupSingleDRep 1_000_000
(poolKH, _, _) <- setupPoolWithStake $ Coin 1_000_000
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 5
cc <- KeyHashObj <$> freshKeyHash
gai1 <-
submitGovAction $
Expand Down Expand Up @@ -379,7 +375,6 @@ actionPrioritySpec =
it "proposals of same priority are enacted in order of submission" $ do
(committeeC :| _) <- registerInitialCommittee
(drepC, _, _) <- setupSingleDRep 1_000_000
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 5
pGai0 <-
submitParameterChange
SNothing
Expand Down Expand Up @@ -408,7 +403,6 @@ actionPrioritySpec =
it "only the first action of a transaction gets enacted" $ do
(committeeC :| _) <- registerInitialCommittee
(drepC, _, _) <- setupSingleDRep 1_000_000
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 5
gaids <-
submitGovActions $
NE.fromList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import Data.Maybe.Strict (StrictMaybe (..))
import qualified Data.Sequence.Strict as SSeq
import qualified Data.Set as Set
import Data.Tree
import Lens.Micro ((%~), (&), (.~))
import Lens.Micro ((&), (.~))
import Test.Cardano.Ledger.Conway.ImpTest
import Test.Cardano.Ledger.Core.Rational (IsRatio (..))
import Test.Cardano.Ledger.Imp.Common
Expand Down Expand Up @@ -189,17 +189,6 @@ dRepSpec =
logStakeDistr
passEpoch
it "constitution is accepted after two epochs" $ do
modifyPParams $ \pp ->
pp
& ppDRepVotingThresholdsL
%~ ( \dvt ->
dvt
{ dvtCommitteeNormal = 1 %! 1
, dvtCommitteeNoConfidence = 1 %! 2
, dvtUpdateToConstitution = 1 %! 2
}
)

constitutionHash <- freshSafeHash
let
constitutionAction =
Expand Down Expand Up @@ -300,6 +289,7 @@ depositMovesToTreasuryWhenStakingAddressUnregisters = do
pp
& ppGovActionLifetimeL .~ EpochInterval 8
& ppGovActionDepositL .~ Coin 100
& ppCommitteeMaxTermLengthL .~ EpochInterval 0
returnAddr <- registerRewardAccount
govActionDeposit <- getsNES $ nesEsL . curPParamsEpochStateL . ppGovActionDepositL
khCC <- KeyHashObj <$> freshKeyHash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

module Test.Cardano.Ledger.Conway.Imp.GovCertSpec (spec) where

import Cardano.Ledger.BaseTypes (EpochInterval (..))
import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Conway.Core (
EraGov (..),
Expand All @@ -26,7 +25,6 @@ import Cardano.Ledger.Conway.Governance (
Voter (..),
committeeMembersL,
)
import Cardano.Ledger.Conway.PParams (ppCommitteeMaxTermLengthL)
import Cardano.Ledger.Conway.Rules (ConwayGovCertPredFailure (..))
import Cardano.Ledger.Conway.TxCert (
pattern AuthCommitteeHotKeyTxCert,
Expand Down Expand Up @@ -66,7 +64,6 @@ spec = describe "GOVCERT" $ do
it
"A CC that has resigned will need to be first voted out and then voted in to be considered active"
$ do
modifyPParams $ \pp -> pp & ppCommitteeMaxTermLengthL .~ EpochInterval 20
(drepCred, _, _) <- setupSingleDRep 1_000_000
passNEpochs 2
-- Add a fresh CC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ proposalsSpec =
let mkCorruptGovActionId :: GovActionId c -> GovActionId c
mkCorruptGovActionId (GovActionId txi (GovActionIx gaix)) =
GovActionId txi $ GovActionIx $ gaix + 999
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 4
Node p1 [Node _p11 []] <-
submitConstitutionGovActionTree
SNothing
Expand Down Expand Up @@ -789,7 +788,6 @@ votingSpec =
{ dvtUpdateToConstitution = 1 %! 2
}
& ppCommitteeMinSizeL .~ 2
& ppCommitteeMaxTermLengthL .~ EpochInterval 10
(dRepCred, _, _) <- setupSingleDRep 1_000_000
ccColdCred0 <- KeyHashObj <$> freshKeyHash
ccColdCred1 <- KeyHashObj <$> freshKeyHash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,7 @@ committeeExpiryResignationDiscountSpec ::
committeeExpiryResignationDiscountSpec =
describe "Expired and resigned committee members are discounted from quorum" $ do
it "Expired" $ do
modifyPParams $ \pp ->
pp
& ppGovActionLifetimeL .~ EpochInterval 10
& ppDRepVotingThresholdsL
.~ def
{ dvtCommitteeNormal = 1 %! 10
, dvtUpdateToConstitution = 1 %! 10
}
& ppCommitteeMinSizeL .~ 2
& ppCommitteeMaxTermLengthL .~ EpochInterval 10
modifyPParams $ ppCommitteeMinSizeL .~ 2
(drep, _, _) <- setupSingleDRep 1_000_000
-- Elect a committee of 2 members
committeeColdC1 <- KeyHashObj <$> freshKeyHash
Expand Down Expand Up @@ -87,16 +78,7 @@ committeeExpiryResignationDiscountSpec =
ccShouldBeExpired committeeColdC2
isCommitteeAccepted gaiConstitution `shouldReturn` False
it "Resigned" $ do
modifyPParams $ \pp ->
pp
& ppGovActionLifetimeL .~ EpochInterval 10
& ppDRepVotingThresholdsL
.~ def
{ dvtCommitteeNormal = 1 %! 10
, dvtUpdateToConstitution = 1 %! 10
}
& ppCommitteeMinSizeL .~ 2
& ppCommitteeMaxTermLengthL .~ EpochInterval 10
modifyPParams $ ppCommitteeMinSizeL .~ 2
(drep, _, _) <- setupSingleDRep 1_000_000
-- Elect a committee of 2 members
committeeColdC1 <- KeyHashObj <$> freshKeyHash
Expand Down Expand Up @@ -186,7 +168,6 @@ paramChangeAffectsProposalsSpec =
isDRepAccepted gaiChild `shouldReturn` False
it "Decreasing the threshold ratifies a hitherto-unratifiable proposal" $ do
(drepC, hotCommitteeC, gpiCC) <- electBasicCommittee
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 5
setThreshold largerThreshold
(drep, _, _) <- setupSingleDRep 1_000_000
(gaiParent, gaiChild) <- submitTwoExampleProposalsAndVoteOnTheChild gpiCC drep
Expand Down Expand Up @@ -257,7 +238,6 @@ paramChangeAffectsProposalsSpec =
isSpoAccepted gaiChild `shouldReturn` False
it "Decreasing the threshold ratifies a hitherto-unratifiable proposal" $ do
(drepC, hotCommitteeC, gpiCC) <- electBasicCommittee
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 5
setThreshold largerThreshold
(poolKH1, _paymentC1, _stakingC1) <- setupPoolWithStake $ Coin 1_000_000
(poolKH2, _paymentC2, _stakingC2) <- setupPoolWithStake $ Coin 1_000_000
Expand Down Expand Up @@ -346,7 +326,6 @@ committeeMinSizeAffectsInFlightProposalsSpec =
getsNES (nesEsL . esAccountStateL . asTreasuryL) `shouldReturn` treasury
it "TreasuryWithdrawal ratifies due to a decrease in CommitteeMinSize" $ do
(drepC, hotCommitteeC, gpiCC) <- electBasicCommittee
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 10
treasury <- getsNES $ nesEsL . esAccountStateL . asTreasuryL
gaiTW <- submitATreasuryWithdrawal
submitYesVote_ (CommitteeVoter hotCommitteeC) gaiTW
Expand Down Expand Up @@ -406,7 +385,10 @@ spoVotesForHardForkInitiation =
(_spoK2, _paymentC2, _stakingC2) <- setupPoolWithStake $ Coin 1_000
(_spoK3, _paymentC3, _stakingC3) <- setupPoolWithStake $ Coin 1_000
(_spoK4, _paymentC4, _stakingC4) <- setupPoolWithStake $ Coin 1_000
modifyPParams $ ppPoolVotingThresholdsL . pvtMotionNoConfidenceL .~ 1 %! 2
modifyPParams $ \pp ->
pp
& ppPoolVotingThresholdsL . pvtMotionNoConfidenceL .~ 1 %! 2
& ppDRepVotingThresholdsL .~ def
gai <- submitGovAction $ NoConfidence SNothing
-- 1 % 4 stake yes; 3 % 4 stake abstain; yes / stake - abstain > 1 % 2
submitYesVote_ (StakePoolVoter spoK1) gai
Expand All @@ -417,8 +399,11 @@ spoVotesForHardForkInitiation =
(_spoK2, _paymentC2, _stakingC2) <- setupPoolWithStake $ Coin 1_000
(_spoK3, _paymentC3, _stakingC3) <- setupPoolWithStake $ Coin 1_000
(_spoK4, _paymentC4, _stakingC4) <- setupPoolWithStake $ Coin 1_000
modifyPParams $ ppPoolVotingThresholdsL . pvtCommitteeNormalL .~ 1 %! 2
modifyPParams $ ppCommitteeMaxTermLengthL .~ EpochInterval 10
modifyPParams $ \pp ->
pp
& ppPoolVotingThresholdsL . pvtCommitteeNormalL .~ 1 %! 2
& ppDRepVotingThresholdsL .~ def

committeeC <- KeyHashObj <$> freshKeyHash
gai <-
submitGovAction $
Expand Down Expand Up @@ -519,7 +504,6 @@ votingSpec =
{ dvtCommitteeNormal = 51 %! 100
, dvtCommitteeNoConfidence = 51 %! 100
}
& ppCommitteeMaxTermLengthL .~ EpochInterval 20
-- Setup DRep delegation #1
(drep1, KeyHashObj stakingKH1, paymentKP1) <- setupSingleDRep 1_000_000
-- Setup DRep delegation #2
Expand Down Expand Up @@ -550,7 +534,6 @@ votingSpec =
{ dvtCommitteeNormal = 51 %! 100
, dvtCommitteeNoConfidence = 51 %! 100
}
& ppCommitteeMaxTermLengthL .~ EpochInterval 20
-- Setup DRep delegation #1
(drep1, staking1, _) <- setupSingleDRep 1_000_000
-- Setup DRep delegation #2
Expand Down Expand Up @@ -586,11 +569,11 @@ votingSpec =
{ pvtCommitteeNormal = 51 %! 100
, pvtCommitteeNoConfidence = 51 %! 100
}
& ppCommitteeMaxTermLengthL .~ EpochInterval 20
& ppDRepVotingThresholdsL .~ def
-- Setup Pool delegation #1
(poolKH1, delegatorCPayment1, delegatorCStaking1) <- setupPoolWithStake $ Coin 1_000_000
-- Setup Pool delegation #2
(poolKH2, _delegatorCPayment2, _delegatorCStaking2) <- setupPoolWithStake $ Coin 1_000_000
(poolKH2, _, _) <- setupPoolWithStake $ Coin 1_000_000
passEpoch
-- Submit a committee proposal
cc <- KeyHashObj <$> freshKeyHash
Expand Down Expand Up @@ -622,11 +605,11 @@ votingSpec =
{ pvtCommitteeNormal = 51 %! 100
, pvtCommitteeNoConfidence = 51 %! 100
}
& ppCommitteeMaxTermLengthL .~ EpochInterval 20
& ppDRepVotingThresholdsL .~ def
-- Setup Pool delegation #1
(poolKH1, _delegatorCPayment1, delegatorCStaking1) <- setupPoolWithStake $ Coin 1_000_000
(poolKH1, _, delegatorCStaking1) <- setupPoolWithStake $ Coin 1_000_000
-- Setup Pool delegation #2
(poolKH2, _delegatorCPayment2, _delegatorCStaking2) <- setupPoolWithStake $ Coin 1_000_000
(poolKH2, _, _) <- setupPoolWithStake $ Coin 1_000_000
passEpoch
-- Submit a committee proposal
cc <- KeyHashObj <$> freshKeyHash
Expand Down Expand Up @@ -660,7 +643,6 @@ delayingActionsSpec =
it "A delaying action delays its child even when both ere proposed and ratified in the same epoch" $ do
(committeeMember :| _) <- registerInitialCommittee
(dRep, _, _) <- setupSingleDRep 1_000_000
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 5
gai0 <- submitInitConstitutionGovAction
gai1 <- submitChildConstitutionGovAction gai0
gai2 <- submitChildConstitutionGovAction gai1
Expand All @@ -687,7 +669,6 @@ delayingActionsSpec =
$ do
(committeeMember :| _) <- registerInitialCommittee
(dRep, _, _) <- setupSingleDRep 1_000_000
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 5
pGai0 <-
submitParameterChange
SNothing
Expand Down Expand Up @@ -808,21 +789,6 @@ delayingActionsSpec =
nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . committeeGovStateL
let members = Map.keysSet $ foldMap' committeeMembers committee
impAnn "Expecting committee members" $ members `shouldBe` expKhs
setPParams :: HasCallStack => ImpTestM era ()
setPParams = do
modifyPParams $ \pp ->
pp
& ppDRepVotingThresholdsL
.~ def
{ dvtCommitteeNormal = 1 %! 1
, dvtCommitteeNoConfidence = 1 %! 2
, dvtUpdateToConstitution = 1 %! 2
}
& ppCommitteeMaxTermLengthL .~ EpochInterval 10
& ppGovActionLifetimeL .~ EpochInterval 100
& ppGovActionDepositL .~ Coin 123

setPParams
(drep, _, _) <- setupSingleDRep 1_000_000
maxTermLength <-
getsNES $
Expand Down
26 changes: 12 additions & 14 deletions eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/ImpTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ instance
(initAlonzoImpNES nes)
& nesEsL . curPParamsEpochStateL . ppDRepActivityL .~ EpochInterval 100
& nesEsL . curPParamsEpochStateL . ppGovActionLifetimeL .~ EpochInterval 30
& nesEsL . curPParamsEpochStateL . ppGovActionDepositL .~ Coin 123
& nesEsL . curPParamsEpochStateL . ppCommitteeMaxTermLengthL .~ EpochInterval 20
& nesEsL . curPParamsEpochStateL . ppCommitteeMinSizeL .~ 1
& nesEsL . curPParamsEpochStateL . ppDRepVotingThresholdsL
%~ ( \dvt ->
dvt
{ dvtCommitteeNormal = 1 %! 1
, dvtCommitteeNoConfidence = 1 %! 2
, dvtUpdateToConstitution = 1 %! 2
}
)
& nesEsL . epochStateGovStateL . committeeGovStateL .~ SJust committee
epochState = newNes ^. nesEsL
ratifyState =
Expand Down Expand Up @@ -1063,20 +1074,7 @@ electBasicCommittee ::
, GovPurposeId 'CommitteePurpose era
)
electBasicCommittee = do
logEntry "Setting up PParams and DRep"
modifyPParams $ \pp ->
pp
& ppDRepVotingThresholdsL
%~ ( \dvt ->
dvt
{ dvtCommitteeNormal = 1 %! 1
, dvtCommitteeNoConfidence = 1 %! 2
, dvtUpdateToConstitution = 1 %! 2
}
)
& ppCommitteeMaxTermLengthL .~ EpochInterval 20
& ppGovActionLifetimeL .~ EpochInterval 2
& ppGovActionDepositL .~ Coin 123
logEntry "Setting up a DRep"
(drep, _, _) <- setupSingleDRep 1_000_000

logEntry "Registering committee member"
Expand Down

0 comments on commit 5d5b461

Please sign in to comment.