Skip to content

Commit b0dda95

Browse files
Merge #1888
1888: Cleanup hard fork history tests r=edsko a=edsko Co-authored-by: Edsko de Vries <[email protected]>
2 parents 6f55a20 + de25515 commit b0dda95

File tree

6 files changed

+582
-492
lines changed

6 files changed

+582
-492
lines changed

ouroboros-consensus/ouroboros-consensus.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ test-suite test-consensus
261261
Test.Consensus.BlockchainTime.SlotLengths
262262
Test.Consensus.BlockchainTime.WallClock
263263
Test.Consensus.HardFork.History
264+
Test.Consensus.HardFork.Infra
265+
Test.Consensus.HardFork.Summary
264266
Test.Consensus.MiniProtocol.ChainSync.Client
265267
Test.Consensus.MiniProtocol.LocalStateQuery.Server
266268
Test.Consensus.Mempool

ouroboros-consensus/src/Ouroboros/Consensus/Util/Counting.hs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{-# LANGUAGE DeriveFunctor #-}
44
{-# LANGUAGE GADTs #-}
55
{-# LANGUAGE KindSignatures #-}
6+
{-# LANGUAGE RankNTypes #-}
67
{-# LANGUAGE ScopedTypeVariables #-}
78
{-# LANGUAGE StandaloneDeriving #-}
89
{-# LANGUAGE TypeOperators #-}
@@ -11,14 +12,17 @@
1112
module Ouroboros.Consensus.Util.Counting (
1213
Exactly(..)
1314
, AtMost(..)
14-
-- * Working with 'AtMost'
15-
, atMostOne
16-
, atMostInit
1715
-- * Working with 'Exactly'
1816
, exactlyOne
1917
, exactlyHead
2018
, exactlyZip
2119
, exactlyZipAtMost
20+
, exactlyWeaken
21+
, exactlyMapStateM
22+
, exactlyN
23+
-- * Working with 'AtMost'
24+
, atMostOne
25+
, atMostInit
2226
) where
2327

2428
import qualified Data.Foldable as Foldable
@@ -75,6 +79,33 @@ exactlyZipAtMost = \as bs -> go as (Foldable.toList bs)
7579
go ExactlyNil _ = AtMostNil
7680
go (ExactlyCons a as) (b:bs) = AtMostCons (a, b) $ go as bs
7781

82+
exactlyWeaken :: Exactly xs a -> AtMost xs a
83+
exactlyWeaken = go
84+
where
85+
go :: Exactly xs a -> AtMost xs a
86+
go ExactlyNil = AtMostNil
87+
go (ExactlyCons x xs) = AtMostCons x (go xs)
88+
89+
exactlyMapStateM :: forall m xs s a b. Monad m
90+
=> (s -> a -> m (s, b))
91+
-> s
92+
-> Exactly xs a -> m (Exactly xs b)
93+
exactlyMapStateM f = go
94+
where
95+
go :: forall xs'. s -> Exactly xs' a -> m (Exactly xs' b)
96+
go _ ExactlyNil = return ExactlyNil
97+
go s (ExactlyCons a as) = do
98+
(s', b) <- f s a
99+
bs <- go s' as
100+
return $ ExactlyCons b bs
101+
102+
exactlyN :: Word -> (forall xs. Exactly xs () -> a) -> a
103+
exactlyN = go
104+
where
105+
go :: Word -> (forall xs. Exactly xs () -> a) -> a
106+
go 0 k = k ExactlyNil
107+
go n k = go (n - 1) $ \xs -> k (ExactlyCons () xs)
108+
78109
{-------------------------------------------------------------------------------
79110
Working with 'AtMost'
80111
-------------------------------------------------------------------------------}

ouroboros-consensus/test-consensus/Main.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Test.Tasty
55
import qualified Test.Consensus.BlockchainTime.SlotLengths (tests)
66
import qualified Test.Consensus.BlockchainTime.WallClock (tests)
77
import qualified Test.Consensus.HardFork.History (tests)
8+
import qualified Test.Consensus.HardFork.Summary (tests)
89
import qualified Test.Consensus.Mempool (tests)
910
import qualified Test.Consensus.MiniProtocol.ChainSync.Client (tests)
1011
import qualified Test.Consensus.MiniProtocol.LocalStateQuery.Server (tests)
@@ -28,5 +29,6 @@ tests =
2829
, Test.Consensus.Protocol.PBFT.tests
2930
, Test.Consensus.ResourceRegistry.tests
3031
, Test.Consensus.Util.Versioned.tests
32+
, Test.Consensus.HardFork.Summary.tests
3133
, Test.Consensus.HardFork.History.tests
3234
]

0 commit comments

Comments
 (0)