Skip to content

Commit 68edc41

Browse files
committed
Add 'Byron' to the list of eras making the testing code more readable
1 parent 8d9d968 commit 68edc41

File tree

2 files changed

+11
-18
lines changed
  • ouroboros-consensus-cardano
    • src/cardano-testlib/Test/Consensus/Cardano
    • test/cardano-test/Test/Consensus/Cardano/MiniProtocol/LocalTxSubmission

2 files changed

+11
-18
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ data HardForkSpec =
9999
, conwayHardForkSpec :: (SL.ProtVer, TriggerHardFork)
100100
}
101101

102-
data Era = Shelley
102+
data Era = Byron
103+
| Shelley
103104
| Allegra
104105
| Mary
105106
| Alonzo
@@ -108,6 +109,7 @@ data Era = Shelley
108109
deriving (Show, Eq, Ord, Enum)
109110

110111
selectEra :: Era -> HardForkSpec -> (SL.ProtVer, TriggerHardFork)
112+
selectEra Byron _ = error "Byron is the first era, therefore there is no hard fork spec."
111113
selectEra Shelley HardForkSpec { shelleyHardForkSpec } = shelleyHardForkSpec
112114
selectEra Allegra HardForkSpec { allegraHardForkSpec } = allegraHardForkSpec
113115
selectEra Mary HardForkSpec { maryHardForkSpec } = maryHardForkSpec
@@ -136,6 +138,7 @@ versionZero :: SL.Version
136138
versionZero = SL.natVersion @0
137139

138140
hardForkInto :: Era -> HardForkSpec
141+
hardForkInto Byron = stayInByron
139142
hardForkInto Shelley =
140143
stayInByron
141144
{ shelleyHardForkSpec = (SL.ProtVer versionZero 0, TriggerHardForkAtEpoch 0) }

ouroboros-consensus-cardano/test/cardano-test/Test/Consensus/Cardano/MiniProtocol/LocalTxSubmission/Server.hs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import Test.Consensus.Cardano.MiniProtocol.LocalTxSubmission.ByteStrin
3939
import Test.Consensus.Cardano.ProtocolInfo
4040
(ByronSlotLengthInSeconds (..), Era (..),
4141
ShelleySlotLengthInSeconds (..), hardForkInto,
42-
mkSimpleTestProtocolInfo, stayInByron)
42+
mkSimpleTestProtocolInfo)
4343
import qualified Test.Consensus.Mempool.Mocked as Mocked
4444
import Test.Consensus.Mempool.Mocked (MockedMempool)
4545
import Test.Tasty (TestTree, testGroup)
@@ -49,37 +49,27 @@ import qualified Test.ThreadNet.Infra.Shelley as Shelley
4949
tests :: TestTree
5050
tests =
5151
testGroup "LocalTxSubmissionServer"
52-
$ [ localServerPassesRegressionTests (stayInByron , 0) ]
53-
<> fmap localServerPassesRegressionTests [(hardForkInto era, fromEnum era + 1) | era <- [Shelley ..]]
54-
-- fromEnum Shelley == 0, hence the '+ 1' to account for the Byron era
52+
$ fmap localServerPassesRegressionTests [Byron ..]
5553
where
56-
eraName 0 = "Byron"
57-
eraName 1 = "Shelley"
58-
eraName 2 = "Allegra"
59-
eraName 3 = "Mary"
60-
eraName 4 = "Alonzo"
61-
eraName 5 = "Babbage"
62-
eraName 6 = "Conway"
63-
eraName i = error $ "Unknown era index: " ++ show i
64-
65-
localServerPassesRegressionTests (hardForkSpec, i) =
66-
testCase ("Passes the regression tests (" ++ eraName i ++ ")") $ do
54+
localServerPassesRegressionTests era =
55+
testCase ("Passes the regression tests (" ++ show era ++ ")") $ do
6756
let
6857
pInfo :: ProtocolInfo (CardanoBlock StandardCrypto)
6958
pInfo = mkSimpleTestProtocolInfo
7059
(Shelley.DecentralizationParam 1)
7160
(Consensus.SecurityParam 10)
7261
(ByronSlotLengthInSeconds 1)
7362
(ShelleySlotLengthInSeconds 1)
74-
hardForkSpec
63+
(hardForkInto era)
64+
7565
eraIndex = index_NS
7666
. Telescope.tip
7767
. getHardForkState
7868
. hardForkLedgerStatePerEra
7969
. ledgerState
8070
$ pInfoInitLedger pInfo
8171

82-
eraIndex @=? i
72+
eraIndex @=? fromEnum era
8373

8474
mempool <- Mocked.openMockedMempool (Mempool.mkCapacityBytesOverride 100_000) -- We don't want the mempool to fill up during these tests.
8575
nullTracer -- Use 'show >$< stdoutTracer' for debugging.

0 commit comments

Comments
 (0)