Skip to content

Commit fcee41c

Browse files
committed
EraBlockHeader: fix shelley-test and ledger-test
1 parent da86af6 commit fcee41c

File tree

10 files changed

+81
-64
lines changed

10 files changed

+81
-64
lines changed

eras/shelley/test-suite/bench/BenchValidation.hs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
{-# LANGUAGE TypeFamilies #-}
99
{-# LANGUAGE TypeOperators #-}
1010
{-# OPTIONS_GHC -Wno-orphans #-}
11-
{-# OPTIONS_GHC -Wno-unused-binds #-}
1211

1312
module BenchValidation (
1413
ValidateInput (..),
@@ -23,7 +22,7 @@ module BenchValidation (
2322
) where
2423

2524
import Cardano.Ledger.BaseTypes (Globals (..), unBlocksMade)
26-
import Cardano.Ledger.Block (Block (..))
25+
import Cardano.Ledger.Block (Block (..), EraBlockHeader)
2726
import qualified Cardano.Ledger.Shelley.API as API
2827
import Cardano.Ledger.Shelley.Bench.Gen (genBlock, genChainState)
2928
import Cardano.Ledger.Shelley.BlockBody (slotToNonce)
@@ -44,7 +43,10 @@ import Cardano.Protocol.TPraos.API (
4443
tickChainDepState,
4544
updateChainDepState,
4645
)
47-
import Cardano.Protocol.TPraos.BHeader (BHeader (..), LastAppliedBlock (..), makeHeaderView)
46+
import Cardano.Protocol.TPraos.BHeader (
47+
BHeader (..),
48+
LastAppliedBlock (..),
49+
)
4850
import Cardano.Protocol.TPraos.Rules.Prtcl (PrtclState (..))
4951
import Cardano.Protocol.TPraos.Rules.Tickn (TicknState (..))
5052
import Cardano.Slotting.Slot (withOriginToMaybe)
@@ -53,6 +55,7 @@ import Control.Monad.Except ()
5355
import Control.State.Transition
5456
import qualified Data.Map.Strict as Map
5557
import Data.Proxy
58+
import Test.Cardano.Ledger.BlockHeader (TestBlockHeader (..), mkTestBlockHeaderNoNonce)
5659
import Test.Cardano.Ledger.Shelley.ConcreteCryptoTypes (MockCrypto)
5760
import Test.Cardano.Ledger.Shelley.Constants (defaultConstants)
5861
import Test.Cardano.Ledger.Shelley.Generator.Core (GenEnv)
@@ -76,9 +79,10 @@ validateInput ::
7679
, EraStake era
7780
, EraRule "LEDGERS" era ~ API.ShelleyLEDGERS era
7881
, QC.HasTrace (API.ShelleyLEDGERS era) (GenEnv MockCrypto era)
79-
, API.ApplyBlock era
82+
, API.ApplyBlock TestBlockHeader era
8083
, GetLedgerView era
8184
, MinLEDGER_STS era
85+
, EraBlockHeader (BHeader MockCrypto) era
8286
) =>
8387
Int ->
8488
IO (ValidateInput era)
@@ -89,39 +93,41 @@ validateInput n = do
8993
pure (ValidateInput testGlobals (chainNes chainstate) block)
9094

9195
benchValidate ::
92-
(API.ApplyBlock era, Show (PredicateFailure (EraRule "BBODY" era))) =>
96+
( API.ApplyBlock TestBlockHeader era
97+
, Show (PredicateFailure (EraRule "BBODY" era))
98+
, EraBlockHeader (BHeader MockCrypto) era
99+
) =>
93100
ValidateInput era ->
94101
IO (NewEpochState era)
95-
benchValidate (ValidateInput globals state (Block bh txs)) =
96-
let block = Block (makeHeaderView bh Nothing) txs
97-
in case API.applyBlockEitherNoEvents ValidateAll globals state block of
98-
Right x -> pure x
99-
Left x -> error (show x)
102+
benchValidate (ValidateInput globals state blk@(Block _ txs)) =
103+
case API.applyBlockEitherNoEvents ValidateAll globals state (Block (mkTestBlockHeaderNoNonce blk) txs) of
104+
Right x -> pure x
105+
Left x -> error (show x)
100106

101107
applyBlock ::
102108
forall era.
103-
( API.ApplyBlock era
109+
( API.ApplyBlock TestBlockHeader era
104110
, NFData (StashedAVVMAddresses era)
105111
, NFData (InstantStake era)
106112
, GovState era ~ ShelleyGovState era
107113
, EraCertState era
108114
, Show (PredicateFailure (EraRule "BBODY" era))
115+
, EraBlockHeader (BHeader MockCrypto) era
109116
) =>
110117
ValidateInput era ->
111118
Int ->
112119
Int
113-
applyBlock (ValidateInput globals state (Block bh txs)) n =
114-
let block = Block (makeHeaderView bh Nothing) txs
115-
in case API.applyBlockEitherNoEvents ValidateAll globals state block of
116-
Right x -> seq (rnf x) (n + 1)
117-
Left x -> error (show x)
120+
applyBlock (ValidateInput globals state blk@(Block _ txs)) n =
121+
case API.applyBlockEitherNoEvents ValidateAll globals state (Block (mkTestBlockHeaderNoNonce blk) txs) of
122+
Right x -> seq (rnf x) (n + 1)
123+
Left x -> error (show x)
118124

119125
benchreValidate ::
120-
API.ApplyBlock era =>
126+
(API.ApplyBlock TestBlockHeader era, EraBlockHeader (BHeader MockCrypto) era) =>
121127
ValidateInput era ->
122128
NewEpochState era
123-
benchreValidate (ValidateInput globals state (Block bh txs)) =
124-
API.applyBlockNoValidaton globals state (Block (makeHeaderView bh Nothing) txs)
129+
benchreValidate (ValidateInput globals state blk@(Block _ txs)) =
130+
API.applyBlockNoValidaton globals state (Block (mkTestBlockHeaderNoNonce blk) txs)
125131

126132
-- ==============================================================
127133

@@ -161,7 +167,8 @@ genUpdateInputs ::
161167
, GetLedgerView era
162168
, EraRule "LEDGERS" era ~ API.ShelleyLEDGERS era
163169
, QC.HasTrace (API.ShelleyLEDGERS era) (GenEnv MockCrypto era)
164-
, API.ApplyBlock era
170+
, API.ApplyBlock TestBlockHeader era
171+
, EraBlockHeader (BHeader MockCrypto) era
165172
) =>
166173
Int ->
167174
IO UpdateInputs

eras/shelley/test-suite/bench/Cardano/Ledger/Shelley/Bench/Gen.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Cardano.Ledger.Shelley.Bench.Gen (
1010
genChainState,
1111
) where
1212

13+
import Cardano.Ledger.Block (EraBlockHeader)
1314
import Cardano.Ledger.Coin
1415
import Cardano.Ledger.Shelley.API (
1516
ApplyBlock,
@@ -29,6 +30,7 @@ import Control.State.Transition.Extended
2930
import Data.Either (fromRight)
3031
import qualified Data.Map.Strict as Map
3132
import Data.Proxy
33+
import Test.Cardano.Ledger.BlockHeader (TestBlockHeader)
3234
import Test.Cardano.Ledger.Shelley.BenchmarkFunctions (ledgerEnv)
3335
import Test.Cardano.Ledger.Shelley.ConcreteCryptoTypes (MockCrypto)
3436
import Test.Cardano.Ledger.Shelley.Constants (
@@ -51,8 +53,6 @@ import Test.Cardano.Ledger.Shelley.Serialisation.Generators ()
5153
import qualified Test.Control.State.Transition.Trace.Generator.QuickCheck as QC
5254
import Test.QuickCheck (generate)
5355

54-
-- ===============================================================
55-
5656
-- | Generate a genesis chain state given a UTxO size
5757
genChainState ::
5858
( EraGen era
@@ -83,7 +83,8 @@ genBlock ::
8383
, GetLedgerView era
8484
, EraRule "LEDGERS" era ~ ShelleyLEDGERS era
8585
, QC.HasTrace (ShelleyLEDGERS era) (GenEnv MockCrypto era)
86-
, ApplyBlock era
86+
, ApplyBlock TestBlockHeader era
87+
, EraBlockHeader (BHeader MockCrypto) era
8788
) =>
8889
GenEnv MockCrypto era ->
8990
ChainState era ->

eras/shelley/test-suite/cardano-ledger-shelley-test.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ benchmark mainbench
198198
QuickCheck,
199199
base,
200200
cardano-data,
201-
cardano-ledger-core,
201+
cardano-ledger-core:{cardano-ledger-core, testlib},
202202
cardano-ledger-shelley:{cardano-ledger-shelley, testlib},
203203
cardano-ledger-shelley-test,
204204
cardano-protocol-tpraos,

eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/Block.hs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ module Test.Cardano.Ledger.Shelley.Generator.Block (
1414
) where
1515

1616
import qualified Cardano.Crypto.VRF as VRF
17-
import Cardano.Ledger.BHeaderView (bhviewBSize, bhviewHSize)
1817
import Cardano.Ledger.BaseTypes (UnitInterval)
18+
import Cardano.Ledger.Block (EraBlockHeader (..))
1919
import Cardano.Ledger.Shelley.API
2020
import Cardano.Ledger.Shelley.Core
2121
import Cardano.Ledger.Shelley.LedgerState (curPParamsEpochStateL, dsGenDelegsL)
@@ -26,7 +26,6 @@ import Cardano.Protocol.TPraos.BHeader (
2626
BHeader (..),
2727
LastAppliedBlock (..),
2828
hashHeaderToNonce,
29-
makeHeaderView,
3029
mkSeed,
3130
seedL,
3231
)
@@ -36,6 +35,7 @@ import Cardano.Protocol.TPraos.Rules.Prtcl (PrtclState (..))
3635
import Cardano.Protocol.TPraos.Rules.Tickn (TicknState (..))
3736
import Cardano.Slotting.Slot (WithOrigin (..))
3837
import Control.Monad (unless)
38+
import Control.State.Transition.Extended (SingEP (EPDiscard))
3939
import Data.Coerce (coerce)
4040
import Data.Foldable (toList)
4141
import qualified Data.List as List (find)
@@ -46,6 +46,7 @@ import Data.Sequence (Seq)
4646
import qualified Data.Set as Set
4747
import Lens.Micro ((^.))
4848
import Lens.Micro.Extras (view)
49+
import Test.Cardano.Ledger.BlockHeader (TestBlockHeader)
4950
import Test.Cardano.Ledger.Common (tracedDiscard)
5051
import Test.Cardano.Ledger.Core.KeyPair (vKey)
5152
import Test.Cardano.Ledger.Shelley.Generator.Core (
@@ -86,11 +87,12 @@ type TxGen era =
8687
genBlock ::
8788
forall era c.
8889
( MinLEDGER_STS era
89-
, ApplyBlock era
90+
, ApplyBlock TestBlockHeader era
9091
, GetLedgerView era
9192
, QC.HasTrace (EraRule "LEDGERS" era) (GenEnv c era)
9293
, EraGen era
9394
, PraosCrypto c
95+
, EraBlockHeader (BHeader c) era
9496
) =>
9597
GenEnv c era ->
9698
ChainState era ->
@@ -106,9 +108,10 @@ genBlock ge = genBlockWithTxGen genTxs ge
106108
genBlockWithTxGen ::
107109
forall era c.
108110
( GetLedgerView era
109-
, ApplyBlock era
111+
, ApplyBlock TestBlockHeader era
110112
, EraGen era
111113
, PraosCrypto c
114+
, EraBlockHeader (BHeader c) era
112115
) =>
113116
TxGen era ->
114117
GenEnv c era ->
@@ -173,17 +176,18 @@ genBlockWithTxGen
173176
-- e.g. the KES period in which this key starts to be valid.
174177
<*> pure (fromIntegral (m * fromIntegral maxKESIterations))
175178
<*> pure oCert
176-
let hView = makeHeaderView (blockHeader theBlock) Nothing
177-
unless (bhviewBSize hView <= pp ^. ppMaxBBSizeL) $
179+
let bSize = theBlock ^. blockHeaderBSizeL
180+
unless (bSize <= pp ^. ppMaxBBSizeL) $
178181
tracedDiscard $
179-
"genBlockWithTxGen: bhviewBSize too large"
180-
<> show (bhviewBSize hView)
182+
"genBlockWithTxGen: bsize too large"
183+
<> show bSize
181184
<> " vs "
182185
<> show (pp ^. ppMaxBBSizeL)
183-
unless (bhviewHSize hView <= fromIntegral (pp ^. ppMaxBHSizeL)) $
186+
let hSize = theBlock ^. blockHeaderHSizeL
187+
unless (hSize <= fromIntegral (pp ^. ppMaxBHSizeL)) $
184188
tracedDiscard $
185-
"genBlockWithTxGen: bhviewHSize too large"
186-
<> show (bhviewHSize hView)
189+
"genBlockWithTxGen: header size too large"
190+
<> show hSize
187191
<> " vs "
188192
<> show (pp ^. ppMaxBHSizeL)
189193
pure theBlock
@@ -198,7 +202,7 @@ selectNextSlotWithLeader ::
198202
forall era c.
199203
( EraGen era
200204
, GetLedgerView era
201-
, ApplyBlock era
205+
, ApplyBlock TestBlockHeader era
202206
, PraosCrypto c
203207
) =>
204208
GenEnv c era ->
@@ -274,7 +278,7 @@ selectNextSlotWithLeader
274278
-- | The chain state is a composite of the new epoch state and the chain dep
275279
-- state. We tick both.
276280
tickChainState ::
277-
(GetLedgerView era, ApplyBlock era) =>
281+
(GetLedgerView era, ApplyBlock TestBlockHeader era) =>
278282
SlotNo ->
279283
ChainState era ->
280284
ChainState era
@@ -302,7 +306,7 @@ tickChainState
302306
ChainDepState {csProtocol, csTickn} =
303307
tickChainDepState testGlobals lv isNewEpoch cds
304308
PrtclState ocertIssue evNonce candNonce = csProtocol
305-
nes' = applyTickNoEvents testGlobals chainNes slotNo
309+
nes' = fst $ applyTick @TestBlockHeader EPDiscard testGlobals chainNes slotNo
306310
in ChainState
307311
{ chainNes = nes'
308312
, chainOCertIssue = ocertIssue

eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/Trace/Chain.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{-# LANGUAGE FlexibleContexts #-}
44
{-# LANGUAGE FlexibleInstances #-}
55
{-# LANGUAGE MultiParamTypeClasses #-}
6-
{-# LANGUAGE NamedFieldPuns #-}
76
{-# LANGUAGE RecordWildCards #-}
87
{-# LANGUAGE ScopedTypeVariables #-}
98
{-# LANGUAGE TypeApplications #-}
@@ -15,7 +14,7 @@
1514

1615
module Test.Cardano.Ledger.Shelley.Generator.Trace.Chain where
1716

18-
import Cardano.Ledger.BHeaderView (BHeaderView (..))
17+
import Cardano.Ledger.Block (BbodySignal, EraBlockHeader)
1918
import Cardano.Ledger.Shelley.API
2019
import Cardano.Ledger.Shelley.Core
2120
import Cardano.Ledger.Shelley.Rules (
@@ -36,6 +35,7 @@ import Cardano.Ledger.Slot (
3635
import Cardano.Ledger.Val ((<->))
3736
import Cardano.Protocol.TPraos.API
3837
import Cardano.Protocol.TPraos.BHeader (
38+
BHeader,
3939
LastAppliedBlock (..),
4040
hashHeaderToNonce,
4141
)
@@ -51,6 +51,7 @@ import Data.Map.Strict (Map)
5151
import qualified Data.Map.Strict as Map
5252
import Data.Proxy (Proxy (..))
5353
import Numeric.Natural (Natural)
54+
import Test.Cardano.Ledger.BlockHeader (TestBlockHeader)
5455
import Test.Cardano.Ledger.Shelley.ConcreteCryptoTypes (MockCrypto)
5556
import Test.Cardano.Ledger.Shelley.Generator.Block (genBlock)
5657
import Test.Cardano.Ledger.Shelley.Generator.Core (GenEnv (..))
@@ -85,14 +86,15 @@ import Test.QuickCheck (Gen)
8586
instance
8687
( EraGen era
8788
, EraBlockBody era
88-
, ApplyBlock era
89+
, EraBlockHeader (BHeader MockCrypto) era
90+
, ApplyBlock TestBlockHeader era
8991
, GetLedgerView era
9092
, MinLEDGER_STS era
9193
, MinCHAIN_STS era
9294
, Embed (EraRule "BBODY" era) (CHAIN era)
9395
, Environment (EraRule "BBODY" era) ~ BbodyEnv era
9496
, State (EraRule "BBODY" era) ~ ShelleyBbodyState era
95-
, Signal (EraRule "BBODY" era) ~ Block BHeaderView era
97+
, Signal (EraRule "BBODY" era) ~ BbodySignal era
9698
, Embed (EraRule "TICKN" era) (CHAIN era)
9799
, Environment (EraRule "TICKN" era) ~ TicknEnv
98100
, State (EraRule "TICKN" era) ~ TicknState
@@ -109,7 +111,7 @@ instance
109111

110112
sigGen ge _env st = genBlock ge st
111113

112-
shrinkSignal = (\_x -> []) -- shrinkBlock -- TO DO FIX ME
114+
shrinkSignal _x = [] -- shrinkBlock -- TO DO FIX ME
113115

114116
type BaseEnv (CHAIN era) = Globals
115117
interpretSTS globals act = runIdentity $ runReaderT act globals

eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/PropertyTests.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ module Test.Cardano.Ledger.Shelley.PropertyTests (
1212
commonTests,
1313
) where
1414

15-
import Cardano.Ledger.BHeaderView (BHeaderView)
1615
import Cardano.Ledger.BaseTypes (Globals, ShelleyBase, SlotNo)
17-
import Cardano.Ledger.Block (Block)
16+
import Cardano.Ledger.Block (BbodySignal, EraBlockHeader)
1817
import Cardano.Ledger.Core
1918
import Cardano.Ledger.Shelley.API (ApplyBlock, ShelleyPOOL)
2019
import Cardano.Ledger.Shelley.Core
@@ -29,9 +28,11 @@ import Cardano.Ledger.Shelley.Rules (
2928
)
3029
import Cardano.Ledger.Shelley.State
3130
import Cardano.Protocol.TPraos.API (GetLedgerView)
31+
import Cardano.Protocol.TPraos.BHeader (BHeader)
3232
import Cardano.Protocol.TPraos.Rules.Tickn (TicknEnv, TicknState)
3333
import Control.State.Transition
3434
import Data.Sequence (Seq)
35+
import Test.Cardano.Ledger.BlockHeader (TestBlockHeader)
3536
import qualified Test.Cardano.Ledger.Shelley.ByronTranslation as ByronTranslation (
3637
testGroupByronTranslation,
3738
)
@@ -66,7 +67,7 @@ commonTests ::
6667
( EraGen era
6768
, EraStake era
6869
, ShelleyEraAccounts era
69-
, ApplyBlock era
70+
, ApplyBlock TestBlockHeader era
7071
, GetLedgerView era
7172
, Embed (EraRule "BBODY" era) (CHAIN era)
7273
, Embed (EraRule "TICK" era) (CHAIN era)
@@ -93,10 +94,11 @@ commonTests ::
9394
, State (EraRule "LEDGERS" era) ~ LedgerState era
9495
, Environment (EraRule "BBODY" era) ~ BbodyEnv era
9596
, Signal (EraRule "TICK" era) ~ SlotNo
96-
, Signal (EraRule "BBODY" era) ~ Block BHeaderView era
97+
, Signal (EraRule "BBODY" era) ~ BbodySignal era
9798
, EraRule "POOL" era ~ ShelleyPOOL era
9899
, InjectRuleFailure "POOL" ShelleyPoolPredFailure era
99100
, InjectRuleEvent "POOL" PoolEvent era
101+
, EraBlockHeader (BHeader MockCrypto) era
100102
) =>
101103
[TestTree]
102104
commonTests =

0 commit comments

Comments
 (0)