Skip to content

Commit

Permalink
Change imp initialization to set the the initialized state in MonadState
Browse files Browse the repository at this point in the history
  • Loading branch information
teodanciu committed Apr 25, 2024
1 parent a2d7a81 commit b031dd3
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 45 deletions.
2 changes: 1 addition & 1 deletion eras/allegra/impl/cardano-ledger-allegra.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ library
cardano-crypto-class,
cardano-ledger-binary ^>=1.3,
cardano-ledger-core ^>=1.12,
cardano-ledger-shelley ^>=1.10,
cardano-ledger-shelley ^>=1.11,
cardano-strict-containers,
cardano-slotting,
cborg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ instance
) =>
ShelleyEraImp (AllegraEra c)
where
initImpNES = initShelleyImpNES
initImpTestState = pure ()

impSatisfyNativeScript = impAllegraSatisfyNativeScript

Expand Down
4 changes: 2 additions & 2 deletions eras/alonzo/impl/cardano-ledger-alonzo.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ library
cardano-ledger-binary ^>=1.3,
cardano-ledger-core ^>=1.12,
cardano-ledger-mary ^>=1.6.0,
cardano-ledger-shelley ^>=1.10,
cardano-ledger-shelley ^>=1.11,
cardano-slotting,
cardano-strict-containers,
containers,
Expand Down Expand Up @@ -133,10 +133,10 @@ library testlib
cardano-ledger-core:{cardano-ledger-core, testlib},
cardano-strict-containers,
cardano-ledger-shelley:{cardano-ledger-shelley, testlib},
data-default-class,
plutus-ledger-api,
generic-random,
microlens,
microlens-mtl,
text,
tree-diff

Expand Down
12 changes: 5 additions & 7 deletions eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/ImpTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import Cardano.Ledger.Plutus.Language (
)
import Cardano.Ledger.Shelley.LedgerState (
NewEpochState,
StashedAVVMAddresses,
curPParamsEpochStateL,
esLStateL,
lsUTxOStateL,
Expand All @@ -68,14 +67,14 @@ import Cardano.Ledger.Shelley.LedgerState (
import Cardano.Ledger.Shelley.UTxO (EraUTxO (..), ScriptsProvided (..))
import Cardano.Ledger.TxIn (TxIn)
import Control.Monad (forM)
import Data.Default.Class (Default)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.MapExtras (fromElems)
import Data.Maybe (catMaybes)
import Data.Set (Set)
import qualified Data.Set as Set
import Lens.Micro
import Lens.Micro.Mtl ((%=))
import qualified PlutusLedgerApi.Common as P
import Test.Cardano.Ledger.Alonzo.TreeDiff ()
import Test.Cardano.Ledger.Core.Arbitrary ()
Expand All @@ -102,14 +101,13 @@ class
initAlonzoImpNES ::
forall era.
( AlonzoEraPParams era
, Default (StashedAVVMAddresses era)
, ShelleyEraImp era
, AlonzoEraScript era
) =>
NewEpochState era ->
NewEpochState era
initAlonzoImpNES =
initShelleyImpNES
& nesEsL . curPParamsEpochStateL %~ initPParams
initAlonzoImpNES nes =
nes & nesEsL . curPParamsEpochStateL %~ initPParams
where
initPParams pp =
pp
Expand Down Expand Up @@ -384,7 +382,7 @@ instance
) =>
ShelleyEraImp (AlonzoEra c)
where
initImpNES = initAlonzoImpNES
initImpTestState = impNESL %= initAlonzoImpNES
impSatisfyNativeScript = impAllegraSatisfyNativeScript
fixupTx = alonzoFixupTx

Expand Down
2 changes: 1 addition & 1 deletion eras/alonzo/test-suite/cardano-ledger-alonzo-test.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ library
cardano-ledger-binary:{cardano-ledger-binary, testlib} >=1.0,
cardano-ledger-core:{cardano-ledger-core, testlib} >=1.11 && <1.13,
cardano-ledger-allegra >=1.2,
cardano-ledger-shelley:{cardano-ledger-shelley, testlib} >=1.6 && <1.11,
cardano-ledger-shelley:{cardano-ledger-shelley, testlib} >=1.6 && <1.12,
cardano-ledger-shelley-test >=1.2,
cardano-ledger-shelley-ma-test ^>=1.2,
cardano-ledger-mary >=1.4,
Expand Down
3 changes: 2 additions & 1 deletion eras/babbage/impl/cardano-ledger-babbage.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ library
cardano-ledger-binary ^>=1.3,
cardano-ledger-core ^>=1.12,
cardano-ledger-mary ^>=1.6,
cardano-ledger-shelley ^>=1.10,
cardano-ledger-shelley ^>=1.11,
cardano-strict-containers,
containers,
deepseq,
Expand Down Expand Up @@ -117,6 +117,7 @@ library testlib
cardano-ledger-binary,
cardano-ledger-core:{cardano-ledger-core, testlib},
generic-random,
microlens-mtl,
small-steps >=1.1,
QuickCheck

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Cardano.Ledger.Babbage (BabbageEra)
import Cardano.Ledger.Core
import Cardano.Ledger.Crypto (Crypto (..))
import Cardano.Ledger.Plutus.Language (SLanguage (..))
import Lens.Micro.Mtl ((%=))
import Test.Cardano.Ledger.Alonzo.ImpTest
import Test.Cardano.Ledger.Babbage.TreeDiff ()
import Test.Cardano.Ledger.Common
Expand All @@ -30,7 +31,7 @@ instance
) =>
ShelleyEraImp (BabbageEra c)
where
initImpNES = initAlonzoImpNES
initImpTestState = impNESL %= initAlonzoImpNES
impSatisfyNativeScript = impAllegraSatisfyNativeScript
fixupTx = alonzoFixupTx

Expand Down
2 changes: 1 addition & 1 deletion eras/babbage/test-suite/cardano-ledger-babbage-test.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ library
cardano-ledger-shelley-ma-test >=1.1,
cardano-ledger-mary >=1.4,
cardano-ledger-shelley-test >=1.1,
cardano-ledger-shelley >=1.6 && <1.11,
cardano-ledger-shelley >=1.6 && <1.12,
cardano-strict-containers,
cardano-slotting,
containers,
Expand Down
3 changes: 2 additions & 1 deletion eras/conway/impl/cardano-ledger-conway.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ library
cardano-ledger-babbage ^>=1.8,
cardano-ledger-core ^>=1.12,
cardano-ledger-mary ^>=1.6,
cardano-ledger-shelley ^>=1.10,
cardano-ledger-shelley ^>=1.11,
cardano-slotting,
cardano-strict-containers,
containers,
Expand Down Expand Up @@ -157,6 +157,7 @@ library testlib
cardano-strict-containers,
data-default-class,
generic-random,
microlens-mtl,
mtl,
text,
small-steps >=1.1
Expand Down
24 changes: 14 additions & 10 deletions eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/ImpTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ import qualified Data.Text as T
import Data.Tree
import qualified GHC.Exts as GHC (fromList)
import Lens.Micro
import Lens.Micro.Mtl ((%=))
import Test.Cardano.Ledger.Babbage.ImpTest
import Test.Cardano.Ledger.Conway.Arbitrary ()
import Test.Cardano.Ledger.Conway.TreeDiff ()
Expand Down Expand Up @@ -224,16 +225,19 @@ instance
) =>
ShelleyEraImp (ConwayEra c)
where
initImpNES =
let nes =
initAlonzoImpNES
& nesEsL . curPParamsEpochStateL . ppDRepActivityL .~ EpochInterval 100
& nesEsL . curPParamsEpochStateL . ppGovActionLifetimeL .~ EpochInterval 30
epochState = nes ^. nesEsL
ratifyState =
def
& rsEnactStateL .~ mkEnactState (epochState ^. epochStateGovStateL)
in nes & nesEsL .~ setCompleteDRepPulsingState def ratifyState epochState
initImpTestState =
impNESL %= initConwayNES
where
initConwayNES nes =
let newNes =
(initAlonzoImpNES nes)
& nesEsL . curPParamsEpochStateL . ppDRepActivityL .~ EpochInterval 100
& nesEsL . curPParamsEpochStateL . ppGovActionLifetimeL .~ EpochInterval 30
epochState = newNes ^. nesEsL
ratifyState =
def
& rsEnactStateL .~ mkEnactState (epochState ^. epochStateGovStateL)
in newNes & nesEsL .~ setCompleteDRepPulsingState def ratifyState epochState

impSatisfyNativeScript = impAllegraSatisfyNativeScript

Expand Down
2 changes: 1 addition & 1 deletion eras/mary/impl/cardano-ledger-mary.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ library
cardano-ledger-allegra ^>=1.4.1,
cardano-ledger-binary ^>=1.3,
cardano-ledger-core ^>=1.12,
cardano-ledger-shelley ^>=1.10,
cardano-ledger-shelley ^>=1.11,
containers,
deepseq,
groups,
Expand Down
2 changes: 1 addition & 1 deletion eras/mary/impl/testlib/Test/Cardano/Ledger/Mary/ImpTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ instance
) =>
ShelleyEraImp (MaryEra c)
where
initImpNES = initShelleyImpNES
initImpTestState = pure ()
impSatisfyNativeScript = impAllegraSatisfyNativeScript
fixupTx = shelleyFixupTx

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: cardano-ledger-shelley-ma-test
version: 1.2.2.0
version: 1.2.2.1
license: Apache-2.0
maintainer: operations@iohk.io
author: IOHK
Expand Down Expand Up @@ -49,7 +49,7 @@ library
containers,
hashable,
cardano-ledger-shelley-test >=1.1,
cardano-ledger-shelley:{cardano-ledger-shelley, testlib} ^>=1.10,
cardano-ledger-shelley:{cardano-ledger-shelley, testlib} ^>=1.11,
cardano-strict-containers,
microlens,
mtl,
Expand Down
3 changes: 2 additions & 1 deletion eras/shelley/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Version history for `cardano-ledger-shelley`

## 1.10.1.0
## 1.11.0.0

*

### `testlib`

* Replace `initImpNES` with `initImpTestState` and change its return type to MonadState
* Add functions to Shelley `ImpTest`:
* `withFixup`
* `withCustomFixup`
Expand Down
2 changes: 1 addition & 1 deletion eras/shelley/impl/cardano-ledger-shelley.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: cardano-ledger-shelley
version: 1.10.1.0
version: 1.11.0.0
license: Apache-2.0
maintainer: operations@iohk.io
author: IOHK
Expand Down
22 changes: 11 additions & 11 deletions eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/ImpTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ module Test.Cardano.Ledger.Shelley.ImpTest (
withNoFixup,
withPostFixup,
withPreFixup,
-- We only export getters, because internal state should not be accessed during testing
impNESG,
impNESL,
impLastTickG,
impKeyPairsG,
impNativeScriptsG,
Expand Down Expand Up @@ -336,6 +336,7 @@ class
, Show (StashedAVVMAddresses era)
, ToExpr (StashedAVVMAddresses era)
, NFData (StashedAVVMAddresses era)
, Default (StashedAVVMAddresses era)
, -- For the LEDGER rule
STS (EraRule "LEDGER" era)
, BaseM (EraRule "LEDGER" era) ~ ShelleyBase
Expand Down Expand Up @@ -376,7 +377,8 @@ class
) =>
ShelleyEraImp era
where
initImpNES :: NewEpochState era
initImpTestState ::
(MonadState (ImpTestState era) m, MonadGen m) => m ()

-- | Try to find a sufficient number of KeyPairs that would satisfy a native script.
-- Whenever script can't be satisfied, Nothing is returned
Expand Down Expand Up @@ -439,11 +441,7 @@ testKeyHash :: Crypto c => KeyHash kd c
testKeyHash = mkKeyHash (-1)

initShelleyImpNES ::
forall era.
( Default (StashedAVVMAddresses era)
, ShelleyEraImp era
) =>
NewEpochState era
forall era. ShelleyEraImp era => NewEpochState era
initShelleyImpNES =
NewEpochState
{ stashedAVVMAddresses = def
Expand Down Expand Up @@ -514,7 +512,7 @@ instance
) =>
ShelleyEraImp (ShelleyEra c)
where
initImpNES = initShelleyImpNES
initImpTestState = pure ()

impSatisfyNativeScript providedVKeyHashes script = do
keyPairs <- gets impKeyPairs
Expand Down Expand Up @@ -1126,11 +1124,13 @@ withImpState ::
SpecWith (ImpTestState era) ->
Spec
withImpState =
beforeAll $ execImpTestM Nothing initImpTestState addRootTxOut
beforeAll $
execImpTestM Nothing impTestState0 $
addRootTxOut >> initImpTestState
where
initImpTestState =
impTestState0 =
ImpTestState
{ impNES = initImpNES
{ impNES = initShelleyImpNES
, impRootTxIn = rootTxIn
, impKeyPairs = mempty
, impByronKeyPairs = mempty
Expand Down
2 changes: 1 addition & 1 deletion eras/shelley/test-suite/cardano-ledger-shelley-test.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ library
cardano-ledger-binary:{cardano-ledger-binary, testlib} >=1.3,
cardano-ledger-byron,
cardano-ledger-core:{cardano-ledger-core, testlib} >=1.11 && <1.13,
cardano-ledger-shelley:{cardano-ledger-shelley, testlib} ^>=1.10,
cardano-ledger-shelley:{cardano-ledger-shelley, testlib} ^>=1.11,
cardano-protocol-tpraos:{cardano-protocol-tpraos, testlib} >=1.0.1,
cardano-slotting:{cardano-slotting, testlib},
cborg,
Expand Down
2 changes: 1 addition & 1 deletion libs/cardano-ledger-api/cardano-ledger-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ library
cardano-ledger-conway >=1.13 && <1.15,
cardano-ledger-core ^>=1.12,
cardano-ledger-mary >=1.5 && <1.7,
cardano-ledger-shelley ^>=1.10,
cardano-ledger-shelley ^>=1.11,
cardano-slotting,
containers,
FailT,
Expand Down

0 comments on commit b031dd3

Please sign in to comment.