Skip to content

Commit

Permalink
Update setupSingleDRep to return Credential instead of KeyHash
Browse files Browse the repository at this point in the history
in order to reduce noise in tests
  • Loading branch information
teodanciu committed Apr 25, 2024
1 parent dbb722c commit f18b579
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 174 deletions.
1 change: 1 addition & 0 deletions eras/conway/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

### `testlib`

* Change return type of `setupSingleDRep` to Credential instead of KeyHash
* Add `registerInitialCommittee` and `getCommitteeMembers` to Conway ImpTest
* Implement `ConwayUtxowPredFailure` instances:
* `Arbitrary`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ treasuryWithdrawalsSpec =

it "Withdrawals exceeding treasury submitted in a single proposal" $ do
(committeeC :| _) <- registerInitialCommittee
(drepKh, _, _) <- setupSingleDRep 1_000_000
(drepC, _, _) <- setupSingleDRep 1_000_000
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 5
initialTreasury <- getTreasury
numWithdrawals <- choose (1, 10)
withdrawals <- genWithdrawalsExceeding initialTreasury numWithdrawals

void $ enactTreasuryWithdrawals withdrawals (KeyHashObj drepKh) committeeC
void $ enactTreasuryWithdrawals withdrawals drepC committeeC
checkNoWithdrawal initialTreasury withdrawals

let sumRequested = foldMap snd withdrawals
Expand All @@ -128,17 +128,17 @@ treasuryWithdrawalsSpec =

it "Withdrawals exceeding maxBound Word64 submitted in a single proposal" $ do
(committeeC :| _) <- registerInitialCommittee
(drepKh, _, _) <- setupSingleDRep 1_000_000
(drepC, _, _) <- setupSingleDRep 1_000_000
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 5
initialTreasury <- getTreasury
numWithdrawals <- choose (1, 10)
withdrawals <- genWithdrawalsExceeding (Coin (fromIntegral (maxBound :: Word64))) numWithdrawals
void $ enactTreasuryWithdrawals withdrawals (KeyHashObj drepKh) committeeC
void $ enactTreasuryWithdrawals withdrawals drepC committeeC
checkNoWithdrawal initialTreasury withdrawals

it "Withdrawals exceeding treasury submitted in several proposals within the same epoch" $ do
(committeeC :| _) <- registerInitialCommittee
(drepKh, _, _) <- setupSingleDRep 1_000_000
(drepC, _, _) <- setupSingleDRep 1_000_000
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 5
initialTreasury <- getTreasury
numWithdrawals <- choose (1, 10)
Expand All @@ -148,7 +148,7 @@ treasuryWithdrawalsSpec =
traverse_
( \w -> do
gaId <- submitTreasuryWithdrawals @era [w]
submitYesVote_ (DRepVoter (KeyHashObj drepKh)) gaId
submitYesVote_ (DRepVoter drepC) gaId
submitYesVote_ (CommitteeVoter committeeC) gaId
)
withdrawals
Expand Down Expand Up @@ -187,7 +187,7 @@ treasuryWithdrawalsSpec =
hardForkInitiationSpec :: ConwayEraImp era => SpecWith (ImpTestState era)
hardForkInitiationSpec =
it "HardForkInitiation" $ do
(committeeC :| _) <- registerInitialCommittee
(committeeMember :| _) <- registerInitialCommittee
modifyPParams $ \pp ->
pp
& ppDRepVotingThresholdsL
Expand All @@ -213,12 +213,12 @@ hardForkInitiationSpec =
nextMajorVersion <- succVersion $ pvMajor curProtVer
let nextProtVer = curProtVer {pvMajor = nextMajorVersion}
govActionId <- submitGovAction $ HardForkInitiation SNothing nextProtVer
submitYesVote_ (CommitteeVoter committeeC) govActionId
submitYesVote_ (DRepVoter (KeyHashObj dRep1)) govActionId
submitYesVote_ (CommitteeVoter committeeMember) govActionId
submitYesVote_ (DRepVoter dRep1) govActionId
submitYesVote_ (StakePoolVoter stakePoolId1) govActionId
passNEpochs 2
getsNES (nesEsL . curPParamsEpochStateL . ppProtocolVersionL) `shouldReturn` curProtVer
submitYesVote_ (DRepVoter (KeyHashObj dRep2)) govActionId
submitYesVote_ (DRepVoter dRep2) govActionId
passNEpochs 2
getsNES (nesEsL . curPParamsEpochStateL . ppProtocolVersionL) `shouldReturn` curProtVer
submitYesVote_ (StakePoolVoter stakePoolId2) govActionId
Expand Down Expand Up @@ -274,34 +274,34 @@ noConfidenceSpec =
, pProcAnchor = def
}
submitYesVote_ (StakePoolVoter khSPO) gaidNoConf
submitYesVote_ (DRepVoter $ KeyHashObj drep) gaidNoConf
submitYesVote_ (DRepVoter drep) gaidNoConf
replicateM_ 4 passEpoch
assertNoCommittee

constitutionSpec :: ConwayEraImp era => SpecWith (ImpTestState era)
constitutionSpec =
it "Constitution" $ do
(committeeC :| _) <- registerInitialCommittee
(drepKh, _, _) <- setupSingleDRep 1_000_000
(committeeMember :| _) <- registerInitialCommittee
(dRep, _, _) <- setupSingleDRep 1_000_000
(govActionId, constitution) <- submitConstitution SNothing

proposalsBeforeVotes <- getsNES $ newEpochStateGovStateL . proposalsGovStateL
pulserBeforeVotes <- getsNES newEpochStateDRepPulsingStateL

submitYesVote_ (DRepVoter (KeyHashObj drepKh)) govActionId
submitYesVote_ (CommitteeVoter committeeC) govActionId
submitYesVote_ (DRepVoter dRep) govActionId
submitYesVote_ (CommitteeVoter committeeMember) govActionId

proposalsAfterVotes <- getsNES $ newEpochStateGovStateL . proposalsGovStateL
pulserAfterVotes <- getsNES newEpochStateDRepPulsingStateL

impAnn "Votes are recorded in the proposals" $ do
let proposalsWithVotes =
proposalsAddVote
(CommitteeVoter committeeC)
(CommitteeVoter committeeMember)
VoteYes
govActionId
( proposalsAddVote
(DRepVoter (KeyHashObj drepKh))
(DRepVoter dRep)
VoteYes
govActionId
proposalsBeforeVotes
Expand Down Expand Up @@ -345,7 +345,7 @@ actionPrioritySpec =
it
"higher action priority wins"
$ do
(drepKh, _, _) <- setupSingleDRep 1_000_000
(drepC, _, _) <- setupSingleDRep 1_000_000
(poolKH, _, _) <- setupPoolWithStake $ Coin 1_000_000
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 5
cc <- KeyHashObj <$> freshKeyHash
Expand All @@ -358,7 +358,7 @@ actionPrioritySpec =
gai3 <- submitGovAction $ NoConfidence SNothing
traverse_ @[]
( \gaid -> do
submitYesVote_ (DRepVoter (KeyHashObj drepKh)) gaid
submitYesVote_ (DRepVoter drepC) gaid
submitYesVote_ (StakePoolVoter poolKH) gaid
)
[gai1, gai2, gai3]
Expand All @@ -378,7 +378,7 @@ actionPrioritySpec =

it "proposals of same priority are enacted in order of submission" $ do
(committeeC :| _) <- registerInitialCommittee
(drepKh, _, _) <- setupSingleDRep 1_000_000
(drepC, _, _) <- setupSingleDRep 1_000_000
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 5
pGai0 <-
submitParameterChange
Expand All @@ -394,7 +394,7 @@ actionPrioritySpec =
$ def & ppuDRepDepositL .~ SJust val3
traverse_ @[]
( \gaid -> do
submitYesVote_ (DRepVoter (KeyHashObj drepKh)) gaid
submitYesVote_ (DRepVoter drepC) gaid
submitYesVote_ (CommitteeVoter committeeC) gaid
)
[pGai0, pGai1, pGai2]
Expand All @@ -407,7 +407,7 @@ actionPrioritySpec =

it "only the first action of a transaction gets enacted" $ do
(committeeC :| _) <- registerInitialCommittee
(drepKh, _, _) <- setupSingleDRep 1_000_000
(drepC, _, _) <- setupSingleDRep 1_000_000
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 5
gaids <-
submitGovActions $
Expand All @@ -427,7 +427,7 @@ actionPrioritySpec =
]
traverse_
( \gaid -> do
submitYesVote_ (DRepVoter (KeyHashObj drepKh)) gaid
submitYesVote_ (DRepVoter drepC) gaid
submitYesVote_ (CommitteeVoter committeeC) gaid
)
gaids
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ dRepSpec =
gaidConstitutionProp <- submitGovAction constitutionAction

(committeeHotCred :| _) <- registerInitialCommittee
(drepKh, _, _) <- setupSingleDRep 1_000_000
(dRepCred, _, _) <- setupSingleDRep 1_000_000
passEpoch
logRatificationChecks gaidConstitutionProp
do
isAccepted <- isDRepAccepted gaidConstitutionProp
assertBool "Gov action should not be accepted" $ not isAccepted
submitYesVote_ (DRepVoter (KeyHashObj drepKh)) gaidConstitutionProp
submitYesVote_ (DRepVoter dRepCred) gaidConstitutionProp
submitYesVote_ (CommitteeVoter committeeHotCred) gaidConstitutionProp
logAcceptedRatio gaidConstitutionProp
do
Expand Down Expand Up @@ -271,7 +271,7 @@ treasuryWithdrawalExpectation ::
ImpTestM era ()
treasuryWithdrawalExpectation extraWithdrawals = do
(committeeHotCred :| _) <- registerInitialCommittee
(drepKh, _, _) <- setupSingleDRep 1_000_000
(dRepCred, _, _) <- setupSingleDRep 1_000_000
treasuryStart <- getsNES $ nesEsL . esAccountStateL . asTreasuryL
rewardAccount <- registerRewardAccount
govPolicy <- getGovPolicy
Expand All @@ -280,7 +280,7 @@ treasuryWithdrawalExpectation extraWithdrawals = do
submitGovActions $
TreasuryWithdrawals (Map.singleton rewardAccount withdrawalAmount) govPolicy
NE.:| extraWithdrawals
submitYesVote_ (DRepVoter (KeyHashObj drepKh)) govActionId
submitYesVote_ (DRepVoter dRepCred) govActionId
submitYesVote_ (CommitteeVoter committeeHotCred) govActionId
passEpoch -- 1st epoch crossing starts DRep pulser
impAnn "Withdrawal should not be received yet" $
Expand Down Expand Up @@ -342,7 +342,7 @@ eventsSpec = describe "Events" $ do
describe "emits event" $ do
it "GovInfoEvent" $ do
(ccCred :| _) <- registerInitialCommittee
(drepKh, _, _) <- setupSingleDRep 1_000_000
(dRepCred, _, _) <- setupSingleDRep 1_000_000
let actionLifetime = 10
modifyPParams $ \pp ->
pp
Expand Down Expand Up @@ -381,7 +381,7 @@ eventsSpec = describe "Events" $ do
]
replicateM_ (fromIntegral actionLifetime) passEpochWithNoDroppedActions
logAcceptedRatio proposalA
submitYesVote_ (DRepVoter (KeyHashObj drepKh)) proposalA
submitYesVote_ (DRepVoter dRepCred) proposalA
submitYesVote_ (CommitteeVoter ccCred) proposalA
gasA <- getGovActionState proposalA
gasB <- getGovActionState proposalB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ spec = describe "GOVCERT" $ do
"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
(drepKh, _, _) <- setupSingleDRep 1_000_000
(drepCred, _, _) <- setupSingleDRep 1_000_000
passNEpochs 2
-- Add a fresh CC
cc <- KeyHashObj <$> freshKeyHash
let addCCAction = UpdateCommittee SNothing mempty (Map.singleton cc 10) (1 %! 2)
addCCGaid <- submitGovAction addCCAction
submitYesVote_ (DRepVoter (KeyHashObj drepKh)) addCCGaid
submitYesVote_ (DRepVoter drepCred) addCCGaid
passNEpochs 2
-- Confirm that they are added
SJust committee <- getsNES $ nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . committeeGovStateL
Expand All @@ -93,14 +93,14 @@ spec = describe "GOVCERT" $ do
-- Re-add the same CC
let reAddCCAction = UpdateCommittee (SJust $ GovPurposeId addCCGaid) mempty (Map.singleton cc 20) (1 %! 2)
reAddCCGaid <- submitGovAction reAddCCAction
submitYesVote_ (DRepVoter (KeyHashObj drepKh)) reAddCCGaid
submitYesVote_ (DRepVoter drepCred) reAddCCGaid
passNEpochs 2
-- Confirm that they are still resigned
ccShouldBeResigned cc
-- Remove them
let removeCCAction = UpdateCommittee (SJust $ GovPurposeId reAddCCGaid) (Set.singleton cc) mempty (1 %! 2)
removeCCGaid <- submitGovAction removeCCAction
submitYesVote_ (DRepVoter (KeyHashObj drepKh)) removeCCGaid
submitYesVote_ (DRepVoter drepCred) removeCCGaid
passNEpochs 2
-- Confirm that they have been removed
SJust committeeAfterRemove <-
Expand All @@ -109,7 +109,7 @@ spec = describe "GOVCERT" $ do
-- Add the same CC back a second time
let secondAddCCAction = UpdateCommittee (SJust $ GovPurposeId removeCCGaid) mempty (Map.singleton cc 20) (1 %! 2)
secondAddCCGaid <- submitGovAction secondAddCCAction
submitYesVote_ (DRepVoter (KeyHashObj drepKh)) secondAddCCGaid
submitYesVote_ (DRepVoter drepCred) secondAddCCGaid
passNEpochs 2
-- Confirm that they have been added
SJust committeeAfterRemoveAndAdd <-
Expand Down

0 comments on commit f18b579

Please sign in to comment.