22{-# LANGUAGE FlexibleContexts #-}
33{-# LANGUAGE NumericUnderscores #-}
44{-# LANGUAGE OverloadedLists #-}
5+ {-# LANGUAGE OverloadedStrings #-}
56{-# LANGUAGE ScopedTypeVariables #-}
67{-# LANGUAGE TypeApplications #-}
78{-# LANGUAGE TypeFamilies #-}
@@ -14,21 +15,18 @@ import Cardano.Ledger.Coin (Coin (..))
1415import Cardano.Ledger.Conway.Core
1516import Cardano.Ledger.Conway.Governance
1617import Cardano.Ledger.Conway.Rules (
17- ConwayLedgerEvent (.. ),
1818 ConwayLedgerPredFailure (.. ),
1919 maxRefScriptSizePerTx ,
2020 )
2121import Cardano.Ledger.Credential (Credential (.. ))
2222import Cardano.Ledger.DRep
2323import Cardano.Ledger.Plutus (SLanguage (.. ), hashPlutusScript )
24- import Cardano.Ledger.Shelley.API.Mempool (ApplyTx (.. ), applyTx , mkMempoolEnv )
24+ import Cardano.Ledger.Shelley.API.Mempool (ApplyTx (.. ), ApplyTxError ( .. ), applyTx , mkMempoolEnv )
2525import qualified Cardano.Ledger.Shelley.HardForks as HF (bootstrapPhase )
2626import Cardano.Ledger.Shelley.LedgerState
27- import Cardano.Ledger.Shelley.Rules (ShelleyLedgersEnv (.. ), ShelleyLedgersEvent (.. ))
28- import Control.State.Transition.Extended
2927import qualified Data.Map.Strict as Map
30- import qualified Data.Sequence as Seq
3128import qualified Data.Set as Set
29+ import qualified Data.Text as T
3230import Lens.Micro ((&) , (.~) , (^.) )
3331import Lens.Micro.Mtl (use )
3432import Test.Cardano.Ledger.Conway.ImpTest
@@ -43,12 +41,6 @@ spec ::
4341 forall era .
4442 ( ConwayEraImp era
4543 , InjectRuleFailure " LEDGER" ConwayLedgerPredFailure era
46- , BaseM (EraRule " LEDGERS" era ) ~ ShelleyBase
47- , Environment (EraRule " LEDGERS" era ) ~ ShelleyLedgersEnv era
48- , Signal (EraRule " LEDGERS" era ) ~ Seq. Seq (Tx era )
49- , Event (EraRule " LEDGERS" era ) ~ ShelleyLedgersEvent era
50- , Event (EraRule " LEDGER" era ) ~ ConwayLedgerEvent era
51- , STS (EraRule " LEDGERS" era )
5244 , ApplyTx era
5345 ) =>
5446 SpecWith (ImpInit (LedgerSpec era ))
@@ -219,43 +211,7 @@ spec = do
219211 mkBasicTx $
220212 mkBasicTxBody & withdrawalsTxBodyL .~ Withdrawals [(ra, mempty )]
221213
222- describe " Mempool events" $ do
223- it " No Mempool events should be emitted via LEDGERS rules " $ do
224- nes <- use impNESL
225- slotNo <- use impLastTickG
226- let ls = nes ^. nesEsL . esLStateL
227- pp = nes ^. nesEsL . curPParamsEpochStateL
228- account = nes ^. nesEsL . esAccountStateL
229- epochNo = nes ^. nesELL
230- tx <- fixupTx $ mkBasicTx mkBasicTxBody
231- Right (_, evs) <-
232- tryRunImpRule @ " LEDGERS"
233- (LedgersEnv slotNo epochNo pp account)
234- ls
235- (Seq. singleton tx)
236- let mempoolEvents = [ev | LedgerEvent ev <- evs]
237- mempoolEvents `shouldBeExpr` []
238-
239- it " Mempool events should be emitted via `applyTx` with `mkMempoolEnv`" $ do
240- globals <- use impGlobalsL
241- slotNo <- use impLastTickG
242- nes <- use impNESL
243- let ls = nes ^. nesEsL . esLStateL
244-
245- let mempoolEnv = mkMempoolEnv nes slotNo
246- tx <- fixupTx $ mkBasicTx mkBasicTxBody
247- let stsOpts =
248- ApplySTSOpts
249- { asoAssertions = AssertionsAll
250- , asoValidation = ValidateAll
251- , asoEvents = EPReturn
252- }
253- case applyTxOpts stsOpts globals mempoolEnv ls tx of
254- Left e ->
255- assertFailure $ " Unexpected failure while applyingTx: " <> show tx <> " : " <> show e
256- Right (_, evs) ->
257- length [ev | ev <- evs] `shouldBe` 1
258-
214+ describe " Mempool" $ do
259215 it " Unelected Committee voting" $ whenPostBootstrap $ do
260216 globals <- use impGlobalsL
261217 slotNo <- use impLastTickG
@@ -291,6 +247,10 @@ spec = do
291247 )
292248
293249 case applyTx globals mempoolEnv ls tx of
294- Left _ -> pure ()
250+ Left err ->
251+ let expectedFailure =
252+ ConwayMempoolFailure $
253+ " Unelected committee members are not allowed to cast votes: " <> T. pack (show (pure @ [] ccHot))
254+ in err `shouldBe` ApplyTxError @ era (pure (injectFailure expectedFailure))
295255 Right _ -> assertFailure $ " Expected failure due to an unallowed vote: " <> show tx
296256 withNoFixup $ submitTx_ tx
0 commit comments