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 6f637c5 commit 5f6e1c7
Show file tree
Hide file tree
Showing 10 changed files with 533 additions and 365 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
Utxos.relevantDuringBootstrapSpec @era
Utxo.spec @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,18 @@ spec ::
SpecWith (ImpTestState era)
spec =
describe "ENACT" $ do
relevantDuringBootstrapSpec
treasuryWithdrawalsSpec
hardForkInitiationSpec
noConfidenceSpec
constitutionSpec
actionPrioritySpec
actionPriorityCommitteePurposeSpec

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

treasuryWithdrawalsSpec ::
forall era.
Expand Down Expand Up @@ -323,12 +333,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,6 +368,12 @@ 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
Expand All @@ -371,11 +387,11 @@ actionPrioritySpec =
$ def & ppuDRepDepositL .~ SJust val1
pGai1 <-
submitParameterChange
(SJust $ GovPurposeId pGai0)
(SJust pGai0)
$ def & ppuDRepDepositL .~ SJust val2
pGai2 <-
submitParameterChange
(SJust $ GovPurposeId pGai1)
(SJust pGai1)
$ def & ppuDRepDepositL .~ SJust val3
traverse_ @[]
( \gaid -> do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}

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

import Cardano.Ledger.Address (RewardAccount (..))
import Cardano.Ledger.BaseTypes (EpochInterval (..), EpochNo (..))
Expand All @@ -33,7 +36,7 @@ import qualified Data.Set as Set
import Data.Tree
import Lens.Micro ((&), (.~))
import Test.Cardano.Ledger.Conway.ImpTest
import Test.Cardano.Ledger.Core.Rational (IsRatio (..))
import Test.Cardano.Ledger.Core.Rational (IsRatio (..), (%!))
import Test.Cardano.Ledger.Imp.Common

spec ::
Expand All @@ -46,10 +49,21 @@ spec ::
SpecWith (ImpTestState era)
spec =
describe "EPOCH" $ do
proposalsSpec
dRepSpec
relevantDuringBootstrapSpec
treasurySpec
eventsSpec

relevantDuringBootstrapSpec ::
forall era.
( ConwayEraImp era
, InjectRuleEvent "TICK" ConwayEpochEvent era
, Event (EraRule "EPOCH" era) ~ ConwayEpochEvent era
, Event (EraRule "NEWEPOCH" era) ~ ConwayNewEpochEvent era
) =>
SpecWith (ImpTestState era)
relevantDuringBootstrapSpec = do
proposalsSpec
dRepSpec
eventsSpec

proposalsSpec ::
forall era.
Expand All @@ -61,7 +75,7 @@ proposalsSpec =
-- + 2 epochs to pass to get the desired effect
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 4
_tree <-
submitConstitutionGovActionTree SNothing $
submitParameterChangeGovActionTree SNothing $
Node
()
[ Node
Expand All @@ -87,7 +101,7 @@ proposalsSpec =
& ppGovActionDepositL .~ deposit
rewardAccount <- registerRewardAccount

getRewardAccountAmount rewardAccount `shouldReturn` Coin 0
initialValue <- getsNES (nesEsL . curPParamsEpochStateL . ppMinFeeAL)

policy <-
getsNES $
Expand All @@ -97,7 +111,11 @@ proposalsSpec =
ProposalProcedure
{ pProcDeposit = deposit
, pProcReturnAddr = rewardAccount
, pProcGovAction = TreasuryWithdrawals [(rewardAccount, Coin 123_456_789)] policy
, pProcGovAction =
ParameterChange
SNothing
(def & ppuMinFeeAL .~ SJust (Coin 3000))
policy
, pProcAnchor = def
}
expectPresentGovActionId govActionId
Expand All @@ -106,6 +124,7 @@ proposalsSpec =
passEpoch
expectMissingGovActionId govActionId

getsNES (nesEsL . curPParamsEpochStateL . ppMinFeeAL) `shouldReturn` initialValue
getRewardAccountAmount rewardAccount `shouldReturn` deposit

dRepSpec ::
Expand All @@ -118,10 +137,12 @@ dRepSpec =
modifyPParams $ ppGovActionLifetimeL .~ EpochInterval 2
(drep, _, _) <- setupSingleDRep 1_000_000

let submitParamChangeProposal =
submitParameterChange SNothing $ def & ppuMinFeeAL .~ SJust (Coin 3000)
expectNumDormantEpochs 0

-- epoch 0
_ <- submitConstitution SNothing
_ <- submitParamChangeProposal
expectCurrentProposals
expectNoPulserProposals
expectNumDormantEpochs 0
Expand Down Expand Up @@ -162,7 +183,7 @@ dRepSpec =
expectNumDormantEpochs 2
expectExtraDRepExpiry drep 0

_ <- submitConstitution SNothing
_ <- submitParamChangeProposal
-- number of dormant epochs is added to the drep expiry and the reset
expectNumDormantEpochs 0
expectExtraDRepExpiry drep 2
Expand All @@ -180,39 +201,47 @@ dRepSpec =
logEntry "Stake distribution after DRep registration:"
logStakeDistr
passEpoch
it "constitution is accepted after two epochs" $ do
initialConstitution <- getConstitution
newAnchor <- arbitrary
let proposedConstitution = Constitution newAnchor SNothing
it "proposal is accepted after two epochs" $ do
modifyPParams $ \pp ->
pp
& ppDRepVotingThresholdsL
.~ def
{ dvtPPEconomicGroup = 1 %! 1
}
let getParamValue = getsNES (nesEsL . curPParamsEpochStateL . ppMinFeeAL)
initialParamValue <- getParamValue

let proposedValue = initialParamValue <+> Coin 300
let proposedUpdate = def & ppuMinFeeAL .~ SJust proposedValue

-- Submit NewConstitution proposal two epoch too early to check that the action
-- doesn't expire prematurely (ppGovActionLifetimeL is set to two epochs)
logEntry "Submitting new constitution"
gaidConstitutionProp <- submitGovAction $ NewConstitution SNothing proposedConstitution
logEntry "Submitting new minFee proposal"
gid <- submitParameterChange SNothing proposedUpdate

(committeeHotCred :| _) <- registerInitialCommittee
(dRepCred, _, _) <- setupSingleDRep 1_000_000
passEpoch
logRatificationChecks gaidConstitutionProp
logRatificationChecks gid
do
isAccepted <- isDRepAccepted gaidConstitutionProp
isAccepted <- isDRepAccepted gid
assertBool "Gov action should not be accepted" $ not isAccepted
submitYesVote_ (DRepVoter dRepCred) gaidConstitutionProp
submitYesVote_ (CommitteeVoter committeeHotCred) gaidConstitutionProp
logAcceptedRatio gaidConstitutionProp
submitYesVote_ (DRepVoter dRepCred) gid
submitYesVote_ (CommitteeVoter committeeHotCred) gid
logAcceptedRatio gid
do
isAccepted <- isDRepAccepted gaidConstitutionProp
isAccepted <- isDRepAccepted gid
assertBool "Gov action should be accepted" isAccepted

passEpoch
do
isAccepted <- isDRepAccepted gaidConstitutionProp
isAccepted <- isDRepAccepted gid
assertBool "Gov action should be accepted" isAccepted
logAcceptedRatio gaidConstitutionProp
logRatificationChecks gaidConstitutionProp
getConstitution `shouldReturn` initialConstitution
logAcceptedRatio gid
logRatificationChecks gid
getParamValue `shouldReturn` initialParamValue
passEpoch
getConstitution `shouldReturn` proposedConstitution
getParamValue `shouldReturn` proposedValue

treasurySpec ::
forall era.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}

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

import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Conway.Core (
Expand Down Expand Up @@ -60,9 +63,11 @@ spec ::
, InjectRuleFailure "LEDGER" ConwayGovCertPredFailure era
) =>
SpecWith (ImpTestState era)
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"
spec = do
relevantDuringBootstrapSpec
describe "GOVCERT"
$ it
"A CC that has resigned will need to be first voted out and then voted in to be considered active"
$ do
(drepCred, _, _) <- setupSingleDRep 1_000_000
passNEpochs 2
Expand Down Expand Up @@ -115,6 +120,14 @@ spec = describe "GOVCERT" $ do
-- Confirm that after registering a hot key, they are active
_hotKey <- registerCommitteeHotKey cc
ccShouldNotBeResigned cc

relevantDuringBootstrapSpec ::
forall era.
( ConwayEraImp era
, InjectRuleFailure "LEDGER" ConwayGovCertPredFailure era
) =>
SpecWith (ImpTestState era)
relevantDuringBootstrapSpec = do
describe "succeeds for" $ do
it "registering and unregistering a DRep" $ do
modifyPParams $ ppDRepDepositL .~ Coin 100
Expand Down

0 comments on commit 5f6e1c7

Please sign in to comment.