Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucsanszky committed Sep 27, 2024
1 parent ddf4e38 commit da55054
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 25 deletions.
8 changes: 3 additions & 5 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,7 @@ import Cardano.Ledger.Shelley.LedgerState (
esLStateL,
lsCertState,
lsUTxOState,
lsUTxOStateL,
nesEsL,
utxosGovStateL,
newEpochStateGovStateL,
utxosStakeDistr,
vsCommitteeState,
vsDReps,
Expand Down Expand Up @@ -421,10 +419,10 @@ instance Crypto c => ConwayEraGov (ConwayEra c) where
newEpochStateDRepPulsingStateL ::
ConwayEraGov era => Lens' (NewEpochState era) (DRepPulsingState era)
newEpochStateDRepPulsingStateL =
nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . drepPulsingStateGovStateL
newEpochStateGovStateL . drepPulsingStateGovStateL

epochStateDRepPulsingStateL :: ConwayEraGov era => Lens' (EpochState era) (DRepPulsingState era)
epochStateDRepPulsingStateL = esLStateL . lsUTxOStateL . utxosGovStateL . drepPulsingStateGovStateL
epochStateDRepPulsingStateL = epochStateGovStateL . drepPulsingStateGovStateL

setCompleteDRepPulsingState ::
GovState era ~ ConwayGovState era =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,7 @@ votingSpec =
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 2
(drep, _, _) <- setupSingleDRep 1_000_000
(govActionId, _) <- submitConstitution SNothing
passEpoch
passEpoch
passEpoch
passNEpochs 3
submitFailingVote
(DRepVoter drep)
govActionId
Expand Down Expand Up @@ -1017,7 +1015,7 @@ constitutionSpec =
impAnn "Pulser has not changed" $
expectedPulser `shouldBe` initialPulser

passEpoch >> passEpoch
passNEpochs 2
impAnn "Proposal gets removed after expiry" $ do
govStateFinal <- getsNES newEpochStateGovStateL
let ratifyState = extractDRepPulsingState (govStateFinal ^. cgsDRepPulsingStateL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1530,14 +1530,14 @@ delayingActionsSpec =
expectMembers expKhs = do
committee <-
getsNES $
nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . committeeGovStateL
newEpochStateGovStateL . committeeGovStateL
let members = Map.keysSet $ foldMap' committeeMembers committee
impAnn "Expecting committee members" $ members `shouldBe` expKhs
(drep, _, _) <- setupSingleDRep 1_000_000
(spoC, _, _) <- setupPoolWithStake $ Coin 42_000_000
maxTermLength <-
getsNES $
nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . curPParamsGovStateL . ppCommitteeMaxTermLengthL
nesEsL . curPParamsEpochStateL . ppCommitteeMaxTermLengthL

hks <- registerInitialCommittee
initialMembers <- getCommitteeMembers
Expand Down
21 changes: 10 additions & 11 deletions eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/ImpTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ getEnactState :: ConwayEraGov era => ImpTestM era (EnactState era)
getEnactState = mkEnactState <$> getsNES (nesEsL . epochStateGovStateL)

getProposals :: ConwayEraGov era => ImpTestM era (Proposals era)
getProposals = getsNES $ nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . proposalsGovStateL
getProposals = getsNES $ newEpochStateGovStateL . proposalsGovStateL

logProposalsForest :: (ConwayEraGov era, HasCallStack) => ImpTestM era ()
logProposalsForest = do
Expand All @@ -894,7 +894,7 @@ getCommitteeMembers ::
ImpTestM era (Set.Set (Credential 'ColdCommitteeRole (EraCrypto era)))
getCommitteeMembers = do
committee <-
getsNES $ nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . committeeGovStateL
getsNES $ newEpochStateGovStateL . committeeGovStateL
pure $ Map.keysSet $ foldMap' committeeMembers committee

getLastEnactedCommittee ::
Expand All @@ -907,7 +907,7 @@ getConstitution ::
ConwayEraImp era =>
ImpTestM era (Constitution era)
getConstitution =
getsNES $ nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . constitutionGovStateL
getsNES $ newEpochStateGovStateL . constitutionGovStateL

getLastEnactedConstitution ::
ConwayEraGov era => ImpTestM era (StrictMaybe (GovPurposeId 'ConstitutionPurpose era))
Expand Down Expand Up @@ -1333,8 +1333,7 @@ electBasicCommittee = do
]
submitYesVote_ (DRepVoter drep) gaidCommitteeProp
submitYesVote_ (StakePoolVoter spoC) gaidCommitteeProp
passEpoch
passEpoch
passNEpochs 2
committeeMembers <- getCommitteeMembers
impAnn "The committee should be enacted" $
committeeMembers `shouldSatisfy` Set.member coldCommitteeC
Expand Down Expand Up @@ -1483,7 +1482,7 @@ enactConstitution prevGovId constitution dRep committeeMembers = impAnn "Enactin
passNEpochs 2
enactedConstitution <-
getsNES $
nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . constitutionGovStateL
newEpochStateGovStateL . constitutionGovStateL
enactedConstitution `shouldBe` constitution
pure govId

Expand All @@ -1493,7 +1492,7 @@ constitutionShouldBe :: (HasCallStack, ConwayEraGov era) => String -> ImpTestM e
constitutionShouldBe cUrl = do
Constitution {constitutionAnchor = Anchor {anchorUrl}} <-
getsNES $
nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . constitutionGovStateL
newEpochStateGovStateL . constitutionGovStateL
anchorUrl `shouldBe` errorFail (textToUrl 128 $ T.pack cUrl)

expectNumDormantEpochs :: HasCallStack => EpochNo -> ImpTestM era ()
Expand Down Expand Up @@ -1594,7 +1593,7 @@ currentProposalIds ::
ConwayEraGov era => ImpTestM era (SSeq.StrictSeq (GovActionId (EraCrypto era)))
currentProposalIds =
proposalsIds
<$> getsNES (nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . proposalsGovStateL)
<$> getsNES (newEpochStateGovStateL . proposalsGovStateL)

lastEpochProposals ::
forall era.
Expand Down Expand Up @@ -1662,7 +1661,7 @@ submitUpdateCommittee mParent ccsToRemove ccsToAdd threshold = do
let
curEpochNo = nes ^. nesELL
rootCommittee =
nes ^. nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . cgsProposalsL . pRootsL . grCommitteeL
nes ^. newEpochStateGovStateL . cgsProposalsL . pRootsL . grCommitteeL
parent = fromMaybe (prRoot rootCommittee) mParent
newCommitteMembers =
Map.fromList [(cc, addEpochInterval curEpochNo lifetime) | (cc, lifetime) <- ccsToAdd]
Expand All @@ -1672,15 +1671,15 @@ expectCommitteeMemberPresence ::
(HasCallStack, ConwayEraGov era) => Credential 'ColdCommitteeRole (EraCrypto era) -> ImpTestM era ()
expectCommitteeMemberPresence cc = do
SJust committee <-
getsNES $ nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . committeeGovStateL
getsNES $ newEpochStateGovStateL . committeeGovStateL
assertBool ("Expected Committee Member: " ++ show cc ++ " to be present in the committee") $
Map.member cc (committee ^. committeeMembersL)

expectCommitteeMemberAbsence ::
(HasCallStack, ConwayEraGov era) => Credential 'ColdCommitteeRole (EraCrypto era) -> ImpTestM era ()
expectCommitteeMemberAbsence cc = do
SJust committee <-
getsNES $ nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . committeeGovStateL
getsNES $ newEpochStateGovStateL . committeeGovStateL
assertBool ("Expected Committee Member: " ++ show cc ++ " to be absent from the committee") $
Map.notMember cc (committee ^. committeeMembersL)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,13 +642,13 @@ esNonMyopicL :: Lens' (EpochState era) (NonMyopic (EraCrypto era))
esNonMyopicL = lens esNonMyopic (\x y -> x {esNonMyopic = y})

curPParamsEpochStateL :: EraGov era => Lens' (EpochState era) (PParams era)
curPParamsEpochStateL = esLStateL . lsUTxOStateL . utxosGovStateL . curPParamsGovStateL
curPParamsEpochStateL = epochStateGovStateL . curPParamsGovStateL

prevPParamsEpochStateL :: EraGov era => Lens' (EpochState era) (PParams era)
prevPParamsEpochStateL = esLStateL . lsUTxOStateL . utxosGovStateL . prevPParamsGovStateL
prevPParamsEpochStateL = epochStateGovStateL . prevPParamsGovStateL

futurePParamsEpochStateL :: EraGov era => Lens' (EpochState era) (FuturePParams era)
futurePParamsEpochStateL = esLStateL . lsUTxOStateL . utxosGovStateL . futurePParamsGovStateL
futurePParamsEpochStateL = epochStateGovStateL . futurePParamsGovStateL

-- ==========================================
-- AccountState
Expand Down

0 comments on commit da55054

Please sign in to comment.