Skip to content

Commit

Permalink
Add function to support running conway tests with any protocol version
Browse files Browse the repository at this point in the history
  • Loading branch information
teodanciu committed Apr 29, 2024
1 parent 0bd0e85 commit b7d5fef
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
3 changes: 2 additions & 1 deletion eras/conway/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@

### `testlib`

* Add `withImpStateWithProtVer` to Conway ImpTest
* Add the following utilities. #4273
* to `Conway.ImpTest`
* `setupDRepWithoutStake`
* `setupPoolWithoutStake`
* `setupPoolWithoutStake`
* `submitAndExpireProposalToMakeReward`
* to `Shelley.ImpTest`
* `getRewardAccountFor`
Expand Down
19 changes: 19 additions & 0 deletions eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/ImpTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ module Test.Cardano.Ledger.Conway.ImpTest (
getsPParams,
currentProposalsShouldContain,
setupDRepWithoutStake,
withImpStateWithProtVer,
) where

import Cardano.Crypto.DSIGN (DSIGNAlgorithm (..), Ed25519DSIGN, Signable)
Expand All @@ -119,6 +120,7 @@ import Cardano.Ledger.BaseTypes (
ProtVer (..),
ShelleyBase,
StrictMaybe (..),
Version,
addEpochInterval,
inject,
succVersion,
Expand All @@ -133,6 +135,7 @@ import Cardano.Ledger.Coin (Coin (..))
import Cardano.Ledger.Conway (ConwayEra)
import Cardano.Ledger.Conway.Core hiding (proposals)
import Cardano.Ledger.Conway.Governance
import Cardano.Ledger.Conway.PParams (ConwayPParams (..))
import Cardano.Ledger.Conway.Rules (
ConwayGovEvent,
EnactSignal,
Expand Down Expand Up @@ -220,6 +223,22 @@ conwayModifyPParams f = modifyNES $ \nes ->
(snapshot, ratifyState) ->
DRComplete snapshot (ratifyState & rsEnactStateL . ensCurPParamsL %~ f)

withImpStateWithProtVer ::
forall era.
( ConwayEraImp era
, GovState era ~ ConwayGovState era
, PParamsHKD Identity era ~ ConwayPParams Identity era
) =>
Version ->
SpecWith (ImpTestState era) ->
Spec
withImpStateWithProtVer ver = do
withImpStateModified $
impNESL . nesEsL . esLStateL . lsUTxOStateL . (utxosGovStateL @era) . cgsCurPParamsL
%~ ( \(PParams pp) ->
PParams (pp {cppProtocolVersion = ProtVer ver 0})
)

instance
( Crypto c
, NFData (SigDSIGN (DSIGN c))
Expand Down
13 changes: 10 additions & 3 deletions eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/ImpTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ module Test.Cardano.Ledger.Shelley.ImpTest (
registerAndRetirePoolToMakeReward,
getRewardAccountAmount,
withImpState,
withImpStateModified,
shelleyFixupTx,
lookupImpRootTxOut,
sendValueTo,
Expand Down Expand Up @@ -1106,13 +1107,19 @@ logToExpr :: (HasCallStack, ToExpr a) => a -> ImpTestM era ()
logToExpr e = logEntry (showExpr e)

withImpState ::
forall era.
ShelleyEraImp era =>
SpecWith (ImpTestState era) ->
Spec
withImpState =
withImpState = withImpStateModified id

withImpStateModified ::
ShelleyEraImp era =>
(ImpTestState era -> ImpTestState era) ->
SpecWith (ImpTestState era) ->
Spec
withImpStateModified f =
beforeAll $
execImpTestM Nothing impTestState0 $
execImpTestM Nothing (f impTestState0) $
addRootTxOut >> initImpTestState
where
impTestState0 =
Expand Down

0 comments on commit b7d5fef

Please sign in to comment.