Skip to content

Commit b99bb37

Browse files
committed
More refactoring
1 parent d07a2ac commit b99bb37

File tree

5 files changed

+36
-32
lines changed

5 files changed

+36
-32
lines changed

cardano-testnet/src/Testnet/Components/Configuration.hs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import Data.Word (Word64)
5656
import GHC.Stack (HasCallStack)
5757
import qualified GHC.Stack as GHC
5858
import qualified Network.HTTP.Simple as HTTP
59-
import RIO (Exception(..), RIO, throwM)
59+
import RIO (Exception(..), MonadThrow, throwM)
6060
import qualified System.Directory as System
6161
import System.FilePath.Posix (takeDirectory, (</>))
6262

@@ -74,9 +74,11 @@ import qualified Hedgehog.Extras.Stock.Time as DTC
7474
-- | Returns JSON encoded hashes of the era, as well as the hard fork configuration toggle.
7575
createConfigJson :: ()
7676
=> HasCallStack
77+
=> MonadIO m
78+
=> MonadThrow m
7779
=> TmpAbsolutePath
7880
-> ShelleyBasedEra era -- ^ The era used for generating the hard fork configuration toggle
79-
-> RIO env (KeyMap Aeson.Value)
81+
-> m (KeyMap Aeson.Value)
8082
createConfigJson (TmpAbsolutePath tempAbsPath) sbe = GHC.withFrozenCallStack $ do
8183
byronGenesisHash <- getByronGenesisHash $ tempAbsPath </> "byron-genesis.json"
8284
shelleyGenesisHash <- getHash ShelleyEra "ShelleyGenesisHash"
@@ -91,7 +93,7 @@ createConfigJson (TmpAbsolutePath tempAbsPath) sbe = GHC.withFrozenCallStack $ d
9193
, Defaults.defaultYamlHardforkViaConfig sbe
9294
]
9395
where
94-
getHash :: CardanoEra a -> Text.Text -> RIO env (KeyMap Value)
96+
getHash :: MonadIO m => CardanoEra a -> Text.Text -> m (KeyMap Value)
9597
getHash e = getShelleyGenesisHash (tempAbsPath </> Defaults.defaultGenesisFilepath e)
9698

9799
createConfigJsonNoHash :: ()
@@ -102,8 +104,10 @@ createConfigJsonNoHash = Defaults.defaultYamlHardforkViaConfig
102104
-- Generate hashes for genesis.json files
103105

104106
getByronGenesisHash
105-
:: FilePath
106-
-> RIO env (KeyMap Aeson.Value)
107+
:: MonadIO m
108+
=> MonadThrow m
109+
=> FilePath
110+
-> m (KeyMap Aeson.Value)
107111
getByronGenesisHash path = do
108112
e <- runExceptT $ readGenesisData path
109113
case e of
@@ -113,9 +117,10 @@ getByronGenesisHash path = do
113117
pure . singleton "ByronGenesisHash" $ toJSON genesisHash'
114118

115119
getShelleyGenesisHash
116-
:: FilePath
120+
:: MonadIO m
121+
=> FilePath
117122
-> Text
118-
-> RIO env (KeyMap Aeson.Value)
123+
-> m (KeyMap Aeson.Value)
119124
getShelleyGenesisHash path key = do
120125
content <- liftIO $ BS.readFile path
121126
let genesisHash = Crypto.hashWith id content :: Crypto.Hash Crypto.Blake2b_256 BS.ByteString
@@ -128,10 +133,11 @@ startTimeOffsetSeconds = if OS.isWin32 then 90 else 15
128133

129134
-- | A start time and 'ShelleyGenesis' value that are fit to pass to 'cardanoTestnet'
130135
getDefaultShelleyGenesis :: ()
136+
=> MonadIO m
131137
=> AnyShelleyBasedEra
132138
-> Word64 -- ^ The max supply
133139
-> GenesisOptions
134-
-> RIO env ShelleyGenesis
140+
-> m ShelleyGenesis
135141
getDefaultShelleyGenesis asbe maxSupply opts = do
136142
currentTime <- liftIO DTC.getCurrentTime
137143
let startTime = DTC.addUTCTime startTimeOffsetSeconds currentTime
@@ -140,8 +146,9 @@ getDefaultShelleyGenesis asbe maxSupply opts = do
140146
-- | An 'AlonzoGenesis' value that is fit to pass to 'cardanoTestnet'
141147
getDefaultAlonzoGenesis :: ()
142148
=> HasCallStack
149+
=> MonadThrow m
143150
=> ShelleyBasedEra era
144-
-> RIO e AlonzoGenesis
151+
-> m AlonzoGenesis
145152
getDefaultAlonzoGenesis sbe =
146153
case Defaults.defaultAlonzoGenesis sbe of
147154
Right genesis -> return genesis
@@ -161,19 +168,22 @@ numSeededUTxOKeys = 3
161168
-- for logging purposes. No reason for the annotations
162169
-- to be littered within the functions
163170
createSPOGenesisAndFiles
164-
:: CardanoTestnetOptions -- ^ The options to use
171+
:: MonadIO m
172+
=> HasCallStack
173+
=> MonadThrow m
174+
=> CardanoTestnetOptions -- ^ The options to use
165175
-> GenesisOptions
166176
-> TestnetOnChainParams
167177
-> TmpAbsolutePath
168-
-> RIO env FilePath -- ^ Shelley genesis directory
178+
-> m FilePath -- ^ Shelley genesis directory
169179
createSPOGenesisAndFiles
170180
testnetOptions genesisOptions@GenesisOptions{genesisTestnetMagic}
171181
onChainParams
172182
(TmpAbsolutePath tempAbsPath) = GHC.withFrozenCallStack $ do
173183
AnyShelleyBasedEra sbe <- pure cardanoNodeEra
174184

175185
let genesisShelleyDirAbs = takeDirectory inputGenesisShelleyFp
176-
-- error "here 1"
186+
177187
genesisShelleyDir <- liftIO $ System.createDirectoryIfMissing True genesisShelleyDirAbs >> pure genesisShelleyDirAbs
178188
let -- At least there should be a delegator per DRep
179189
-- otherwise some won't be representing anybody
@@ -310,9 +320,11 @@ instance Exception BlockfrostParamsError where
310320
-- into a unified, consistent set of Genesis files
311321
resolveOnChainParams :: ()
312322
=> HasCallStack
323+
=> MonadIO m
324+
=> MonadThrow m
313325
=> TestnetOnChainParams
314326
-> (AlonzoGenesis, ConwayGenesis, ShelleyGenesis)
315-
-> RIO env (AlonzoGenesis, ConwayGenesis, ShelleyGenesis)
327+
-> m (AlonzoGenesis, ConwayGenesis, ShelleyGenesis)
316328
resolveOnChainParams onChainParams geneses = case onChainParams of
317329

318330
DefaultParams -> pure geneses

cardano-testnet/src/Testnet/Orphans.hs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@
22

33
module Testnet.Orphans () where
44

5-
-- import Hedgehog (MonadTest(..))
6-
import RIO (RIO)
5+
import RIO (RIO(..), liftIO)
76

8-
-- Not possible to have
9-
-- instance MonadTest (RIO env) where
10-
-- liftTest = liftRIO . liftTest
11-
-- If you pattern match on the RIO constructor
12-
-- it rightfully complains!
13-
-- what extension is responsible for this?
147
instance MonadFail (RIO env) where
15-
fail = error "TODO: throw exception here then catch it in the liftToIntegration "
8+
fail = liftIO . fail

cardano-testnet/src/Testnet/Process/NewRun.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ execCli' execConfig = GHC.withFrozenCallStack $ execFlex' execConfig "cardano-cl
6363

6464
execCli_
6565
:: HasCallStack
66+
=> MonadIO m
6667
=> [String]
67-
-> RIO env ()
68-
execCli_ = GHC.withFrozenCallStack $ void . execCli
68+
-> m ()
69+
execCli_ = GHC.withFrozenCallStack $ void . liftIO . runRIO () . execCli
6970

7071
execCli
7172
:: HasCallStack

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ createTestnetEnv
224224
-- > ├── configuration.json
225225
-- > ├── current-stake-pools.json
226226
-- > └── module
227-
cardanoTestnet :: HasCallStack
227+
cardanoTestnet
228+
:: HasCallStack
228229
=> CardanoTestnetOptions -- ^ The options to use
229230
-> Conf -- ^ Path to the test sandbox
230231
-> RIO ResourceMap TestnetRuntime
@@ -366,7 +367,7 @@ cardanoTestnet
366367
, "--byron-signing-key", nodePoolKeysDir </> "byron-delegate.key"
367368
]
368369
keys@SpoNodeKeys{poolNodeKeysVrf} = mkTestnetNodeKeyPaths i
369-
-- error "forCuncurrently" -- works!
370+
370371
eRuntime <- runExceptT . retryOnAddressInUseError $
371372
startNode (TmpAbsolutePath tmpAbsPath) nodeName testnetDefaultIpv4Address port testnetMagic $
372373
[ "run"
@@ -376,9 +377,9 @@ cardanoTestnet
376377
]
377378
<> spoNodeCliArgs
378379
<> extraCliArgs nodeOptions
379-
-- error "eRuntime" -- works!
380+
380381
pure $ eRuntime <&> \rt -> rt{poolKeys=mKeys}
381-
-- error "mid cardanoTestnet before 3" -- works!!
382+
382383
let (failedNodes, testnetNodes') = partitionEithers eTestnetNodes
383384
unless (null failedNodes) $ do
384385
error $ "Some nodes failed to start:\n" ++ show (vsep (prettyError <$> failedNodes))
@@ -451,13 +452,10 @@ createAndRunTestnet :: ()
451452
-> H.Integration TestnetRuntime
452453
createAndRunTestnet testnetOptions genesisOptions conf = do
453454
liftToIntegration $ do
454-
-- works error "here"
455455
createTestnetEnv
456456
testnetOptions genesisOptions def
457457
conf
458-
-- works error "here"
459458
cardanoTestnet testnetOptions conf
460-
-- error "here post cardanoTestnet" -- WORKS!
461459

462460
-- | Retry an action when `NodeAddressAlreadyInUseError` gets thrown from an action
463461
retryOnAddressInUseError

cardano-testnet/test/cardano-testnet-test/Cardano/Testnet/Test/SanityCheck.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ hprop_ledger_events_sanity_check = integrationRetryWorkspace 2 "ledger-events-sa
5050

5151
TestnetRuntime{configurationFile, testnetNodes}
5252
<- createAndRunTestnet fastTestnetOptions shelleyOptions conf
53-
-- error "Test failure" -- works
53+
5454
nr@TestnetNode{nodeSprocket} <- H.headM testnetNodes
5555
let socketPath = nodeSocketPath nr
5656

0 commit comments

Comments
 (0)