From ddf4e389f4c22f9c6e1f18f2964862be51c9cde8 Mon Sep 17 00:00:00 2001 From: Lucsanszky Date: Thu, 26 Sep 2024 05:30:27 +0200 Subject: [PATCH] Add bootstrap related SPO voting spec --- .../Cardano/Ledger/Conway/Imp/RatifySpec.hs | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/RatifySpec.hs b/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/RatifySpec.hs index 840f7c04b4b..14914eeee52 100644 --- a/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/RatifySpec.hs +++ b/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/RatifySpec.hs @@ -58,6 +58,7 @@ relevantDuringBootstrapSpec :: relevantDuringBootstrapSpec = do spoVotesForHardForkInitiation initiateHardForkWithLessThanMinimalCommitteeSize + spoVotingSpecWhenCCExpired it "Many CC Cold Credentials map to the same Hot Credential act as many votes" $ do hotCred NE.:| _ <- registerInitialCommittee (dRep, _, _) <- setupSingleDRep =<< uniformRM (10_000_000, 1_000_000_000) @@ -104,6 +105,77 @@ initiateHardForkWithLessThanMinimalCommitteeSize = passNEpochs 2 getLastEnactedHardForkInitiation `shouldReturn` SNothing +spoVotingSpecWhenCCExpired :: + forall era. + ConwayEraImp era => + SpecWith (ImpTestState era) +spoVotingSpecWhenCCExpired = do + describe "When CC expired" $ do + let setup = do + hotCs <- registerInitialCommittee + -- TODO: change the maxtermlength to make the test faster + EpochInterval committeeMaxTermLength <- + getsNES $ + nesEsL . curPParamsEpochStateL . ppCommitteeMaxTermLengthL + passNEpochs $ fromIntegral committeeMaxTermLength + ms <- getCommitteeMembers + -- Make sure that committee expired + forM_ ms ccShouldBeExpired + pure hotCs + it "SPOs alone can't enact hard-fork" $ do + hotCs <- setup + (spoC, _, _) <- setupPoolWithStake $ Coin 1_000_000_000 + protVer <- getProtVer + gai <- submitGovAction $ HardForkInitiation SNothing (majorFollow protVer) + submitYesVote_ (StakePoolVoter spoC) gai + -- CC members expired so their votes don't count - we are stuck! + submitYesVoteCCs_ hotCs gai + passNEpochs 2 + getLastEnactedHardForkInitiation `shouldReturn` SNothing + it "SPOs alone can't enact security group parameter change" $ do + void setup + (spoC, _, _) <- setupPoolWithStake $ Coin 1_000_000_000 + gid <- + submitParameterChange SNothing $ + emptyPParamsUpdate + & ppuMinFeeRefScriptCostPerByteL .~ SJust (25 %! 2) + submitYesVote_ (StakePoolVoter spoC) gid + passNEpochs 2 + getLastEnactedParameterChange `shouldReturn` SNothing + describe "When CC threshold is 0" $ do + let + modifyCommittee f = modifyNES $ \nes -> + nes + & newEpochStateGovStateL . committeeGovStateL %~ f + & newEpochStateDRepPulsingStateL %~ modifyDRepPulser + where + modifyDRepPulser pulser = + case finishDRepPulser pulser of + (snapshot, rState) -> DRComplete snapshot (rState & rsEnactStateL . ensCommitteeL %~ f) + it "SPOs alone can enact hard-fork during bootstrap" $ do + (spoC, _, _) <- setupPoolWithStake $ Coin 1_000_000_000 + protVer <- getProtVer + modifyCommittee $ fmap (\cc -> cc {committeeThreshold = 0 %! 1}) + gai <- submitGovAction $ HardForkInitiation SNothing (majorFollow protVer) + submitYesVote_ (StakePoolVoter spoC) gai + passNEpochs 2 + if bootstrapPhase protVer + then getLastEnactedHardForkInitiation `shouldReturn` SJust (GovPurposeId gai) + else getLastEnactedHardForkInitiation `shouldReturn` SNothing + it "SPOs alone can enact security group parameter change during bootstrap" $ do + (spoC, _, _) <- setupPoolWithStake $ Coin 1_000_000_000 + protVer <- getProtVer + modifyCommittee $ fmap (\cc -> cc {committeeThreshold = 0 %! 1}) + gai <- + submitParameterChange SNothing $ + emptyPParamsUpdate + & ppuMinFeeRefScriptCostPerByteL .~ SJust (25 %! 2) + submitYesVote_ (StakePoolVoter spoC) gai + passNEpochs 2 + if bootstrapPhase protVer + then getLastEnactedParameterChange `shouldReturn` SJust (GovPurposeId gai) + else getLastEnactedParameterChange `shouldReturn` SNothing + committeeExpiryResignationDiscountSpec :: forall era. ConwayEraImp era =>