Skip to content

Commit

Permalink
Add initial constitution in conway ImpTestState initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
teodanciu committed Apr 25, 2024
1 parent 5d5b461 commit e174283
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 30 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`

* Add `getConstitution` to Conway ImpTest
* Change return type of `setupSingleDRep` to Credential instead of KeyHash
* Add `registerInitialCommittee` and `getCommitteeMembers` to Conway ImpTest
* Implement `ConwayUtxowPredFailure` instances:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ constitutionSpec =
(committeeMember :| _) <- registerInitialCommittee
(dRep, _, _) <- setupSingleDRep 1_000_000
(govActionId, constitution) <- submitConstitution SNothing
initialConstitution <- getConstitution

proposalsBeforeVotes <- getsNES $ newEpochStateGovStateL . proposalsGovStateL
pulserBeforeVotes <- getsNES newEpochStateDRepPulsingStateL
Expand Down Expand Up @@ -312,7 +313,7 @@ constitutionSpec =

impAnn "New constitution is not enacted after one epoch" $ do
constitutionAfterOneEpoch <- getsNES $ newEpochStateGovStateL . constitutionGovStateL
constitutionAfterOneEpoch `shouldBe` def
constitutionAfterOneEpoch `shouldBe` initialConstitution

impAnn "Pulser should reflect the constitution to be enacted" $ do
pulser <- getsNES newEpochStateDRepPulsingStateL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,13 @@
module Test.Cardano.Ledger.Conway.Imp.EpochSpec (spec) where

import Cardano.Ledger.Address (RewardAccount (..))
import Cardano.Ledger.BaseTypes (EpochInterval (..), EpochNo (..), textToUrl)
import Cardano.Ledger.BaseTypes (EpochInterval (..), EpochNo (..))
import Cardano.Ledger.Coin
import Cardano.Ledger.Conway.Core
import Cardano.Ledger.Conway.Governance
import Cardano.Ledger.Conway.Rules (ConwayEpochEvent (GovInfoEvent), ConwayNewEpochEvent (..))
import Cardano.Ledger.Credential (Credential (..))
import Cardano.Ledger.Shelley.LedgerState (
asTreasuryL,
curPParamsEpochStateL,
epochStateGovStateL,
esAccountStateL,
nesEpochStateL,
nesEsL,
)
import Cardano.Ledger.Shelley.LedgerState
import Cardano.Ledger.Shelley.Rules (Event, ShelleyTickEvent (..))
import Cardano.Ledger.Val
import Control.Monad.Writer (listen)
Expand All @@ -34,7 +27,6 @@ import Data.Default.Class (Default (..))
import Data.List.NonEmpty (NonEmpty (..))
import qualified Data.List.NonEmpty as NE
import qualified Data.Map.Strict as Map
import Data.Maybe (fromJust)
import Data.Maybe.Strict (StrictMaybe (..))
import qualified Data.Sequence.Strict as SSeq
import qualified Data.Set as Set
Expand Down Expand Up @@ -189,22 +181,14 @@ dRepSpec =
logStakeDistr
passEpoch
it "constitution is accepted after two epochs" $ do
constitutionHash <- freshSafeHash
let
constitutionAction =
NewConstitution
SNothing
( Constitution
( Anchor
(fromJust $ textToUrl 64 "constitution.0")
constitutionHash
)
SNothing
)
initialConstitution <- getConstitution
newAnchor <- arbitrary
let proposedConstitution = Constitution newAnchor SNothing

-- 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 constitutionAction
gaidConstitutionProp <- submitGovAction $ NewConstitution SNothing proposedConstitution

(committeeHotCred :| _) <- registerInitialCommittee
(dRepCred, _, _) <- setupSingleDRep 1_000_000
Expand All @@ -226,10 +210,9 @@ dRepSpec =
assertBool "Gov action should be accepted" isAccepted
logAcceptedRatio gaidConstitutionProp
logRatificationChecks gaidConstitutionProp
constitutionShouldBe ""

getConstitution `shouldReturn` initialConstitution
passEpoch
constitutionShouldBe "constitution.0"
getConstitution `shouldReturn` proposedConstitution

treasurySpec ::
forall era.
Expand Down
16 changes: 13 additions & 3 deletions eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/ImpTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module Test.Cardano.Ledger.Conway.ImpTest (
isSpoAccepted,
isCommitteeAccepted,
getCommitteeMembers,
getConstitution,
registerInitialCommittee,
logRatificationChecks,
resignCommitteeColdKey,
Expand Down Expand Up @@ -227,11 +228,13 @@ instance
ShelleyEraImp (ConwayEra c)
where
initImpTestState = do
kh <- fst <$> freshKeyPairA$
kh <- fst <$> freshKeyPair
let committee = Committee [(KeyHashObj kh, EpochNo 15)] (1 %! 1)
impNESL %= initConwayNES committee
anchor <- arbitrary
let constitution = Constitution anchor SNothing
impNESL %= initConwayNES committee constitution
where
initConwayNES committee nes =
initConwayNES committee constitution nes =
let newNes =
(initAlonzoImpNES nes)
& nesEsL . curPParamsEpochStateL . ppDRepActivityL .~ EpochInterval 100
Expand All @@ -248,6 +251,7 @@ instance
}
)
& nesEsL . epochStateGovStateL . committeeGovStateL .~ SJust committee
& nesEsL . epochStateGovStateL . constitutionGovStateL .~ constitution
epochState = newNes ^. nesEsL
ratifyState =
def
Expand Down Expand Up @@ -709,6 +713,12 @@ getLastEnactedCommittee = do
ps <- getProposals
pure $ ps ^. pRootsL . grCommitteeL . prRootL

getConstitution ::
ConwayEraImp era =>
ImpTestM era (Constitution era)
getConstitution =
getsNES $ nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . constitutionGovStateL

getLastEnactedConstitution ::
ConwayEraGov era => ImpTestM era (StrictMaybe (GovPurposeId 'ConstitutionPurpose era))
getLastEnactedConstitution = do
Expand Down

0 comments on commit e174283

Please sign in to comment.