25
25
-- them to be).
26
26
module Test.Consensus.HardFork.History (tests ) where
27
27
28
+ import Cardano.Ledger.BaseTypes (StrictMaybe (.. ))
28
29
import Cardano.Slotting.EpochInfo
29
30
import Control.Exception (throw )
30
31
import Control.Monad.Except
@@ -65,11 +66,11 @@ import Test.Util.QuickCheck
65
66
-- General approach:
66
67
--
67
68
-- * Generate a chain of events
68
- -- * Each event records its own 'RelativeTime', 'SlotNo', and 'EpochNo '
69
+ -- * Each event records its own 'RelativeTime', 'SlotNo', 'EpochNo', and 'PerasRoundNo '
69
70
-- * We then construct a 'HF.Summary' from a /prefix/ of this chain
70
71
-- * We then pick an arbitrary event from the (full) chain:
71
72
-- a. If that event is on the prefix of the chain, or within the safe zone, we
72
- -- expect to be able to do any slot/epoch or slot/time conversion, and we
73
+ -- expect to be able to do any slot/epoch, slot/time or Peras round/slot conversion, and we
73
74
-- can easily verify the result by comparing it to the values the 'Event'
74
75
-- itself reports.
75
76
-- b. If the event is outside of safe zone, we expect the conversion to throw
@@ -96,6 +97,7 @@ tests =
96
97
, testProperty " eventWallclockToSlot" eventWallclockToSlot
97
98
, testProperty " epochInfoSlotToEpoch" epochInfoSlotToEpoch
98
99
, testProperty " epochInfoEpochToSlot" epochInfoEpochToSlot
100
+ , testProperty " eventPerasRounNoToSlot" eventPerasRounNoToSlot
99
101
, testProperty " query vs expr" queryVsExprConsistency
100
102
]
101
103
]
@@ -208,6 +210,16 @@ eventWallclockToSlot chain@ArbitraryChain{..} =
208
210
diff :: NominalDiffTime
209
211
diff = arbitraryDiffTime arbitraryParams
210
212
213
+ eventPerasRounNoToSlot :: ArbitraryChain -> Property
214
+ eventPerasRounNoToSlot chain@ ArbitraryChain {.. } =
215
+ testSkeleton chain (HF. perasRoundNoToSlot eventTimePerasRoundNo) $
216
+ \ (startOfPerasRound, _roundLength) ->
217
+ conjoin
218
+ [ eventTimeSlot === HF. addSlots eventTimeSlotInPerasRound startOfPerasRound
219
+ ]
220
+ where
221
+ EventTime {.. } = eventTime arbitraryEvent
222
+
211
223
-- | Composing queries should be equivalent to composing expressions.
212
224
--
213
225
-- This is a regression test. Each expression in a query should be evaluated in
@@ -503,7 +515,13 @@ data EventTime = EventTime
503
515
{ eventTimeSlot :: SlotNo
504
516
, eventTimeEpochNo :: EpochNo
505
517
, eventTimeEpochSlot :: Word64
518
+ -- ^ Relative slot withing the current epoch round,
519
+ -- needed to be able to advance the epoch number
506
520
, eventTimeRelative :: RelativeTime
521
+ , eventTimePerasRoundNo :: PerasRoundNo
522
+ , eventTimeSlotInPerasRound :: Word64
523
+ -- ^ Relative slot withing the current Peras round,
524
+ -- needed to be able to advance the round number
507
525
}
508
526
deriving Show
509
527
@@ -514,6 +532,8 @@ initEventTime =
514
532
, eventTimeEpochNo = EpochNo 0
515
533
, eventTimeEpochSlot = 0
516
534
, eventTimeRelative = RelativeTime 0
535
+ , eventTimePerasRoundNo = PerasRoundNo 0
536
+ , eventTimeSlotInPerasRound = 0
517
537
}
518
538
519
539
-- | Next time slot
@@ -526,6 +546,8 @@ stepEventTime HF.EraParams{..} EventTime{..} =
526
546
, eventTimeRelative =
527
547
addRelTime (getSlotLength eraSlotLength) $
528
548
eventTimeRelative
549
+ , eventTimePerasRoundNo = perasRoundNo'
550
+ , eventTimeSlotInPerasRound = slotInPerasRound'
529
551
}
530
552
where
531
553
epoch' :: EpochNo
@@ -535,6 +557,16 @@ stepEventTime HF.EraParams{..} EventTime{..} =
535
557
then (succ eventTimeEpochNo, 0 )
536
558
else (eventTimeEpochNo, succ eventTimeEpochSlot)
537
559
560
+ perasRoundNo' :: PerasRoundNo
561
+ slotInPerasRound' :: Word64
562
+ args@ (perasRoundNo', slotInPerasRound') =
563
+ case eraPerasRoundLength of
564
+ SNothing -> args
565
+ SJust (PerasRoundLength perasRoundLength) ->
566
+ if succ eventTimeSlotInPerasRound == perasRoundLength
567
+ then (succ eventTimePerasRoundNo, 0 )
568
+ else (eventTimePerasRoundNo, succ eventTimeSlotInPerasRound)
569
+
538
570
{- ------------------------------------------------------------------------------
539
571
Chain model
540
572
-----------------------------------------------------------------------------}
0 commit comments