Skip to content

Commit

Permalink
Remove cluster config instance duplicated definition
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed May 3, 2024
1 parent aeaf62a commit 7d099a0
Showing 1 changed file with 48 additions and 61 deletions.
109 changes: 48 additions & 61 deletions lib/integration/framework/Test/Integration/Framework/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,31 @@ import Cardano.Wallet.Faucet
)
import Cardano.Wallet.Launch.Cluster
( ClusterEra (..)
, Config
, FaucetFunds (..)
, FileOf (..)
, LogFileConfig (..)
, RunningNode (..)
, clusterEraFromEnv
, defaultPoolConfigs
, runClusterM
, sendFaucetAssetsTo
, withCluster
, withFaucet
, withSMASH
)
import Cardano.Wallet.Launch.Cluster.Config
( Config (..)
, TestnetMagic
, testnetMagicToNatural
)
import Cardano.Wallet.Launch.Cluster.Env
( nodeOutputFileFromEnv
( localClusterConfigsFromEnv
, nodeOutputFileFromEnv
)
import Cardano.Wallet.Launch.Cluster.FileOf
( DirOf (..)
, toFilePath, mkRelDirOf
, mkRelDirOf
, toFilePath
)
import Cardano.Wallet.Network.Implementation.Ouroboros
( tunedForMainnetPipeliningStrategy
Expand Down Expand Up @@ -219,7 +227,6 @@ import qualified Cardano.Pool.DB as Pool
import qualified Cardano.Pool.DB.Layer as Pool
import qualified Cardano.Wallet.Api.Link as Link
import qualified Cardano.Wallet.Faucet as Faucet
import qualified Cardano.Wallet.Launch.Cluster as Cluster
import qualified Data.Text as T

-- | Do all the program setup required for integration tests, create a temporary
Expand All @@ -246,11 +253,10 @@ withTestsSetup action = do
let clusterDir = DirOf $ absDir testDir
withTracers clusterDir $ action clusterDir

mkFaucetFunds :: Cluster.TestnetMagic -> FaucetM FaucetFunds
mkFaucetFunds :: TestnetMagic -> FaucetM FaucetFunds
mkFaucetFunds testnetMagic = do
let networkTag =
NetworkTag . fromIntegral
$ Cluster.testnetMagicToNatural testnetMagic
NetworkTag . fromIntegral $ testnetMagicToNatural testnetMagic
shelleyFunds <- Faucet.shelleyFunds shelleyTestnet
byronFunds <- Faucet.byronFunds networkTag
icarusFunds <- Faucet.icarusFunds networkTag
Expand Down Expand Up @@ -282,7 +288,7 @@ mkFaucetFunds testnetMagic = do
}

data TestingCtx = TestingCtx
{ testnetMagic :: Cluster.TestnetMagic
{ testnetMagic :: TestnetMagic
, testDir :: DirOf "cluster"
, tr :: Tracer IO TestsLog
, tracers :: Tracers IO
Expand Down Expand Up @@ -317,10 +323,9 @@ recordPoolGarbageCollectionEvents TestingCtx{..} eventsRef =

withServer
:: TestingCtx
-> DirOf "cluster-configs"
-> Config
-> FaucetFunds
-> Pool.DBDecorator IO
-> Maybe (FileOf "node-output")
-> ( T.Text
-> CardanoNodeConn
-> NetworkParameters
Expand All @@ -330,28 +335,13 @@ withServer
-> IO ExitCode
withServer
ctx@TestingCtx{..}
clusterConfigs
clusterConfig
faucetFunds
dbDecorator
nodeOutputFile
onReady =
bracketTracer' tr "withServer" $ do
let tr' = contramap MsgCluster tr
era <- clusterEraFromEnv
let tr' = cfgTracer clusterConfig
withSMASH tr' (toFilePath . absDirOf $ testDir) $ \smashUrl -> do
let clusterConfig =
Cluster.Config
{ cfgStakePools = Cluster.defaultPoolConfigs
, cfgLastHardFork = era
, cfgNodeLogging = LogFileConfig Info Nothing Info
, cfgClusterDir = testDir
, cfgClusterConfigs = clusterConfigs
, cfgTestnetMagic = testnetMagic
, cfgShelleyGenesisMods = []
, cfgTracer = tr'
, cfgNodeOutputFile = nodeOutputFile
, cfgRelayNodePath = mkRelDirOf "relay"
}
withCluster clusterConfig faucetFunds
$ onClusterStart
ctx
Expand Down Expand Up @@ -415,29 +405,27 @@ httpManager = do

setupContext
:: TestingCtx
-> Config
-> MVar Context
-> ClientEnv
-> IORef [PoolGarbageCollectionEvent]
-> Maybe (FileOf "node-output")
-> T.Text
-> CardanoNodeConn
-> NetworkParameters
-> URI
-> IO ()
setupContext
TestingCtx{..}
clusterConfig
ctx
faucetClientEnv
poolGarbageCollectionEvents
nodeOutputFile
smashUrl
nodeConnection
networkParameters
baseUrl =
bracketTracer' tr "setupContext" $ do
clusterConfigs <- Cluster.localClusterConfigsFromEnv
faucet <- Faucet.initFaucet faucetClientEnv
let tr' = contramap MsgCluster tr
prometheusUrl <-
let packPort (h, p) =
T.pack h <> ":" <> toText @(Port "Prometheus") p
Expand All @@ -449,22 +437,6 @@ setupContext
traceWith tr $ MsgBaseUrl baseUrl ekgUrl prometheusUrl smashUrl
manager <- httpManager
mintSeaHorseAssetsLock <- newMVar ()

let withConfig =
runClusterM
$ Cluster.Config
{ cfgStakePools = error "cfgStakePools: unused"
, cfgLastHardFork = localClusterEra
, cfgNodeLogging = error "cfgNodeLogging: unused"
, cfgClusterDir = testDir
, cfgClusterConfigs = clusterConfigs
, cfgTestnetMagic = testnetMagic
, cfgShelleyGenesisMods = []
, cfgTracer = tr'
, cfgNodeOutputFile = nodeOutputFile
, cfgRelayNodePath = mkRelDirOf "relay"
}

putMVar
ctx
Context
Expand All @@ -479,7 +451,7 @@ setupContext
, _smashUrl = smashUrl
, _mintSeaHorseAssets = \nPerAddr batchSize c addrs ->
withMVar mintSeaHorseAssetsLock $ \() ->
withConfig
runClusterM clusterConfig
$ sendFaucetAssetsTo
nodeConnection
batchSize
Expand All @@ -491,36 +463,50 @@ withContext testingCtx@TestingCtx{..} action = do
bracketTracer' tr "withContext" $ withFaucet $ \faucetClientEnv -> do
ctx <- newEmptyMVar
nodeOutputFile <- nodeOutputFileFromEnv
clusterConfigs <- Cluster.localClusterConfigsFromEnv
clusterConfigs <- localClusterConfigsFromEnv
poolGarbageCollectionEvents <- newIORef []
faucetFunds <- runFaucetM faucetClientEnv $ mkFaucetFunds testnetMagic

era <- clusterEraFromEnv
let clusterConfig =
Config
{ cfgStakePools = defaultPoolConfigs
, cfgLastHardFork = era
, cfgNodeLogging = LogFileConfig Info Nothing Info
, cfgClusterDir = testDir
, cfgClusterConfigs = clusterConfigs
, cfgTestnetMagic = testnetMagic
, cfgShelleyGenesisMods = []
, cfgTracer = contramap MsgCluster tr
, cfgNodeOutputFile = nodeOutputFile
, cfgRelayNodePath = mkRelDirOf "relay"
}
let dbEventRecorder =
recordPoolGarbageCollectionEvents
testingCtx
poolGarbageCollectionEvents
cluster =
setupContext
testingCtx
clusterConfig
ctx
faucetClientEnv
poolGarbageCollectionEvents
nodeOutputFile
res <-
race
( withServer
testingCtx
clusterConfigs
clusterConfig
faucetFunds
dbEventRecorder
nodeOutputFile
cluster
)
(takeMVar ctx >>= bracketTracer' tr "spec" .
(\c -> setupDelegation faucetClientEnv c >> action c))
( takeMVar ctx
>>= bracketTracer' tr "spec"
. (\c -> setupDelegation faucetClientEnv c >> action c)
)
whenLeft res (throwIO . ProcessHasExited "integration")
where
-- | Setup delegation for 'rewardWallet' / 'rewardWalletMnemonics'.
-- \| Setup delegation for 'rewardWallet' / 'rewardWalletMnemonics'.
--
-- Rewards take 4-5 epochs (here ~2 min) to accrue from delegating. By
-- doing this up-front, the rewards are likely available by the time
Expand All @@ -539,11 +525,12 @@ withContext testingCtx@TestingCtx{..} action = do
-- resources for unnecessary restoration.
forM_ mnemonics $ \mw -> runResourceT $ do
w <- walletFromMnemonic ctx mw
_ <- joinStakePool
@('Testnet 0) -- protocol magic doesn't matter
ctx
(SpecificPool pool)
(w, fixturePassphrase)
_ <-
joinStakePool
@('Testnet 0) -- protocol magic doesn't matter
ctx
(SpecificPool pool)
(w, fixturePassphrase)
pure ()

bracketTracer' :: Tracer IO TestsLog -> Text -> IO a -> IO a
Expand Down

0 comments on commit 7d099a0

Please sign in to comment.