Skip to content

Commit

Permalink
Merge pull request #4745 from IntersectMBO/lehins/ImpSpec
Browse files Browse the repository at this point in the history
Extract `ImpSpec` into its own package
  • Loading branch information
lehins authored Nov 14, 2024
2 parents 81a39af + bfa6dfe commit 14a4713
Show file tree
Hide file tree
Showing 68 changed files with 1,194 additions and 894 deletions.
1 change: 1 addition & 0 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ jobs:
- set-algebra
- small-steps
- vector-map
- ImpSpec
ghc: ["8.10.7", "9.2.8", "9.6.6", "9.8.2", "9.10.1"]
os: [ubuntu-latest]
fail-fast: false
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
**/*-blx.bib
**/*.run.xml

## Cabal & Stack
## Cabal & Stack (we no longer use stack)
stack.yaml
.stack-work*/
.stack-work-local/
*/dist
Expand Down
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ packages:
libs/cardano-data
libs/set-algebra
libs/vector-map
libs/ImpSpec

-- == Byron era ==
-- byron-spec-chain:
Expand Down
4 changes: 4 additions & 0 deletions eras/allegra/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

* Use `Mismatch` to clarify predicate failures. #4711

### `testlib`

* Switch to using `ImpSpec` package

## 1.6.0.1

*
Expand Down
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 @@ -64,7 +64,7 @@ library
bytestring,
cardano-crypto-class,
cardano-ledger-binary >=1.4,
cardano-ledger-core >=1.15 && <1.17,
cardano-ledger-core >=1.16 && <1.17,
cardano-ledger-shelley ^>=1.15,
cardano-strict-containers,
cardano-slotting,
Expand Down
4 changes: 2 additions & 2 deletions eras/allegra/impl/testlib/Test/Cardano/Ledger/Allegra/Imp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Test.Cardano.Ledger.Allegra.Imp (spec) where
import Cardano.Ledger.Core
import Cardano.Ledger.Shelley.Rules (ShelleyUtxoPredFailure, ShelleyUtxowPredFailure)
import qualified Test.Cardano.Ledger.Allegra.Imp.UtxowSpec as UtxowSpec
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Imp.Common
import qualified Test.Cardano.Ledger.Shelley.Imp as ShelleyImp
import Test.Cardano.Ledger.Shelley.ImpTest

Expand All @@ -24,5 +24,5 @@ spec ::
Spec
spec = do
ShelleyImp.spec @era
describe "AllegraImpSpec" . withImpState @era $ do
describe "AllegraImpSpec" . withImpInit @(LedgerSpec era) $ do
UtxowSpec.spec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec ::
( ShelleyEraImp era
, InjectRuleFailure "LEDGER" ShelleyUtxowPredFailure era
) =>
SpecWith (ImpTestState era)
SpecWith (ImpInit (LedgerSpec era))
spec = describe "UTXOW" $ do
it "InvalidMetadata" $ do
invalidMetadatum <- genInvalidMetadata
Expand Down
1 change: 1 addition & 0 deletions eras/alonzo/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

### `testlib`

* Switch to using `ImpSpec` package
* Rename `expectPhase2Invalid` to `submitPhase2Invalid_`
* Add `submitPhase2Invalid`
* Add `expectTxSuccess`
Expand Down
12 changes: 6 additions & 6 deletions eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Imp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import Cardano.Ledger.Shelley.Rules (ShelleyUtxoPredFailure, ShelleyUtxowPredFai
import qualified Test.Cardano.Ledger.Alonzo.Imp.UtxoSpec as Utxo
import qualified Test.Cardano.Ledger.Alonzo.Imp.UtxosSpec as Utxos
import qualified Test.Cardano.Ledger.Alonzo.Imp.UtxowSpec as Utxow
import Test.Cardano.Ledger.Alonzo.ImpTest (AlonzoEraImp, withImpState)
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Alonzo.ImpTest (AlonzoEraImp, LedgerSpec)
import Test.Cardano.Ledger.Imp.Common
import qualified Test.Cardano.Ledger.Mary.Imp as MaryImp

spec ::
Expand All @@ -34,7 +34,7 @@ spec ::
Spec
spec = do
MaryImp.spec @era
describe "AlonzoImpSpec" . withImpState @era $ do
Utxo.spec @era
Utxos.spec @era
Utxow.spec @era
describe "AlonzoImpSpec" . withImpInit @(LedgerSpec era) $ do
Utxo.spec
Utxos.spec
Utxow.spec
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec ::
( AlonzoEraImp era
, InjectRuleFailure "LEDGER" AlonzoUtxoPredFailure era
) =>
SpecWith (ImpTestState era)
SpecWith (ImpInit (LedgerSpec era))
spec = describe "UTXO" $ do
it "Wrong network ID" $ do
submitFailingTx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ spec ::
( AlonzoEraImp era
, InjectRuleFailure "LEDGER" AlonzoUtxosPredFailure era
) =>
SpecWith (ImpTestState era)
SpecWith (ImpInit (LedgerSpec era))
spec = describe "UTXOS" $
forM_ (eraLanguages @era) $ \lang ->
withSLanguage lang $ \slang ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Cardano.Ledger.Alonzo.Rules (
import Cardano.Ledger.Shelley.Rules (ShelleyUtxowPredFailure)
import qualified Test.Cardano.Ledger.Alonzo.Imp.UtxowSpec.Invalid as Invalid
import qualified Test.Cardano.Ledger.Alonzo.Imp.UtxowSpec.Valid as Valid
import Test.Cardano.Ledger.Alonzo.ImpTest (AlonzoEraImp, ImpTestState)
import Test.Cardano.Ledger.Alonzo.ImpTest
import Test.Cardano.Ledger.Common

spec ::
Expand All @@ -27,8 +27,8 @@ spec ::
, InjectRuleFailure "LEDGER" AlonzoUtxosPredFailure era
, InjectRuleFailure "LEDGER" AlonzoUtxowPredFailure era
) =>
SpecWith (ImpTestState era)
SpecWith (ImpInit (LedgerSpec era))
spec = do
describe "UTXOW PredicateFailures" $ do
describe "UTXOW" $ do
Valid.spec
Invalid.spec
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ spec ::
, InjectRuleFailure "LEDGER" AlonzoUtxosPredFailure era
, InjectRuleFailure "LEDGER" AlonzoUtxowPredFailure era
) =>
SpecWith (ImpTestState era)
SpecWith (ImpInit (LedgerSpec era))
spec = describe "Invalid transactions" $ do
it "Phase 1 script failure" $ do
-- Script will be invalid because slot 100 will be in the future
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ spec ::
( AlonzoEraImp era
, InjectRuleFailure "LEDGER" AlonzoUtxosPredFailure era
) =>
SpecWith (ImpTestState era)
SpecWith (ImpInit (LedgerSpec era))
spec = describe "Valid transactions" $ do
forM_ (eraLanguages @era) $ \lang ->
withSLanguage lang $ \slang ->
Expand Down
4 changes: 4 additions & 0 deletions eras/babbage/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

* Use `Mismatch` to clarify predicate failures. #4711

### `testlib`

* Switch to using `ImpSpec` package

## 1.10.0.0

* Add `ProtVer` argument to `TxInfo` functions:
Expand Down
2 changes: 1 addition & 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-allegra ^>=1.6.1,
cardano-ledger-alonzo >=1.12,
cardano-ledger-binary >=1.4,
cardano-ledger-core >=1.15 && <1.17,
cardano-ledger-core >=1.16 && <1.17,
cardano-ledger-mary ^>=1.7,
cardano-ledger-shelley ^>=1.15,
cardano-strict-containers,
Expand Down
8 changes: 4 additions & 4 deletions eras/babbage/impl/testlib/Test/Cardano/Ledger/Babbage/Imp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import Cardano.Ledger.Babbage.TxInfo (BabbageContextError)
import Cardano.Ledger.BaseTypes (Inject)
import Cardano.Ledger.Shelley.Rules (ShelleyUtxoPredFailure, ShelleyUtxowPredFailure)
import qualified Test.Cardano.Ledger.Alonzo.Imp as AlonzoImp
import Test.Cardano.Ledger.Alonzo.ImpTest (AlonzoEraImp, withImpState)
import Test.Cardano.Ledger.Alonzo.ImpTest (AlonzoEraImp, LedgerSpec)
import qualified Test.Cardano.Ledger.Babbage.Imp.UtxowSpec as Utxow
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Imp.Common

spec ::
forall era.
Expand All @@ -39,5 +39,5 @@ spec ::
Spec
spec = do
AlonzoImp.spec @era
describe "BabbageImpSpec" . withImpState @era $ do
Utxow.spec @era
describe "BabbageImpSpec" . withImpInit @(LedgerSpec era) $ do
Utxow.spec
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ spec ::
, InjectRuleFailure "LEDGER" AlonzoUtxowPredFailure era
, Inject (BabbageContextError era) (ContextError era)
) =>
SpecWith (ImpTestState era)
SpecWith (ImpInit (LedgerSpec era))
spec = describe "UTXOW" $ do
it "MalformedScriptWitnesses" $ do
let scriptHash = hashPlutusScript (malformedPlutus @'PlutusV2)
Expand Down
2 changes: 2 additions & 0 deletions eras/conway/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### `testlib`

* Switch to using `ImpSpec` package
* Remove `withImpStateWithProtVer`
* Added `delegateSPORewardAddressToDRep_`
* Add `mkUpdateCommitteeProposal`
* Add `SubmitFailureExpectation`, `FailBoth`, `submitBootstrapAwareFailingVote`, `submitBootstrapAwareFailingProposal`, `submitBootstrapAwareFailingProposal_`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ spec = describe "Regression" $ do
, "49848004800504d9010281d8799f182aff0581840000d8799f182aff820000f4f6"
]
describe "ImpTest" $
withImpState @Conway $
withImpInit @(LedgerSpec Conway) $
it "InsufficientCollateral is not encoded with negative coin #4198" $ do
collateralAddress <- freshKeyAddr_
(_, skp) <- freshKeyPair
Expand Down
35 changes: 16 additions & 19 deletions eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import Cardano.Ledger.Alonzo.Rules (
import Cardano.Ledger.Babbage.Rules (BabbageUtxoPredFailure, BabbageUtxowPredFailure)
import Cardano.Ledger.Babbage.TxInfo (BabbageContextError)
import Cardano.Ledger.BaseTypes (Inject, ShelleyBase)
import Cardano.Ledger.Conway (Conway)
import Cardano.Ledger.Conway.Core
import Cardano.Ledger.Conway.Rules (
ConwayBbodyPredFailure,
Expand All @@ -44,7 +43,6 @@ import Control.State.Transition.Extended
import Data.Sequence (Seq)
import Data.Typeable (Typeable)
import qualified Test.Cardano.Ledger.Babbage.Imp as BabbageImp
import Test.Cardano.Ledger.Common
import qualified Test.Cardano.Ledger.Conway.Imp.BbodySpec as Bbody
import qualified Test.Cardano.Ledger.Conway.Imp.CertsSpec as Certs
import qualified Test.Cardano.Ledger.Conway.Imp.DelegSpec as Deleg
Expand All @@ -56,7 +54,8 @@ import qualified Test.Cardano.Ledger.Conway.Imp.LedgerSpec as Ledger
import qualified Test.Cardano.Ledger.Conway.Imp.RatifySpec as Ratify
import qualified Test.Cardano.Ledger.Conway.Imp.UtxoSpec as Utxo
import qualified Test.Cardano.Ledger.Conway.Imp.UtxosSpec as Utxos
import Test.Cardano.Ledger.Conway.ImpTest (ConwayEraImp, withImpStateWithProtVer)
import Test.Cardano.Ledger.Conway.ImpTest (ConwayEraImp, LedgerSpec, modifyImpInitProtVer)
import Test.Cardano.Ledger.Imp.Common

spec ::
forall era.
Expand Down Expand Up @@ -98,20 +97,18 @@ spec ::
Spec
spec = do
BabbageImp.spec @era
let
conwayImpSpec protVer =
withImpInit @(LedgerSpec era) $
forM_ (eraProtVersions @era) $ \protVer ->
describe ("ConwayImpSpec - " <> show protVer) $
withImpStateWithProtVer @era protVer $ do
describe "BBODY" $ Bbody.spec @era
describe "CERTS" $ Certs.spec @era
describe "DELEG" $ Deleg.spec @era
describe "ENACT" $ Enact.spec @era
describe "EPOCH" $ Epoch.spec @era
describe "GOV" $ Gov.spec @era
describe "GOVCERT" $ GovCert.spec @era
describe "LEDGER" $ Ledger.spec @era
describe "RATIFY" $ Ratify.spec @era
describe "UTXO" $ Utxo.spec @era
describe "UTXOS" $ Utxos.spec @era
in
forM_ [eraProtVerLow @Conway .. eraProtVerHigh @Conway] conwayImpSpec
modifyImpInitProtVer protVer $ do
describe "BBODY" Bbody.spec
describe "CERTS" Certs.spec
describe "DELEG" Deleg.spec
describe "ENACT" Enact.spec
describe "EPOCH" Epoch.spec
describe "GOV" Gov.spec
describe "GOVCERT" GovCert.spec
describe "LEDGER" Ledger.spec
describe "RATIFY" Ratify.spec
describe "UTXO" Utxo.spec
describe "UTXOS" Utxos.spec
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ spec ::
, EraSegWits era
, InjectRuleFailure "BBODY" ConwayBbodyPredFailure era
) =>
SpecWith (ImpTestState era)
SpecWith (ImpInit (LedgerSpec era))
spec = describe "BBODY" $ do
it "BodyRefScriptsSizeTooBig" $ do
Just (script :: Script era) <- pure largeScript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ spec ::
, InjectRuleFailure "LEDGER" ConwayCertsPredFailure era
, InjectRuleFailure "LEDGER" ConwayLedgerPredFailure era
) =>
SpecWith (ImpTestState era)
SpecWith (ImpInit (LedgerSpec era))
spec = do
describe "Withdrawals" $ do
it "Withdrawing from an unregistered reward account" $ do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ spec ::
( ConwayEraImp era
, InjectRuleFailure "LEDGER" ConwayDelegPredFailure era
) =>
SpecWith (ImpTestState era)
SpecWith (ImpInit (LedgerSpec era))
spec = do
describe "Register stake credential" $ do
it "With correct deposit or without any deposit" $ do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ spec ::
, InjectRuleEvent "TICK" ConwayEpochEvent era
, InjectRuleFailure "LEDGER" ConwayGovPredFailure era
) =>
SpecWith (ImpTestState era)
SpecWith (ImpInit (LedgerSpec era))
spec = do
committeeSpec
treasuryWithdrawalsSpec
Expand All @@ -74,7 +74,7 @@ treasuryWithdrawalsSpec ::
, Eq (Event (EraRule "ENACT" era))
, Typeable (Event (EraRule "ENACT" era))
) =>
SpecWith (ImpTestState era)
SpecWith (ImpInit (LedgerSpec era))
treasuryWithdrawalsSpec =
describe "Treasury withdrawals" $ do
-- Treasury withdrawals are disallowed in bootstrap, so we're running these tests only post-bootstrap
Expand Down Expand Up @@ -208,7 +208,7 @@ hardForkInitiationSpec ::
, Event (EraRule "EPOCH" era) ~ ConwayEpochEvent era
, InjectRuleEvent "TICK" ConwayEpochEvent era
) =>
SpecWith (ImpTestState era)
SpecWith (ImpInit (LedgerSpec era))
hardForkInitiationSpec =
it "HardForkInitiation" $ whenPostBootstrap $ do
committeeMembers' <- registerInitialCommittee
Expand Down Expand Up @@ -256,7 +256,7 @@ hardForkInitiationNoDRepsSpec ::
, Event (EraRule "EPOCH" era) ~ ConwayEpochEvent era
, InjectRuleEvent "TICK" ConwayEpochEvent era
) =>
SpecWith (ImpTestState era)
SpecWith (ImpInit (LedgerSpec era))
hardForkInitiationNoDRepsSpec =
it "HardForkInitiation without DRep voting" $ do
committeeMembers' <- registerInitialCommittee
Expand Down Expand Up @@ -285,7 +285,7 @@ hardForkInitiationNoDRepsSpec =
]
getProtVer `shouldReturn` nextProtVer

pparamPredictionSpec :: ConwayEraImp era => SpecWith (ImpTestState era)
pparamPredictionSpec :: ConwayEraImp era => SpecWith (ImpInit (LedgerSpec era))
pparamPredictionSpec =
it "futurePParams" $ do
committeeMembers' <- registerInitialCommittee
Expand All @@ -306,7 +306,7 @@ pparamPredictionSpec =
passEpoch
getProtVer `shouldReturn` nextProtVer

noConfidenceSpec :: forall era. ConwayEraImp era => SpecWith (ImpTestState era)
noConfidenceSpec :: forall era. ConwayEraImp era => SpecWith (ImpInit (LedgerSpec era))
noConfidenceSpec =
it "NoConfidence" $ whenPostBootstrap $ do
modifyPParams $ \pp ->
Expand Down Expand Up @@ -355,7 +355,7 @@ constitutionSpec ::
( ConwayEraImp era
, InjectRuleFailure "LEDGER" ConwayGovPredFailure era
) =>
SpecWith (ImpTestState era)
SpecWith (ImpInit (LedgerSpec era))
constitutionSpec =
it "Constitution" $ do
(committeeMember1 :| [committeeMember2]) <- registerInitialCommittee
Expand Down Expand Up @@ -428,7 +428,7 @@ actionPrioritySpec ::
( ConwayEraImp era
, InjectRuleFailure "LEDGER" ConwayGovPredFailure era
) =>
SpecWith (ImpTestState era)
SpecWith (ImpInit (LedgerSpec era))
actionPrioritySpec =
describe "Competing proposals" $ do
it "higher action priority wins" $ do
Expand Down Expand Up @@ -552,7 +552,7 @@ committeeSpec ::
( ConwayEraImp era
, InjectRuleFailure "LEDGER" ConwayGovPredFailure era
) =>
SpecWith (ImpTestState era)
SpecWith (ImpInit (LedgerSpec era))
committeeSpec =
describe "Committee enactment" $ do
it "Enact UpdateCommitee with lengthy lifetime" $ do
Expand Down
Loading

0 comments on commit 14a4713

Please sign in to comment.