Skip to content

Commit

Permalink
Added conformance check when running passTick
Browse files Browse the repository at this point in the history
  • Loading branch information
Soupstraw committed Nov 19, 2024
1 parent d7c9778 commit e3a3a81
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 7 deletions.
19 changes: 19 additions & 0 deletions eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/ImpTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ module Test.Cardano.Ledger.Shelley.ImpTest (
impSetSeed,
modifyImpInitProtVer,
modifyImpInitHook,
modifyImpInitPassTickHook,

-- * Logging
Doc,
Expand All @@ -119,6 +120,7 @@ module Test.Cardano.Ledger.Shelley.ImpTest (
withPreFixup,
withCborRoundTripFailures,
withHook,
withPassTickHook,
impNESL,
impGlobalsL,
impLastTickG,
Expand Down Expand Up @@ -305,6 +307,7 @@ instance ShelleyEraImp era => ImpSpec (LedgerSpec era) where
{ iteFixup = fixupTx
, iteCborRoundTripFailures = True
, iteHook = \_ _ _ _ -> pure ()
, itePassTickHook = pure ()
}
, impInitState = initState
}
Expand Down Expand Up @@ -646,6 +649,14 @@ modifyImpInitHook ::
modifyImpInitHook f =
modifyImpInit (impInitEnvL . iteHookL .~ f)

modifyImpInitPassTickHook ::
forall era.
ImpTestM era () ->
SpecWith (ImpInit (LedgerSpec era)) ->
SpecWith (ImpInit (LedgerSpec era))
modifyImpInitPassTickHook f =
modifyImpInit (impInitEnvL . itePassTickHookL .~ f)

impLedgerEnv :: EraGov era => NewEpochState era -> ImpTestM era (LedgerEnv era)
impLedgerEnv nes = do
slotNo <- gets impLastTick
Expand Down Expand Up @@ -792,6 +803,7 @@ data ImpTestEnv era = ImpTestEnv
LedgerState era ->
Tx era ->
ImpTestM era ()
, itePassTickHook :: ImpTestM era ()
, iteCborRoundTripFailures :: !Bool
-- ^ Expect failures in CBOR round trip serialization tests for predicate failures
}
Expand All @@ -812,6 +824,9 @@ iteHookL ::
)
iteHookL = lens iteHook (\x y -> x {iteHook = y})

itePassTickHookL :: Lens' (ImpTestEnv era) (ImpTestM era ())
itePassTickHookL = lens itePassTickHook (\x y -> x {itePassTickHook = y})

iteCborRoundTripFailuresL :: Lens' (ImpTestEnv era) Bool
iteCborRoundTripFailuresL = lens iteCborRoundTripFailures (\x y -> x {iteCborRoundTripFailures = y})

Expand Down Expand Up @@ -1220,6 +1235,7 @@ passTick ::
) =>
ImpTestM era ()
passTick = do
impAnn "Running passTickHook" =<< asks itePassTickHook
impLastTick <- gets impLastTick
curNES <- getsNES id
nes <- runImpRule @"TICK" () curNES impLastTick
Expand Down Expand Up @@ -1607,6 +1623,9 @@ withHook ::
ImpTestM era a
withHook f = local $ iteHookL .~ f

withPassTickHook :: ImpTestM era () -> ImpTestM era a -> ImpTestM era a
withPassTickHook f = local $ itePassTickHookL .~ f

expectUTxOContent ::
(HasCallStack, ToExpr (TxOut era)) =>
UTxO era -> [(TxIn (EraCrypto era), Maybe (TxOut era) -> Bool)] -> ImpTestM era ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ import Cardano.Ledger.Alonzo.Tx (AlonzoTx)
import Cardano.Ledger.BaseTypes
import Cardano.Ledger.Binary (EncCBOR)
import Cardano.Ledger.Conway (Conway)
import Cardano.Ledger.Conway.Governance (
ConwayGovState,
GovActionState,
cgsProposalsL,
proposalsActions,
)
import Cardano.Ledger.Conway.Rules
import Cardano.Ledger.Core
import Cardano.Ledger.Shelley.Governance
Expand All @@ -25,17 +31,19 @@ import Control.State.Transition
import Data.Bifunctor (bimap)
import Data.Bitraversable (bimapM)
import Data.Default (def)
import Data.List.NonEmpty
import Data.Foldable (Foldable (..))
import Data.List.NonEmpty (NonEmpty)
import Lens.Micro
import Lens.Micro.Mtl (use)
import Test.Cardano.Ledger.Conformance.ExecSpecRule.Conway (ConwayLedgerExecContext (..))
import Test.Cardano.Ledger.Conformance.ExecSpecRule.Conway.Base ()
import Test.Cardano.Ledger.Conformance.ExecSpecRule.Core
import Test.Cardano.Ledger.Conformance.SpecTranslate.Core
import Test.Cardano.Ledger.Constrained.Conway
import Test.Cardano.Ledger.Conway.Imp qualified as ConwayImp (conwaySpec)
import Test.Cardano.Ledger.Conway.ImpTest
import Test.Cardano.Ledger.Imp.Common hiding (Args)
import UnliftIO (evaluateDeep)
import UnliftIO (MonadIO (..), evaluateDeep)

testImpConformance ::
forall era.
Expand Down Expand Up @@ -129,16 +137,63 @@ testImpConformance impRuleResult env state signal = do
impResponse
agdaResponse

testImpConformanceNewEpoch ::
forall era fn.
( ShelleyEraImp era
, ExecSpecRule fn "NEWEPOCH" era
, NFData (SpecRep (PredicateFailure (EraRule "NEWEPOCH" era)))
, Eq (SpecRep (PredicateFailure (EraRule "NEWEPOCH" era)))
, Inject (State (EraRule "NEWEPOCH" era)) (ExecState fn "NEWEPOCH" era)
, SpecTranslate (ExecContext fn "NEWEPOCH" era) (ExecState fn "NEWEPOCH" era)
, SpecTranslate (ExecContext fn "NEWEPOCH" era) (State (EraRule "NEWEPOCH" era))
, FixupSpecRep (SpecRep (PredicateFailure (EraRule "NEWEPOCH" era)))
, EncCBOR (ExecContext fn "NEWEPOCH" era)
, EncCBOR (Environment (EraRule "NEWEPOCH" era))
, EncCBOR (State (EraRule "NEWEPOCH" era))
, EncCBOR (Signal (EraRule "NEWEPOCH" era))
, ToExpr (ExecContext fn "NEWEPOCH" era)
, ToExpr (SpecRep (PredicateFailure (EraRule "NEWEPOCH" era)))
, GovState era ~ ConwayGovState era
, ExecContext fn "NEWEPOCH" era ~ [GovActionState era]
, ExecState fn "NEWEPOCH" era ~ NewEpochState era
, ExecEnvironment fn "NEWEPOCH" era ~ EpochExecEnv era
, ExecSignal fn "NEWEPOCH" era ~ EpochNo
) =>
ImpTestM era ()
testImpConformanceNewEpoch = do
ctx <-
getsNES $
nesEsL
. epochStateGovStateL
. cgsProposalsL
. to (toList . proposalsActions)
st <- getsNES id
eNo <- getsNES nesELL
let
env = EpochExecEnv stakeDistr
stakeDistr = mempty
args =
stdArgs
{ maxSuccess = 1
, chatty = False
}
liftIO . quickCheckWith args $
testConformance @fn @"NEWEPOCH" @era ctx env st eNo

spec :: Spec
spec =
withImpInit @(LedgerSpec Conway) $ do
xdescribe "Tx conformance"
describe "Tx conformance"
. modifyImpInitProtVer @Conway (natVersion @10)
. modifyImpInitHook testImpConformance
. modifyImpInitPassTickHook (testImpConformanceNewEpoch @Conway @ConwayFn)
$ do
it "Tx conformance" $ do
xit "Tx conformance" $ do
_ <- submitConstitution @Conway SNothing
passNEpochs 2
xdescribe "Test.Cardano.Ledger.Conway.Imp conformance" $
modifyImpInitHook testImpConformance $
ConwayImp.conwaySpec @Conway
it "passEpoch conformance" $ do
passNEpochs 10
describe "Test.Cardano.Ledger.Conway.Imp conformance"
. modifyImpInitHook testImpConformance
. modifyImpInitPassTickHook (testImpConformanceNewEpoch @Conway @ConwayFn)
$ ConwayImp.conwaySpec @Conway

0 comments on commit e3a3a81

Please sign in to comment.