Skip to content

Commit 97d8491

Browse files
committed
Remove MonadTest constraints from assertion functions
1 parent f7280e5 commit 97d8491

File tree

1 file changed

+21
-23
lines changed
  • cardano-testnet/src/Testnet/Property

1 file changed

+21
-23
lines changed

cardano-testnet/src/Testnet/Property/Assert.hs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import Prelude hiding (lines)
2222

2323
import qualified Control.Concurrent as IO
2424
import Control.Monad
25-
import Control.Monad.Catch (MonadCatch)
2625
import Control.Monad.Trans.Reader (ReaderT)
2726
import Control.Monad.Trans.Resource (ResourceT)
2827
import Data.Aeson (Value, (.:))
@@ -39,17 +38,16 @@ import qualified Data.Time.Clock as DTC
3938
import Data.Type.Equality
4039
import Data.Word (Word8)
4140
import GHC.Stack as GHC
41+
import RIO (throwString)
4242

43-
import Testnet.Process.Run
43+
import Testnet.Process.RunIO
4444
import Testnet.Start.Types
4545

4646
import Hedgehog (MonadTest)
4747
import qualified Hedgehog as H
4848
import Hedgehog.Extras.Internal.Test.Integration (IntegrationState)
4949
import qualified Hedgehog.Extras.Stock.IO.File as IO
50-
import Hedgehog.Extras.Test.Base (failMessage)
5150
import qualified Hedgehog.Extras.Test.Base as H
52-
import qualified Hedgehog.Extras.Test.File as H
5351
import Hedgehog.Extras.Test.Process (ExecConfig)
5452

5553
newlineBytes :: Word8
@@ -65,23 +63,23 @@ fileJsonGrep fp f = do
6563
return $ L.any f jsons
6664

6765
assertByDeadlineIOCustom
68-
:: (MonadTest m, MonadIO m, HasCallStack)
66+
:: (MonadIO m, HasCallStack)
6967
=> String -> DTC.UTCTime -> IO Bool -> m ()
7068
assertByDeadlineIOCustom str deadline f = withFrozenCallStack $ do
71-
success <- H.evalIO f
69+
success <- liftIOAnnotated f
7270
unless success $ do
73-
currentTime <- H.evalIO DTC.getCurrentTime
71+
currentTime <- liftIOAnnotated DTC.getCurrentTime
7472
if currentTime < deadline
7573
then do
76-
H.evalIO $ IO.threadDelay 1_000_000
74+
liftIOAnnotated $ IO.threadDelay 1_000_000
7775
assertByDeadlineIOCustom str deadline f
7876
else do
79-
H.annotateShow currentTime
80-
H.failMessage GHC.callStack $ "Condition not met by deadline: " <> str
77+
throwString $ "Condition not met by deadline: " <> str
8178

8279
-- | A sanity check that confirms that there are the expected number of SPOs in the ledger state
8380
assertExpectedSposInLedgerState
84-
:: (MonadTest m, MonadCatch m, MonadIO m, HasCallStack)
81+
:: HasCallStack
82+
=> MonadIO m
8583
=> FilePath -- ^ Stake pools query output filepath
8684
-> NumPools
8785
-> ExecConfig
@@ -92,21 +90,21 @@ assertExpectedSposInLedgerState output (NumPools numExpectedPools) execConfig =
9290
, "--out-file", output
9391
]
9492

95-
poolSet <- H.evalEither =<< H.evalIO (Aeson.eitherDecodeFileStrict' @(Set PoolId) output)
96-
97-
H.cat output
98-
99-
let numPoolsInLedgerState = Set.size poolSet
100-
unless (numPoolsInLedgerState == numExpectedPools) $
101-
failMessage GHC.callStack
102-
$ unlines [ "Expected number of stake pools not found in ledger state"
103-
, "Expected: ", show numExpectedPools
104-
, "Actual: ", show numPoolsInLedgerState
105-
]
93+
ePoolSet <- liftIOAnnotated (Aeson.eitherDecodeFileStrict' @(Set PoolId) output)
94+
case ePoolSet of
95+
Left err ->
96+
throwString $ "Failed to decode stake pools from ledger state: " <> err
97+
Right poolSet -> do
98+
let numPoolsInLedgerState = Set.size poolSet
99+
unless (numPoolsInLedgerState == numExpectedPools) $
100+
throwString $ unlines
101+
[ "Expected number of stake pooFvls not found in ledger state"
102+
, "Expected: ", show numExpectedPools
103+
, "Actual: ", show numPoolsInLedgerState
104+
]
106105

107106
assertChainExtended
108107
:: HasCallStack
109-
=> H.MonadTest m
110108
=> MonadIO m
111109
=> DTC.UTCTime
112110
-> NodeLoggingFormat

0 commit comments

Comments
 (0)