Skip to content

Commit

Permalink
No need to specify TEST_DATA_PATH env var; consistent location/name f…
Browse files Browse the repository at this point in the history
…or the local cluster configuration. (#4132)

This PR makes integration test suite work without requiring the
environment variable "SHELLEY_TEST_DATA";

On top of it, the naming was made consistent:

**Before:**
"SHELLEY_DATA_PATH", "cardano-node-shelley", "cluster setup dir" etc.

**After:**
- the directory is renamed to
`lib/local-cluster/test/data/cluster-configs`
- the env var is renamed to "LOCAL_CLUSTER_CONFIGS"
- the `Config`'s data type accessor function is `cfgClusterConfigs`
  • Loading branch information
Unisay authored Sep 27, 2023
2 parents 21ab620 + e628452 commit b02c21c
Show file tree
Hide file tree
Showing 624 changed files with 52 additions and 57 deletions.
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ default:
build:
cabal build all

local-cluster $SHELLEY_TEST_DATA="lib/local-cluster/test/data/cardano-node-shelley":
local-cluster $LOCAL_CLUSTER_CONFIGS="lib/local-cluster/test/data/cluster-configs":
nix shell '.#local-cluster' '.#cardano-node' '.#cardano-wallet' -c "local-cluster"

# run wallet-e2e suite against the preprod network
Expand Down
46 changes: 22 additions & 24 deletions lib/local-cluster/lib/Cardano/Wallet/Launch/Cluster.hs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ configurePool tr Config{..} metadataServer recipe = do
(config, genesisData, vd) <-
genNodeConfig
(retag @"pool" @_ @"output" poolDir)
cfgSetupDir
cfgClusterConfigs
(Tagged @"node-name" mempty)
genesisFiles
hardForks
Expand Down Expand Up @@ -633,7 +633,7 @@ configurePool tr Config{..} metadataServer recipe = do
retCert <- issuePoolRetirementCert tr poolDir opPub e
(rawTx, faucetPrv) <-
preparePoolRetirement tr
poolDir cfgSetupDir cfgLastHardFork [retCert]
poolDir cfgClusterConfigs cfgLastHardFork [retCert]
tx <- signTx tr
(retag @"pool" @_ @"output" poolDir)
(retag @"retirement-tx" @_ @"tx-body" rawTx)
Expand Down Expand Up @@ -706,7 +706,7 @@ configurePool tr Config{..} metadataServer recipe = do
preparePoolRegistration
tr
poolDir
cfgSetupDir
cfgClusterConfigs
cfgLastHardFork
ownerPub
certificates
Expand Down Expand Up @@ -936,7 +936,7 @@ data Config = Config
-- ^ Log severity for node.
, cfgClusterDir :: Tagged "cluster" FilePath
-- ^ Root directory for cluster data.
, cfgSetupDir :: Tagged "setup" FilePath
, cfgClusterConfigs:: Tagged "cluster-configs" FilePath
-- ^ Directory containing data for cluster setup.
} deriving stock (Show)

Expand Down Expand Up @@ -968,7 +968,7 @@ unsafePositiveUnitInterval x =
generateGenesis
:: HasCallStack
=> Tagged "cluster" FilePath
-> Tagged "setup" FilePath
-> Tagged "cluster-configs" FilePath
-> [(Address, Coin)]
-> (ShelleyGenesis StandardCrypto -> ShelleyGenesis StandardCrypto)
-- ^ For adding genesis pools and staking in Babbage and later.
Expand Down Expand Up @@ -1130,12 +1130,11 @@ withCluster tr config@Config{..} faucetFunds onClusterStart =
let federalizeNetwork =
over #sgProtocolParams (set ppDL (unsafeUnitInterval 0.25))

faucetAddresses <- readFaucetAddresses cfgSetupDir

faucetAddresses <- readFaucetAddresses cfgClusterConfigs
genesisFiles <-
generateGenesis
cfgClusterDir
cfgSetupDir
cfgClusterConfigs
(adaFunds <> map (,Coin 1_000_000_000_000_000) faucetAddresses)
(if postAlonzo then addGenesisPools else federalizeNetwork)

Expand Down Expand Up @@ -1172,7 +1171,7 @@ withCluster tr config@Config{..} faucetFunds onClusterStart =
cfgLastHardFork
(head ports)
cfgNodeLogging
withBFTNode tr cfgClusterDir cfgSetupDir bftCfg $
withBFTNode tr cfgClusterDir cfgClusterConfigs bftCfg $
\runningBFTNode -> do
extraClusterSetupUsingNode configuredPools runningBFTNode

Expand Down Expand Up @@ -1204,7 +1203,7 @@ withCluster tr config@Config{..} faucetFunds onClusterStart =

-- Needs to happen in the first 20% of the epoch, so we run this first.
moveInstantaneousRewardsTo
tr conn cfgClusterDir cfgSetupDir cfgLastHardFork mirFunds
tr conn cfgClusterDir cfgClusterConfigs cfgLastHardFork mirFunds

-- Submit retirement certs for all pools using the connection to
-- the only running first pool to avoid the certs being rolled
Expand Down Expand Up @@ -1232,8 +1231,7 @@ withCluster tr config@Config{..} faucetFunds onClusterStart =
tr
conn
cfgClusterDir
cfgSetupDir
cfgLastHardFork
cfgClusterConfigs cfgLastHardFork
20
(first (T.unpack . encodeMainnetShelleyAddr) <$> maFunds)

Expand Down Expand Up @@ -1367,7 +1365,7 @@ withBFTNode
-> Tagged "cluster" FilePath
-- ^ Parent cluster state directory.
-- Node data will be created in a subdirectory of this.
-> Tagged "setup" FilePath
-> Tagged "cluster-configs" FilePath
-> NodeParams
-- ^ Parameters used to generate config files.
-> (RunningNode -> IO a)
Expand Down Expand Up @@ -1435,7 +1433,7 @@ _withRelayNode
-> Tagged "cluster" FilePath
-- ^ Parent state directory.
-- Node data will be created in a subdirectory of this.
-> Tagged "setup" FilePath
-> Tagged "cluster-configs" FilePath
-> NodeParams
-- ^ Parameters used to generate config files.
-> (RunningNode -> IO a)
Expand Down Expand Up @@ -1564,7 +1562,7 @@ data GenesisFiles = GenesisFiles
genNodeConfig
:: Tagged "output" FilePath
-- ^ A top-level directory where to put the configuration.
-> Tagged "setup" FilePath
-> Tagged "cluster-configs" FilePath
-> Tagged "node-name" String -- Node name
-> GenesisFiles
-- ^ Genesis block start time
Expand Down Expand Up @@ -1929,7 +1927,7 @@ issueDlgCert tr poolDir stakePub opPub = do
preparePoolRegistration
:: Tracer IO ClusterLog
-> Tagged "pool" FilePath
-> Tagged "setup" FilePath
-> Tagged "cluster-configs" FilePath
-> ClusterEra
-> Tagged "stake-pub" FilePath
-> [FilePath]
Expand Down Expand Up @@ -1962,7 +1960,7 @@ preparePoolRegistration tr poolDir setupDir era stakePub certs pledgeAmt = do
preparePoolRetirement
:: Tracer IO ClusterLog
-> Tagged "pool" FilePath
-> Tagged "setup" FilePath
-> Tagged "cluster-configs" FilePath
-> ClusterEra
-> [Tagged "retirement-cert" FilePath]
-> IO (Tagged "retirement-tx" FilePath, Tagged "faucet-prv" FilePath)
Expand Down Expand Up @@ -2074,7 +2072,7 @@ sendFaucetFundsTo
:: Tracer IO ClusterLog
-> CardanoNodeConn
-> Tagged "cluster" FilePath
-> Tagged "setup" FilePath
-> Tagged "cluster-configs" FilePath
-> ClusterEra
-> [(String, Coin)]
-> IO ()
Expand All @@ -2094,7 +2092,7 @@ sendFaucetAssetsTo
:: Tracer IO ClusterLog
-> CardanoNodeConn
-> Tagged "cluster" FilePath
-> Tagged "setup" FilePath
-> Tagged "cluster-configs" FilePath
-> ClusterEra
-> Int
-- ^ batch size
Expand All @@ -2114,7 +2112,7 @@ sendFaucet
=> Tracer IO ClusterLog
-> CardanoNodeConn
-> Tagged "cluster" FilePath
-> Tagged "setup" FilePath
-> Tagged "cluster-configs" FilePath
-> ClusterEra
-> String
-- ^ label for logging
Expand Down Expand Up @@ -2202,7 +2200,7 @@ moveInstantaneousRewardsTo
=> Tracer IO ClusterLog
-> CardanoNodeConn
-> Tagged "cluster" FilePath
-> Tagged "setup" FilePath
-> Tagged "cluster-configs" FilePath
-> ClusterEra
-> [(Credential, Coin)]
-> IO ()
Expand Down Expand Up @@ -2363,7 +2361,7 @@ prepareKeyRegistration tr Config{..} = do
let stakePub = Tagged @"stake-pub"
$ untag cfgClusterDir </> "pre-registered-stake.pub"
Aeson.encodeFile (untag stakePub) preRegisteredStakeKey
(faucetInput, faucetPrv) <- takeFaucet cfgSetupDir
(faucetInput, faucetPrv) <- takeFaucet cfgClusterConfigs
cert <- issueStakeVkCert
tr outputDir (Tagged @"prefix" "pre-registered") stakePub
sink <- genSinkAddress tr outputDir Nothing
Expand Down Expand Up @@ -2467,7 +2465,7 @@ submitTx tr conn name signedTx =
-- transaction.
takeFaucet
:: HasCallStack
=> Tagged "setup" FilePath
=> Tagged "cluster-configs" FilePath
-> IO (Tagged "tx-in" String, Tagged "faucet-prv" FilePath)
takeFaucet setupDir = do
i <- modifyMVar faucetIndex (\i -> pure (i + 1, i))
Expand All @@ -2484,7 +2482,7 @@ takeFaucet setupDir = do
let signingKey = basename <> ".shelley.key"
pure (Tagged @"tx-in" txin, Tagged @"faucet-prv" signingKey)

readFaucetAddresses :: HasCallStack => Tagged "setup" FilePath -> IO [Address]
readFaucetAddresses :: HasCallStack => Tagged "cluster-configs" FilePath -> IO [Address]
readFaucetAddresses setupDir = do
let faucetDataPath = untag setupDir </> "faucet-addrs"
allFileNames <- listDirectory faucetDataPath
Expand Down
16 changes: 8 additions & 8 deletions lib/local-cluster/lib/Service.hs
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ main = withUtf8 $ do
cfgNodeLogging <-
Cluster.logFileConfigFromEnv
(Just (Cluster.clusterEraToString clusterEra))
cfgSetupDir <- getShelleyTestDataPath
cfgClusterConfigs <- getClusterConfigsPath
let clusterCfg = Cluster.Config
{ cfgStakePools = Cluster.defaultPoolConfigs
, cfgLastHardFork = clusterEra
, cfgNodeLogging
, cfgClusterDir = Tagged clusterPath
, cfgSetupDir
, cfgClusterConfigs
}
Cluster.withCluster stdoutTextTracer clusterCfg faucetFunds $ \node -> do
clusterDir <- Path.parseAbsDir clusterPath
Expand Down Expand Up @@ -241,11 +241,11 @@ main = withUtf8 $ do
, let (xPub, _xPrv) = deriveShelleyRewardAccount (SomeMnemonic m)
]
}
-- | Returns the shelley test data path, which is usually relative to the
-- package sources, but can be overridden by the @SHELLEY_TEST_DATA@ environment
-- | Returns a path to the local cluster configuration, which is usually relative to the
-- package sources, but can be overridden by the @LOCAL_CLUSTER_CONFIGS@ environment
-- variable.
getShelleyTestDataPath :: IO (Tagged "setup" FilePath)
getShelleyTestDataPath =
lookupEnvNonEmpty "SHELLEY_TEST_DATA" <&> Tagged . \case
Nothing -> $(getTestData) </> "cardano-node-shelley"
getClusterConfigsPath :: IO (Tagged "cluster-configs" FilePath)
getClusterConfigsPath =
lookupEnvNonEmpty "LOCAL_CLUSTER_CONFIGS" <&> Tagged . \case
Nothing -> $(getTestData) </> "cluster-configs"
Just fp -> fp
Loading

0 comments on commit b02c21c

Please sign in to comment.