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 54b2daf commit 6e296c2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 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,12 @@ dRepSpec =
assertBool "Gov action should be accepted" isAccepted
logAcceptedRatio gaidConstitutionProp
logRatificationChecks gaidConstitutionProp
constitutionShouldBe ""

let govStateConstitution =
getsNES $ nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . constitutionGovStateL
govStateConstitution `shouldReturn` initialConstitution
passEpoch
constitutionShouldBe "constitution.0"
getConstitution `shouldReturn` proposedConstitution
govStateConstitution `shouldReturn` proposedConstitution

treasurySpec ::
forall era.
Expand Down
16 changes: 14 additions & 2 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 @@ -230,9 +231,11 @@ instance
do
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 @@ -710,6 +714,14 @@ getLastEnactedCommittee = do
ps <- getProposals
pure $ ps ^. pRootsL . grCommitteeL . prRootL

getConstitution ::
ConwayEraImp era =>
ImpTestM era (Constitution era)
getConstitution = do
pulser <- getsNES newEpochStateDRepPulsingStateL
let ratifyState = extractDRepPulsingState pulser
pure $ ratifyState ^. rsEnactStateL . ensConstitutionL

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

0 comments on commit 6e296c2

Please sign in to comment.