Skip to content

Commit

Permalink
Initialize Conway NewEpochState with an initial committee
Browse files Browse the repository at this point in the history
  • Loading branch information
teodanciu committed Apr 25, 2024
1 parent 736bf4d commit c44c04d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 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 `registerInitialCommittee` and `getCommitteeMembers` to Conway ImpTest
* Implement `ConwayUtxowPredFailure` instances:
* `Arbitrary`
* `ToExpr`
Expand Down
30 changes: 26 additions & 4 deletions eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/ImpTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ module Test.Cardano.Ledger.Conway.ImpTest (
isDRepAccepted,
isSpoAccepted,
isCommitteeAccepted,
getCommitteeMembers,
registerInitialCommittee,
logRatificationChecks,
resignCommitteeColdKey,
registerCommitteeHotKey,
Expand Down Expand Up @@ -108,7 +110,7 @@ import Cardano.Ledger.Allegra.Scripts (Timelock)
import Cardano.Ledger.Alonzo.Scripts (AlonzoScript)
import Cardano.Ledger.BaseTypes (
EpochInterval (..),
EpochNo,
EpochNo (..),
Network (..),
ProtVer (..),
ShelleyBase,
Expand Down Expand Up @@ -225,14 +227,17 @@ instance
) =>
ShelleyEraImp (ConwayEra c)
where
initImpTestState =
impNESL %= initConwayNES
initImpTestState = do
kh <- fst <$> freshKeyPairA$
let committee = Committee [(KeyHashObj kh, EpochNo 15)] (1 %! 1)
impNESL %= initConwayNES committee
where
initConwayNES nes =
initConwayNES committee nes =
let newNes =
(initAlonzoImpNES nes)
& nesEsL . curPParamsEpochStateL . ppDRepActivityL .~ EpochInterval 100
& nesEsL . curPParamsEpochStateL . ppGovActionLifetimeL .~ EpochInterval 30
& nesEsL . epochStateGovStateL . committeeGovStateL .~ SJust committee
epochState = newNes ^. nesEsL
ratifyState =
def
Expand Down Expand Up @@ -283,6 +288,15 @@ instance
) =>
ConwayEraImp (ConwayEra c)

registerInitialCommittee ::
(HasCallStack, ConwayEraImp era) =>
ImpTestM era (NonEmpty (Credential 'HotCommitteeRole (EraCrypto era)))
registerInitialCommittee = do
committeeMembers <- Set.toList <$> getCommitteeMembers
case committeeMembers of
x : xs -> traverse registerCommitteeHotKey $ x NE.:| xs
_ -> error "Expected an initial committee"

-- | Submit a transaction that registers a new DRep and return the keyhash
-- belonging to that DRep
registerDRep ::
Expand Down Expand Up @@ -671,6 +685,14 @@ logProposalsForest = do
proposals <- getProposals
logEntry $ proposalsShowDebug proposals True

getCommitteeMembers ::
ConwayEraImp era =>
ImpTestM era (Set.Set (Credential 'ColdCommitteeRole (EraCrypto era)))
getCommitteeMembers = do
committee <-
getsNES $ nesEsL . esLStateL . lsUTxOStateL . utxosGovStateL . committeeGovStateL
pure $ Map.keysSet $ foldMap' committeeMembers committee

getLastEnactedCommittee ::
ConwayEraGov era => ImpTestM era (StrictMaybe (GovPurposeId 'CommitteePurpose era))
getLastEnactedCommittee = do
Expand Down

0 comments on commit c44c04d

Please sign in to comment.