Skip to content

Commit e8675fc

Browse files
jasagredoamesgen
andcommitted
Code review suggestions
Co-authored-by: Alexander Esgen <[email protected]>
1 parent c9a357b commit e8675fc

File tree

7 files changed

+19
-36
lines changed

7 files changed

+19
-36
lines changed

ouroboros-consensus-cardano/ouroboros-consensus-cardano.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ library unstable-cardano-testlib
413413
sop-core,
414414
sop-extras,
415415
strict-sop-core,
416+
text,
416417
unstable-byron-testlib,
417418
unstable-shelley-testlib,
418419

ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/Block.hs

+4-4
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ type ShelleyBasedLedgerEras c =
128128
-- Here we use layout and adjacency to make it obvious that we haven't
129129
-- miscounted.
130130

131-
pattern TagByron :: f ByronBlock -> NS f (CardanoEras c)
131+
pattern TagByron :: f ByronBlock -> NS f (CardanoEras c)
132132
pattern TagShelley :: f (ShelleyBlock (TPraos c) ShelleyEra) -> NS f (CardanoEras c)
133133
pattern TagAllegra :: f (ShelleyBlock (TPraos c) AllegraEra) -> NS f (CardanoEras c)
134-
pattern TagMary :: f (ShelleyBlock (TPraos c) MaryEra) -> NS f (CardanoEras c)
135-
pattern TagAlonzo :: f (ShelleyBlock (TPraos c) AlonzoEra) -> NS f (CardanoEras c)
134+
pattern TagMary :: f (ShelleyBlock (TPraos c) MaryEra ) -> NS f (CardanoEras c)
135+
pattern TagAlonzo :: f (ShelleyBlock (TPraos c) AlonzoEra ) -> NS f (CardanoEras c)
136136
pattern TagBabbage :: f (ShelleyBlock (Praos c) BabbageEra) -> NS f (CardanoEras c)
137-
pattern TagConway :: f (ShelleyBlock (Praos c) ConwayEra) -> NS f (CardanoEras c)
137+
pattern TagConway :: f (ShelleyBlock (Praos c) ConwayEra ) -> NS f (CardanoEras c)
138138

139139
pattern TagByron x = Z x
140140
pattern TagShelley x = S (Z x)

ouroboros-consensus-cardano/src/unstable-cardano-testlib/Test/Consensus/Cardano/Examples.hs

+5-11
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import Data.SOP.BasicFunctors
3333
import Data.SOP.Counting (Exactly (..))
3434
import Data.SOP.Index (Index (..), himap)
3535
import Data.SOP.Strict
36+
import qualified Data.Text as T
3637
import Ouroboros.Consensus.Block
3738
import Ouroboros.Consensus.Byron.ByronHFC
3839
import Ouroboros.Consensus.Byron.Ledger (ByronBlock)
@@ -109,16 +110,11 @@ combineEras perEraExamples = Examples {
109110
inj idx = fmap (fmap (inject $ oracularInjectionIndex exampleStartBounds idx))
110111

111112
perEraExamplesPrefixed :: NP Examples (CardanoEras Crypto)
112-
perEraExamplesPrefixed = hzipWith (\(K eraName) es -> prefixExamples eraName es) perEraNames perEraExamples
113+
perEraExamplesPrefixed = hcmap proxySingle prefixWithEraName perEraExamples
113114
where
114-
perEraNames = K "Byron"
115-
:* K "Shelley"
116-
:* K "Allegra"
117-
:* K "Mary"
118-
:* K "Alonzo"
119-
:* K "Babbage"
120-
:* K "Conway"
121-
:* Nil
115+
prefixWithEraName es = prefixExamples (T.unpack eraName) es
116+
where
117+
eraName = singleEraName $ singleEraInfo es
122118

123119
exampleLedgerConfigCardano ::
124120
Labelled (HardForkLedgerConfig (CardanoEras Crypto))
@@ -200,8 +196,6 @@ instance Inject Examples where
200196
=> Proxy f -> Labelled a -> Labelled b
201197
inj p = map (fmap (inject' p iidx))
202198

203-
204-
205199
{-------------------------------------------------------------------------------
206200
Setup
207201
-------------------------------------------------------------------------------}

ouroboros-consensus-cardano/src/unstable-cardano-testlib/Test/Consensus/Cardano/Generators.hs

+7-17
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import qualified Data.Map.Strict as Map
2727
import Data.Maybe (catMaybes, fromMaybe)
2828
import Data.Proxy
2929
import Data.SOP.BasicFunctors
30+
import Data.SOP.Constraint
3031
import Data.SOP.Counting (Exactly (..))
3132
import Data.SOP.Index
3233
import Data.SOP.NonEmpty
@@ -726,23 +727,12 @@ instance SListI xs => Arbitrary (History.Shape xs) where
726727

727728
instance (CardanoHardForkConstraints c)
728729
=> Arbitrary (PerEraLedgerConfig (CardanoEras c)) where
729-
arbitrary = do
730-
byronPLC <- WrapPartialLedgerConfig <$> arbitrary
731-
shelleyPLC <- WrapPartialLedgerConfig <$> arbitrary
732-
allegraPLC <- WrapPartialLedgerConfig <$> arbitrary
733-
maryPLC <- WrapPartialLedgerConfig <$> arbitrary
734-
alonzoPLC <- WrapPartialLedgerConfig <$> arbitrary
735-
babbagePLC <- WrapPartialLedgerConfig <$> arbitrary
736-
conwayPLC <- WrapPartialLedgerConfig <$> arbitrary
737-
return $ PerEraLedgerConfig $
738-
byronPLC
739-
:* shelleyPLC
740-
:* allegraPLC
741-
:* maryPLC
742-
:* alonzoPLC
743-
:* babbagePLC
744-
:* conwayPLC
745-
:* Nil
730+
arbitrary =
731+
fmap PerEraLedgerConfig . hsequence'
732+
$ hcpure (Proxy @(Compose Arbitrary WrapPartialLedgerConfig)) (Comp arbitrary)
733+
734+
instance Arbitrary (PartialLedgerConfig blk) => Arbitrary (WrapPartialLedgerConfig blk) where
735+
arbitrary = WrapPartialLedgerConfig <$> arbitrary
746736

747737
instance Arbitrary ByronPartialLedgerConfig where
748738
arbitrary = ByronPartialLedgerConfig <$> arbitrary <*> arbitrary

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Config/SecurityParam.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import Quiet
1717
--
1818
-- We interpret this as the number of rollbacks we support.
1919
--
20-
-- i.e., k == 0: we can't roll back at all
21-
-- k == 1: we can roll back at most one block, etc
20+
-- i.e., k == 1: we can roll back at most one block
21+
-- k == 2: we can roll back at most two blocks, etc
2222
--
2323
-- NOTE: This talks about the number of /blocks/ we can roll back, not
2424
-- the number of /slots/.

ouroboros-consensus/src/unstable-consensus-testlib/Test/Ouroboros/Consensus/ChainGenerator/Adversarial.hs

-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ checkAdversarialChain recipe adv = do
171171
let pc = BV.countActivesInV S.notInverted vA
172172
when (C.toVar pc <= 0) $ Exn.throwError BadCount
173173

174-
175174
-- the youngest slot in which the adversarial schedule cannot have accelerated
176175
--
177176
-- (IE @s@ past the first active adversarial slot, or @d@ past the @k+1@st

ouroboros-consensus/src/unstable-consensus-testlib/Test/Ouroboros/Consensus/ChainGenerator/Params.hs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{-# LANGUAGE FlexibleInstances #-}
22
{-# LANGUAGE PatternSynonyms #-}
3-
{-# OPTIONS_GHC -Wno-orphans #-}
43

54
module Test.Ouroboros.Consensus.ChainGenerator.Params (
65
Asc (Asc, UnsafeAsc)

0 commit comments

Comments
 (0)