Skip to content

Commit f1b890b

Browse files
committed
Move tryRunImpBBODY from Conway.Imp.BbodySpec to Shelly.ImpTest
1 parent a0fb982 commit f1b890b

File tree

2 files changed

+38
-39
lines changed
  • eras
    • conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp
    • shelley/impl/testlib/Test/Cardano/Ledger/Shelley

2 files changed

+38
-39
lines changed

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/BbodySpec.hs

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,33 @@
11
{-# LANGUAGE BangPatterns #-}
22
{-# LANGUAGE DataKinds #-}
33
{-# LANGUAGE FlexibleContexts #-}
4-
{-# LANGUAGE NamedFieldPuns #-}
54
{-# LANGUAGE NumericUnderscores #-}
65
{-# LANGUAGE OverloadedLists #-}
76
{-# LANGUAGE PatternSynonyms #-}
87
{-# LANGUAGE ScopedTypeVariables #-}
98
{-# LANGUAGE TypeApplications #-}
109

11-
module Test.Cardano.Ledger.Conway.Imp.BbodySpec (
12-
spec,
13-
) where
10+
module Test.Cardano.Ledger.Conway.Imp.BbodySpec (spec) where
1411

15-
import Cardano.Ledger.BHeaderView (BHeaderView (..))
1612
import Cardano.Ledger.Babbage.Core
17-
import Cardano.Ledger.BaseTypes (BlocksMade (..), Mismatch (..), ProtVer (..), natVersion)
18-
import Cardano.Ledger.Block
13+
import Cardano.Ledger.BaseTypes (Mismatch (..), ProtVer (..), natVersion)
1914
import Cardano.Ledger.Coin (Coin (..))
2015
import Cardano.Ledger.Conway.PParams (ConwayEraPParams (..))
2116
import Cardano.Ledger.Conway.Rules (
2217
ConwayBbodyPredFailure (..),
2318
totalRefScriptSizeInBlock,
2419
)
25-
import Cardano.Ledger.Conway.State
2620
import Cardano.Ledger.Plutus (SLanguage (..), hashPlutusScript)
27-
import Cardano.Ledger.Shelley.LedgerState
28-
import Cardano.Ledger.Shelley.Rules (
29-
BbodyEnv (..),
30-
ShelleyBbodyState (..),
31-
)
3221
import Cardano.Ledger.Shelley.Scripts (
3322
pattern RequireSignature,
3423
)
3524
import Cardano.Ledger.TxIn
3625
import Control.Monad (forM)
3726
import Data.List.NonEmpty (NonEmpty (..))
3827
import qualified Data.List.NonEmpty as NE
39-
import qualified Data.Map as Map
4028
import qualified Data.Sequence.Strict as SSeq
4129
import Data.Word (Word32)
4230
import Lens.Micro ((&), (.~), (^.))
43-
import Lens.Micro.Mtl (use)
4431
import Test.Cardano.Ledger.Babbage.ImpTest
4532
import Test.Cardano.Ledger.Conway.ImpTest (ConwayEraImp)
4633
import Test.Cardano.Ledger.Core.Utils (txInAt)
@@ -82,7 +69,7 @@ spec = do
8269
>>= updateAddrTxWits
8370

8471
let expectedTotalRefScriptSize = scriptSize * sum txScriptCounts
85-
predFailures <- expectLeftExpr =<< tryRunBBODY txs
72+
predFailures <- expectLeftExpr =<< tryRunImpBBODY txs
8673
predFailures
8774
`shouldBe` NE.fromList
8875
[ injectFailure
@@ -129,7 +116,7 @@ spec = do
129116
pure $ refScriptTxs ++ [spendTx]
130117
)
131118

132-
predFailures <- expectLeftExpr =<< tryRunBBODY txs
119+
predFailures <- expectLeftExpr =<< tryRunImpBBODY txs
133120
predFailures
134121
`shouldBe` NE.fromList
135122
[ injectFailure
@@ -267,25 +254,6 @@ spec = do
267254
<$> getUTxO
268255
`shouldReturn` (if isPostV10 protVer then scriptSize else 0)
269256
where
270-
tryRunBBODY txs = do
271-
let blockBody = mkBasicBlockBody @era & txSeqBlockBodyL .~ SSeq.fromList txs
272-
nes <- use impNESL
273-
let ls = nes ^. nesEsL . esLStateL
274-
pp = nes ^. nesEsL . curPParamsEpochStateL @era
275-
kh <- freshKeyHash
276-
slotNo <- use impCurSlotNoG
277-
let bhView =
278-
BHeaderView
279-
{ bhviewID = kh
280-
, bhviewBSize = fromIntegral $ bBodySize (ProtVer (eraProtVerLow @era) 0) blockBody
281-
, bhviewHSize = 0
282-
, bhviewBHash = hashBlockBody blockBody
283-
, bhviewSlot = slotNo
284-
}
285-
tryRunImpRule @"BBODY"
286-
(BbodyEnv pp (nes ^. chainAccountStateL))
287-
(BbodyState ls (BlocksMade Map.empty))
288-
(Block {blockHeader = bhView, blockBody})
289257
isPostV10 protVer = pvMajor protVer >= natVersion @11
290258

291259
-- Generate a list of integers such that the sum of their multiples by scale is greater than toExceed

eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/ImpTest.hs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ module Test.Cardano.Ledger.Shelley.ImpTest (
6868
impAnnDoc,
6969
impLogToExpr,
7070
runImpRule,
71+
tryRunImpBBODY,
7172
tryRunImpRule,
7273
tryRunImpRuleNoAssertions,
7374
delegateStake,
@@ -170,10 +171,10 @@ import Cardano.Ledger.Address (
170171
RewardAccount (..),
171172
bootstrapKeyHash,
172173
)
173-
import Cardano.Ledger.BHeaderView (BHeaderView)
174+
import Cardano.Ledger.BHeaderView (BHeaderView (..))
174175
import Cardano.Ledger.BaseTypes
175176
import Cardano.Ledger.Binary (DecCBOR, EncCBOR)
176-
import Cardano.Ledger.Block (Block)
177+
import Cardano.Ledger.Block (Block (..))
177178
import Cardano.Ledger.Coin
178179
import Cardano.Ledger.Compactible (fromCompact)
179180
import Cardano.Ledger.Credential (Credential (..), Ptr, StakeReference (..), credToText)
@@ -212,7 +213,7 @@ import Cardano.Ledger.Shelley.LedgerState (
212213
import Cardano.Ledger.Shelley.Rules (
213214
BbodyEnv (..),
214215
LedgerEnv (..),
215-
ShelleyBbodyState,
216+
ShelleyBbodyState (..),
216217
ShelleyDelegPredFailure,
217218
ShelleyPoolPredFailure,
218219
ShelleyUtxoPredFailure,
@@ -1261,6 +1262,36 @@ submitFailingTxM tx mkExpectedFailures = do
12611262
expectedFailures <- mkExpectedFailures fixedUpTx
12621263
predFailures `shouldBeExpr` expectedFailures
12631264

1265+
tryRunImpBBODY ::
1266+
forall era.
1267+
ShelleyEraImp era =>
1268+
[Tx TopTx era] ->
1269+
ImpTestM
1270+
era
1271+
( Either
1272+
(NonEmpty (PredicateFailure (EraRule "BBODY" era)))
1273+
(State (EraRule "BBODY" era), [Event (EraRule "BBODY" era)])
1274+
)
1275+
tryRunImpBBODY txs = do
1276+
let blockBody = mkBasicBlockBody @era & txSeqBlockBodyL .~ SSeq.fromList txs
1277+
nes <- use impNESL
1278+
let ls = nes ^. nesEsL . esLStateL
1279+
pp = nes ^. nesEsL . curPParamsEpochStateL @era
1280+
kh <- freshKeyHash
1281+
slotNo <- use impCurSlotNoG
1282+
let bhView =
1283+
BHeaderView
1284+
{ bhviewID = kh
1285+
, bhviewBSize = fromIntegral $ bBodySize (ProtVer (eraProtVerLow @era) 0) blockBody
1286+
, bhviewHSize = 0
1287+
, bhviewBHash = hashBlockBody blockBody
1288+
, bhviewSlot = slotNo
1289+
}
1290+
tryRunImpRule @"BBODY"
1291+
(BbodyEnv pp (nes ^. chainAccountStateL))
1292+
(BbodyState ls (BlocksMade Map.empty))
1293+
(Block {blockHeader = bhView, blockBody})
1294+
12641295
tryRunImpRule ::
12651296
forall rule era.
12661297
(STS (EraRule rule era), BaseM (EraRule rule era) ~ ShelleyBase) =>

0 commit comments

Comments
 (0)