@@ -112,7 +112,7 @@ waitForEpochs
112
112
-> EpochInterval -- ^ Number of epochs to wait
113
113
-> m EpochNo -- ^ The epoch number reached
114
114
waitForEpochs epochStateView interval = withFrozenCallStack $ do
115
- void $ watchEpochStateUpdate epochStateView interval $ \ _ -> pure Nothing
115
+ void $ watchEpochStateUpdate epochStateView interval $ \ _ -> pure ( ConditionNotMet , () )
116
116
getCurrentEpochNo epochStateView
117
117
118
118
-- | Wait for the requested number of blocks
@@ -129,12 +129,12 @@ waitForBlocks epochStateView numberOfBlocks = withFrozenCallStack $ do
129
129
BlockNo startingBlockNumber <- getBlockNumber epochStateView
130
130
H. note_ $ " Current block number: " <> show startingBlockNumber <> " . "
131
131
<> " Waiting for " <> show numberOfBlocks <> " blocks"
132
- H. noteShowM . H. nothingFailM . fmap (fmap BlockNo ) $
132
+ H. noteShowM . fmap (BlockNo . snd ) $
133
133
watchEpochStateUpdate epochStateView (EpochInterval maxBound ) $ \ (_, _, BlockNo blockNumber) ->
134
134
pure $
135
135
if blockNumber >= startingBlockNumber + numberOfBlocks
136
- then Just blockNumber
137
- else Nothing
136
+ then ( ConditionMet , blockNumber)
137
+ else ( ConditionNotMet , blockNumber)
138
138
139
139
data TestnetWaitPeriod
140
140
= WaitForEpochs EpochInterval
@@ -268,21 +268,23 @@ watchEpochStateUpdate
268
268
:: forall m a . (HasCallStack , MonadIO m , MonadTest m , MonadAssertion m )
269
269
=> EpochStateView -- ^ The info to access the epoch state
270
270
-> EpochInterval -- ^ The maximum number of epochs to wait
271
- -> ((AnyNewEpochState , SlotNo , BlockNo ) -> m (Maybe a )) -- ^ The guard function (@Just@ if the condition is met, @Nothing@ otherwise)
272
- -> m (Maybe a )
271
+ -> ((AnyNewEpochState , SlotNo , BlockNo ) -> m (LedgerStateCondition , a ))
272
+ -- ^ The callback executed on every new epoch state, stops the execution when 'ConditionMet' is returned as
273
+ -- a first argument of a tuple
274
+ -> m (LedgerStateCondition , a )
273
275
watchEpochStateUpdate epochStateView (EpochInterval maxWait) f = withFrozenCallStack $ do
274
276
AnyNewEpochState _ newEpochState <- getEpochState epochStateView
275
277
let EpochNo currentEpoch = L. nesEL newEpochState
276
278
go $ currentEpoch + fromIntegral maxWait
277
279
where
278
- go :: Word64 -> m (Maybe a )
280
+ go :: Word64 -> m (LedgerStateCondition , a )
279
281
go timeout = do
280
282
newEpochStateDetails@ (AnyNewEpochState _ newEpochState', _, _) <- getEpochStateDetails epochStateView pure
281
283
let EpochNo currentEpoch = L. nesEL newEpochState'
282
284
f newEpochStateDetails >>= \ case
283
- Just result -> pure ( Just result)
284
- Nothing
285
- | currentEpoch > timeout -> pure Nothing
285
+ r @ ( ConditionMet , _) -> pure r
286
+ r @ ( ConditionNotMet , _)
287
+ | currentEpoch > timeout -> pure r
286
288
| otherwise -> do
287
289
H. threadDelay 300_000
288
290
go timeout
@@ -523,25 +525,21 @@ assertNewEpochState
523
525
-> value -- ^ The expected value to check in the epoch state.
524
526
-> m ()
525
527
assertNewEpochState epochStateView sbe maxWait lens expected = withFrozenCallStack $ do
526
- mStateView <- watchEpochStateUpdate epochStateView maxWait (const checkEpochState)
527
- when (isNothing mStateView) $ do
528
- val <- getFromEpochStateForEra
529
- -- there's a tiny tiny chance that the value has changed since 'watchEpochStateUpdate'
530
- -- so check it again
531
- if val == expected
532
- then pure ()
533
- else H. failMessage callStack $ unlines
534
- [ " assertNewEpochState: expected value not reached within the time frame."
535
- , " Expected value: " <> show expected
536
- , " Actual value: " <> show val
537
- ]
528
+ (cond, val) <- watchEpochStateUpdate epochStateView maxWait (const checkEpochState)
529
+ when (cond == ConditionNotMet ) $ do
530
+ H. failMessage callStack $ unlines
531
+ [ " assertNewEpochState: expected value not reached within the time frame."
532
+ , " Expected value: " <> show expected
533
+ , " Actual value: " <> show val
534
+ ]
538
535
where
539
536
checkEpochState
540
537
:: HasCallStack
541
- => m (Maybe () )
538
+ => m (LedgerStateCondition , value )
542
539
checkEpochState = withFrozenCallStack $ do
543
540
val <- getFromEpochStateForEra
544
- pure $ if val == expected then Just () else Nothing
541
+ let cond = if val == expected then ConditionMet else ConditionNotMet
542
+ pure (cond, val)
545
543
546
544
getFromEpochStateForEra
547
545
:: HasCallStack
0 commit comments