Skip to content

Commit 1118c89

Browse files
committed
Update onClusterStartup hook to return node config path
1 parent 0203d84 commit 1118c89

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

src/Internal/Contract/Hooks.purs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Hooks =
2323

2424
type ClusterParameters =
2525
{ nodeSocketPath :: FilePath
26+
, nodeConfigPath :: FilePath
2627
}
2728

2829
emptyHooks :: Hooks

src/Internal/Testnet/Contract.purs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import Control.Monad.State (State, execState, modify_)
4444
import Control.Monad.Trans.Class (lift)
4545
import Control.Monad.Writer (censor, execWriterT, tell)
4646
import Control.Parallel (parTraverse)
47+
import Ctl.Internal.Contract.Hooks (ClusterParameters)
4748
import Ctl.Internal.Test.ContractTest
4849
( ContractTest(ContractTest)
4950
, ContractTestPlan(ContractTestPlan)
@@ -62,7 +63,7 @@ import Ctl.Internal.Testnet.DistributeFunds
6263
)
6364
import Ctl.Internal.Testnet.DistributeFunds (Tx(Tx)) as DistrFunds
6465
import Ctl.Internal.Testnet.Server
65-
( StartedTestnetCluster
66+
( StartedTestnetCluster(StartedTestnetCluster)
6667
, makeClusterContractEnv
6768
, mkLogging
6869
, startTestnetCluster
@@ -243,14 +244,17 @@ startTestnetContractEnv
243244
startTestnetContractEnv cfg distr cleanupRef = do
244245
_ <- cleanupOnExit cleanupRef
245246
logging@{ logger } <- liftEffect $ mkLogging cfg
246-
cluster <- startTestnetCluster cfg cleanupRef logger
247+
cluster@(StartedTestnetCluster { paths: { nodeSocketPath, nodeConfigPath } }) <-
248+
startTestnetCluster cfg cleanupRef logger
247249
{ env, printLogs, clearLogs } <- makeClusterContractEnv cleanupRef logging
248250
wallets <- mkWallets env cluster
249-
apathize $ liftEffect $
250-
for_ env.hooks.onClusterStartup \onClusterStartup ->
251-
onClusterStartup
252-
{ nodeSocketPath: (unwrap cluster).paths.nodeSocketPath
253-
}
251+
let
252+
clusterParams :: ClusterParameters
253+
clusterParams =
254+
{ nodeSocketPath
255+
, nodeConfigPath
256+
}
257+
apathize $ liftEffect $ for_ env.hooks.onClusterStartup (_ $ clusterParams)
254258
pure
255259
{ cluster
256260
, env

src/Internal/Testnet/Server.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Ctl.Internal.Testnet.Server
22
( Channels
3-
, StartedTestnetCluster(MkStartedTestnetCluster)
3+
, StartedTestnetCluster(StartedTestnetCluster)
44
, startKupo
55
, startOgmios
66
, startTestnetCluster
@@ -103,7 +103,7 @@ type Channels a =
103103
, stdout :: EventSource a
104104
}
105105

106-
newtype StartedTestnetCluster = MkStartedTestnetCluster
106+
newtype StartedTestnetCluster = StartedTestnetCluster
107107
{ ogmios ::
108108
{ process :: ManagedProcess
109109
, channels :: Channels String
@@ -224,7 +224,7 @@ startTestnetCluster cfg cleanupRef logger = do
224224
kupo <- annotateError "Could not start kupo"
225225
$ startKupo' { paths, workdir: workdirAbsolute }
226226

227-
pure $ MkStartedTestnetCluster
227+
pure $ StartedTestnetCluster
228228
{ paths
229229
, ogmios
230230
, kupo

test/Testnet/ClusterParameters.purs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ import Effect.Class (liftEffect)
1616
import Effect.Ref (Ref)
1717
import Effect.Ref as Ref
1818
import Mote (group, test)
19-
import Test.Spec.Assertions (shouldNotEqual)
19+
import Node.FS.Sync (exists)
20+
import Test.Spec.Assertions (shouldNotEqual, shouldReturn)
2021

2122
runTest :: TestPlanM (Aff Unit) Unit
2223
runTest = do
2324
clusterParamsRef <-
2425
liftEffect $ Ref.new
2526
{ nodeSocketPath: mempty
27+
, nodeConfigPath: mempty
2628
}
2729
testTestnetContracts
2830
defaultTestnetConfig
@@ -39,5 +41,8 @@ mkSuite ref = do
3941
withWallets unit \_ -> do
4042
clusterParams <- liftEffect $ Ref.read ref
4143
clusterParams.nodeSocketPath `shouldNotEqual` mempty
44+
clusterParams.nodeConfigPath `shouldNotEqual` mempty
45+
liftEffect (exists clusterParams.nodeSocketPath) `shouldReturn` true
46+
liftEffect (exists clusterParams.nodeConfigPath) `shouldReturn` true
4247
logDebug' $ "ClusterParameters: " <> show clusterParams
4348
pure unit

0 commit comments

Comments
 (0)