Skip to content

Commit ea904de

Browse files
carbolymerJimbo4350
authored andcommitted
Fix liftToIntegration to report the exception location to Hedgehog
1 parent 7587cd3 commit ea904de

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

cardano-testnet/src/Testnet/Start/Cardano.hs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
{-# LANGUAGE OverloadedStrings #-}
77
{-# LANGUAGE ScopedTypeVariables #-}
88
{-# LANGUAGE TupleSections #-}
9+
{-# LANGUAGE TypeApplications #-}
910
{-# LANGUAGE TypeFamilies #-}
1011
{-# LANGUAGE TypeOperators #-}
1112

@@ -32,15 +33,18 @@ import Cardano.Api
3233
import Cardano.Api.Byron (GenesisData (..))
3334
import qualified Cardano.Api.Byron as Byron
3435

36+
import Cardano.Node.Configuration.Topology (RemoteAddress (..))
37+
import qualified Cardano.Node.Configuration.Topology as Direct
3538
import qualified Cardano.Node.Configuration.TopologyP2P as P2P
3639
import Cardano.Prelude (canonicalEncodePretty)
3740
import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPoint (..))
3841

3942
import Prelude hiding (lines)
4043

4144
import Control.Concurrent (threadDelay)
42-
import Control.Monad
45+
import Control.Monad
4346
import Control.Monad.Catch
47+
import Control.Monad.Trans.Resource (MonadResource, getInternalState)
4448
import Data.Aeson
4549
import qualified Data.Aeson.Encode.Pretty as A
4650
import qualified Data.ByteString.Lazy as LBS
@@ -61,6 +65,7 @@ import Testnet.Components.Configuration
6165
import qualified Testnet.Defaults as Defaults
6266
import Testnet.Filepath
6367
import Testnet.Handlers (interruptNodesOnSigINT)
68+
import Testnet.Orphans ()
6469
import Testnet.Process.RunIO (execCli', execCli_, liftIOAnnotated, mkExecConfig)
6570
import Testnet.Property.Assert (assertChainExtended, assertExpectedSposInLedgerState)
6671
import Testnet.Runtime as TR
@@ -69,13 +74,12 @@ import Testnet.Types as TR hiding (shelleyGenesis)
6974

7075
import qualified Hedgehog.Extras as H
7176
import qualified Hedgehog.Extras.Stock.IO.Network.Port as H
77+
import Hedgehog.Internal.Property (failException)
7278

73-
74-
import RIO (RIO(..),runRIO, throwString, MonadUnliftIO)
75-
import Control.Monad.Trans.Resource (getInternalState, MonadResource)
76-
import Testnet.Orphans ()
77-
import RIO.Orphans (ResourceMap)
78-
import UnliftIO.Async
79+
import RIO (MonadUnliftIO, RIO (..), runRIO, throwString)
80+
import RIO.Orphans (ResourceMap)
81+
import UnliftIO.Async
82+
import UnliftIO.Exception (stringException)
7983

8084

8185
-- | There are certain conditions that need to be met in order to run
@@ -88,10 +92,10 @@ testMinimumConfigurationRequirements options = withFrozenCallStack $ do
8892
when (cardanoNumPools options < 1) $ do
8993
throwString "Need at least one SPO node to produce blocks, but got none."
9094

91-
liftToIntegration :: HasCallStack => RIO ResourceMap a -> H.Integration a
92-
liftToIntegration r = do
93-
rMap <- lift $ lift getInternalState
94-
liftIOAnnotated $ runRIO rMap r
95+
liftToIntegration :: HasCallStack => RIO ResourceMap a -> H.Integration a
96+
liftToIntegration r = do
97+
rMap <- lift $ lift getInternalState
98+
catch @_ @SomeException (runRIO rMap r) (withFrozenCallStack $ failException . toException . stringException . displayException)
9599

96100
createTestnetEnv :: ()
97101
=> HasCallStack
@@ -218,7 +222,7 @@ createTestnetEnv
218222
-- > ├── configuration.json
219223
-- > ├── current-stake-pools.json
220224
-- > └── module
221-
cardanoTestnet
225+
cardanoTestnet
222226
:: HasCallStack
223227
=> MonadUnliftIO m
224228
=> MonadResource m
@@ -244,8 +248,8 @@ cardanoTestnet
244248
shelleyGenesisFile = tmpAbsPath </> "shelley-genesis.json"
245249

246250
sBytes <- liftIOAnnotated (LBS.readFile shelleyGenesisFile)
247-
shelleyGenesis@ShelleyGenesis{sgNetworkMagic}
248-
<- case eitherDecode sBytes of
251+
shelleyGenesis@ShelleyGenesis{sgNetworkMagic}
252+
<- case eitherDecode sBytes of
249253
Right sg -> return sg
250254
Left err -> throwString $ "Could not decode shelley genesis file: " <> shelleyGenesisFile <> " Error: " <> err
251255
let testnetMagic :: Int = fromIntegral sgNetworkMagic
@@ -333,8 +337,8 @@ cardanoTestnet
333337

334338
-- Update start time in Byron genesis file
335339
eByron <- runExceptT $ Byron.readGenesisData byronGenesisFile
336-
(byronGenesis', _byronHash) <-
337-
case eByron of
340+
(byronGenesis', _byronHash) <-
341+
case eByron of
338342
Right bg -> return bg
339343
Left err -> throwString $ "Could not read byron genesis data from file: " <> byronGenesisFile <> " Error: " <> show err
340344
let byronGenesis = byronGenesis'{gdStartTime = startTime}

0 commit comments

Comments
 (0)