Skip to content

Commit

Permalink
Adapt Imp tests to bootstrap check
Browse files Browse the repository at this point in the history
* separate tests that are relevant for bootstrap from those that are not
* run the former only with protocol version 9, and all of them with version 10
  • Loading branch information
teodanciu committed Apr 29, 2024
1 parent 819a198 commit e880aa5
Show file tree
Hide file tree
Showing 11 changed files with 634 additions and 453 deletions.
33 changes: 23 additions & 10 deletions eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import Cardano.Ledger.Alonzo.Plutus.Context (EraPlutusContext (..))
import Cardano.Ledger.Alonzo.Rules (AlonzoUtxosPredFailure)
import Cardano.Ledger.Babbage.Rules (BabbageUtxoPredFailure)
import Cardano.Ledger.Babbage.TxInfo (BabbageContextError)
import Cardano.Ledger.BaseTypes (Inject)
import Cardano.Ledger.BaseTypes (Inject, natVersion)
import Cardano.Ledger.Conway.Core
import Cardano.Ledger.Conway.Governance (ConwayGovState)
import Cardano.Ledger.Conway.PParams (ConwayPParams)
import Cardano.Ledger.Conway.Rules (
ConwayEpochEvent,
ConwayGovCertPredFailure,
Expand All @@ -23,6 +24,7 @@ import Cardano.Ledger.Conway.Rules (
)
import Cardano.Ledger.Conway.TxInfo (ConwayContextError)
import Cardano.Ledger.Shelley.Rules (Event, ShelleyUtxoPredFailure, ShelleyUtxowPredFailure)
import Data.Functor.Identity
import Data.Typeable (Typeable)
import qualified Test.Cardano.Ledger.Babbage.Imp as BabbageImp
import Test.Cardano.Ledger.Common
Expand All @@ -33,12 +35,13 @@ import qualified Test.Cardano.Ledger.Conway.Imp.GovSpec as Gov
import qualified Test.Cardano.Ledger.Conway.Imp.RatifySpec as Ratify
import qualified Test.Cardano.Ledger.Conway.Imp.UtxoSpec as Utxo
import qualified Test.Cardano.Ledger.Conway.Imp.UtxosSpec as Utxos
import Test.Cardano.Ledger.Conway.ImpTest (ConwayEraImp, withImpState)
import Test.Cardano.Ledger.Conway.ImpTest (ConwayEraImp, withImpState, withImpStateWithProtVer)

spec ::
forall era.
( ConwayEraImp era
, GovState era ~ ConwayGovState era
, PParamsHKD Identity era ~ ConwayPParams Identity era
, InjectRuleFailure "LEDGER" ConwayGovPredFailure era
, Inject (BabbageContextError era) (ContextError era)
, Inject (ConwayContextError era) (ContextError era)
Expand All @@ -58,11 +61,21 @@ spec ::
Spec
spec = do
BabbageImp.spec @era
describe "ConwayImpSpec" $ withImpState @era $ do
Enact.spec @era
Epoch.spec @era
Gov.spec @era
GovCert.spec @era
Utxo.spec @era
Utxos.spec @era
Ratify.spec @era
describe "ConwayImpSpec - post bootstrap (protocol version 10)" $
withImpStateWithProtVer @era (natVersion @10) $ do
Enact.spec @era
Epoch.spec @era
Gov.spec @era
GovCert.spec @era
Utxo.spec @era
Utxos.spec @era
Ratify.spec @era
describe "ConwayImpSpec - bootstrap phase (protocol version 9)" $
withImpState @era $ do
Enact.relevantDuringBootstrapSpec @era
Epoch.relevantDuringBootstrapSpec @era
Gov.relevantDuringBootstrapSpec @era
GovCert.relevantDuringBootstrapSpec @era
Utxo.spec @era
Utxos.relevantDuringBootstrapSpec @era
Ratify.relevantDuringBootstrapSpec @era
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}

module Test.Cardano.Ledger.Conway.Imp.EnactSpec (spec) where
module Test.Cardano.Ledger.Conway.Imp.EnactSpec (
spec,
relevantDuringBootstrapSpec,
) where

import Cardano.Ledger.Address
import Cardano.Ledger.BaseTypes
Expand Down Expand Up @@ -47,11 +50,19 @@ spec ::
SpecWith (ImpTestState era)
spec =
describe "ENACT" $ do
relevantDuringBootstrapSpec
treasuryWithdrawalsSpec
hardForkInitiationSpec
noConfidenceSpec
constitutionSpec
actionPrioritySpec
actionPriorityCommitteePurposeSpec
hardForkInitiationSpec

relevantDuringBootstrapSpec ::
ConwayEraImp era =>
SpecWith (ImpTestState era)
relevantDuringBootstrapSpec = do
actionPrioritySpec
hardForkInitiationNoDRepsSpec

treasuryWithdrawalsSpec ::
forall era.
Expand Down Expand Up @@ -189,27 +200,49 @@ hardForkInitiationSpec =
pp
& ppDRepVotingThresholdsL . dvtHardForkInitiationL .~ 2 %! 3
& ppPoolVotingThresholdsL . pvtHardForkInitiationL .~ 2 %! 3
& ppGovActionLifetimeL .~ EpochInterval 20
_ <- setupPoolWithStake $ Coin 22_000_000
(stakePoolId1, _, _) <- setupPoolWithStake $ Coin 22_000_000
(stakePoolId2, _, _) <- setupPoolWithStake $ Coin 22_000_000
(dRep1, _, _) <- setupSingleDRep 11_000_000
(dRep2, _, _) <- setupSingleDRep 11_000_000
curProtVer <- getsNES $ nesEsL . curPParamsEpochStateL . ppProtocolVersionL
curProtVer <- getProtVer
nextMajorVersion <- succVersion $ pvMajor curProtVer
let nextProtVer = curProtVer {pvMajor = nextMajorVersion}
govActionId <- submitGovAction $ HardForkInitiation SNothing nextProtVer
submitYesVote_ (CommitteeVoter committeeMember) govActionId
submitYesVote_ (DRepVoter dRep1) govActionId
submitYesVote_ (StakePoolVoter stakePoolId1) govActionId
passNEpochs 2
getsNES (nesEsL . curPParamsEpochStateL . ppProtocolVersionL) `shouldReturn` curProtVer
getProtVer `shouldReturn` curProtVer
submitYesVote_ (DRepVoter dRep2) govActionId
passNEpochs 2
getsNES (nesEsL . curPParamsEpochStateL . ppProtocolVersionL) `shouldReturn` curProtVer
getProtVer `shouldReturn` curProtVer
submitYesVote_ (StakePoolVoter stakePoolId2) govActionId
passNEpochs 2
getsNES (nesEsL . curPParamsEpochStateL . ppProtocolVersionL) `shouldReturn` nextProtVer
getProtVer `shouldReturn` nextProtVer

hardForkInitiationNoDRepsSpec :: ConwayEraImp era => SpecWith (ImpTestState era)
hardForkInitiationNoDRepsSpec =
it "HardForkInitiation without DRep voting" $ do
(committeeMember :| _) <- registerInitialCommittee
modifyPParams $ \pp ->
pp
& ppDRepVotingThresholdsL . dvtHardForkInitiationL .~ def
& ppPoolVotingThresholdsL . pvtHardForkInitiationL .~ 2 %! 3
_ <- setupPoolWithStake $ Coin 22_000_000
(stakePoolId1, _, _) <- setupPoolWithStake $ Coin 22_000_000
(stakePoolId2, _, _) <- setupPoolWithStake $ Coin 22_000_000
curProtVer <- getProtVer
nextMajorVersion <- succVersion $ pvMajor curProtVer
let nextProtVer = curProtVer {pvMajor = nextMajorVersion}
govActionId <- submitGovAction $ HardForkInitiation SNothing nextProtVer
submitYesVote_ (CommitteeVoter committeeMember) govActionId
submitYesVote_ (StakePoolVoter stakePoolId1) govActionId
passNEpochs 2
getProtVer `shouldReturn` curProtVer
submitYesVote_ (StakePoolVoter stakePoolId2) govActionId
passNEpochs 2
getProtVer `shouldReturn` nextProtVer

noConfidenceSpec :: forall era. ConwayEraImp era => SpecWith (ImpTestState era)
noConfidenceSpec =
Expand Down Expand Up @@ -323,12 +356,12 @@ constitutionSpec =
enactState <- getEnactState
rsEnactState pulserRatifyState `shouldBe` enactState

actionPrioritySpec ::
actionPriorityCommitteePurposeSpec ::
forall era.
ConwayEraImp era =>
SpecWith (ImpTestState era)
actionPrioritySpec =
describe "Competing proposals ratified in the same epoch" $ do
actionPriorityCommitteePurposeSpec =
describe "Competing proposals with different priorities" $ do
it
"higher action priority wins"
$ do
Expand Down Expand Up @@ -358,64 +391,79 @@ actionPrioritySpec =
nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . committeeGovStateL
committee `shouldBe` SNothing

actionPrioritySpec ::
forall era.
ConwayEraImp era =>
SpecWith (ImpTestState era)
actionPrioritySpec =
describe "Competing proposals ratified in the same epoch" $ do
let val1 = Coin 1_000_001
let val2 = Coin 1_000_002
let val3 = Coin 1_000_003

it "proposals of same priority are enacted in order of submission" $ do
modifyPParams $ \pp ->
pp
& ppDRepVotingThresholdsL . dvtPPEconomicGroupL .~ def
& ppPoolVotingThresholdsL . pvtPPSecurityGroupL .~ 1 %! 1

(committeeC :| _) <- registerInitialCommittee
(drepC, _, _) <- setupSingleDRep 1_000_000
(spoC, _, _) <- setupPoolWithStake $ Coin 42_000_000
pGai0 <-
submitParameterChange
SNothing
$ def & ppuDRepDepositL .~ SJust val1
$ def & ppuMinFeeAL .~ SJust val1
pGai1 <-
submitParameterChange
(SJust $ GovPurposeId pGai0)
$ def & ppuDRepDepositL .~ SJust val2
(SJust pGai0)
$ def & ppuMinFeeAL .~ SJust val2
pGai2 <-
submitParameterChange
(SJust $ GovPurposeId pGai1)
$ def & ppuDRepDepositL .~ SJust val3
(SJust pGai1)
$ def & ppuMinFeeAL .~ SJust val3
traverse_ @[]
( \gaid -> do
submitYesVote_ (DRepVoter drepC) gaid
submitYesVote_ (StakePoolVoter spoC) gaid
submitYesVote_ (CommitteeVoter committeeC) gaid
)
[pGai0, pGai1, pGai2]
passNEpochs 2
getLastEnactedParameterChange
`shouldReturn` SJust (GovPurposeId pGai2)
expectNoCurrentProposals
getsNES (nesEsL . curPParamsEpochStateL . ppDRepDepositL)
getsNES (nesEsL . curPParamsEpochStateL . ppMinFeeAL)
`shouldReturn` val3

it "only the first action of a transaction gets enacted" $ do
modifyPParams $ \pp ->
pp
& ppDRepVotingThresholdsL . dvtPPEconomicGroupL .~ def
& ppPoolVotingThresholdsL . pvtPPSecurityGroupL .~ 1 %! 1
(committeeC :| _) <- registerInitialCommittee
(drepC, _, _) <- setupSingleDRep 1_000_000
(spoC, _, _) <- setupPoolWithStake $ Coin 42_000_000
gaids <-
submitGovActions $
NE.fromList
[ ParameterChange
SNothing
(def & ppuDRepDepositL .~ SJust val1)
(def & ppuMinFeeAL .~ SJust val1)
SNothing
, ParameterChange
SNothing
(def & ppuDRepDepositL .~ SJust val2)
(def & ppuMinFeeAL .~ SJust val2)
SNothing
, ParameterChange
SNothing
(def & ppuDRepDepositL .~ SJust val3)
(def & ppuMinFeeAL .~ SJust val3)
SNothing
]
traverse_
( \gaid -> do
submitYesVote_ (DRepVoter drepC) gaid
submitYesVote_ (StakePoolVoter spoC) gaid
submitYesVote_ (CommitteeVoter committeeC) gaid
)
gaids
passNEpochs 2
getsNES (nesEsL . curPParamsEpochStateL . ppDRepDepositL)
getsNES (nesEsL . curPParamsEpochStateL . ppMinFeeAL)
`shouldReturn` val1
expectNoCurrentProposals

0 comments on commit e880aa5

Please sign in to comment.