-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a
Test.Util.HeaderValidation
module
... which contains an `AddBogusTime` type class, which allows to add bogus times to headers. This type class and its instances are meant to be used in test code.
- Loading branch information
Showing
4 changed files
with
55 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
ouroboros-consensus/src/unstable-consensus-testlib/Test/Util/HeaderValidation.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE TypeSynonymInstances #-} | ||
|
||
module Test.Util.HeaderValidation ( | ||
-- * Bogus time | ||
AddBogusTime | ||
, addBogusTime | ||
, addBogusTimeToFragment | ||
) where | ||
|
||
import Cardano.Slotting.Time (RelativeTime (..)) | ||
import Data.Typeable (Typeable) | ||
import Ouroboros.Consensus.Block (Header) | ||
import Ouroboros.Consensus.HeaderValidation (HeaderWithTime (..)) | ||
import Ouroboros.Network.AnchoredFragment (AnchoredFragment) | ||
import qualified Ouroboros.Network.AnchoredFragment as AF | ||
|
||
{------------------------------------------------------------------------------- | ||
Bogus time | ||
-------------------------------------------------------------------------------} | ||
|
||
-- REVIEW: I'm not sure about the name of this type class, and how safe it is to use it in testing code. What if suddenly a test decides to rely on the header's time? | ||
class AddBogusTime blk where | ||
addBogusTime :: | ||
Header blk | ||
-> HeaderWithTime blk | ||
|
||
-- REVIEW: I even wonder if this instance should be defined here and | ||
-- at all: there might be use cases in which the 'TestBlock's are used | ||
-- in tests that depend on the header having a meaningful time | ||
-- associated with them. | ||
-- | ||
instance AddBogusTime blk where | ||
addBogusTime testHeader = HeaderWithTime { | ||
hwtHeader = testHeader | ||
, hwtSlotRelativeTime = RelativeTime (error "Header time should not be used!") | ||
} | ||
|
||
addBogusTimeToFragment :: (AF.HasHeader (Header blk), Typeable blk) | ||
=> AnchoredFragment (Header blk) | ||
-> AnchoredFragment (HeaderWithTime blk) | ||
addBogusTimeToFragment = AF.mapAnchoredFragment addBogusTime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters