Skip to content

Commit

Permalink
create-testnet-data: use new node configuration flag
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Sep 26, 2024
1 parent 6d97756 commit 3ffa09e
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 58 deletions.
130 changes: 72 additions & 58 deletions cardano-cli/test/cardano-cli-golden/Test/Golden/CreateTestnetData.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
Expand All @@ -11,10 +12,13 @@ import Cardano.Api.Shelley (ShelleyGenesis (..))
import qualified Cardano.Ledger.Shelley.API as L

import Control.Monad
import Control.Monad.Catch (MonadCatch)
import Control.Monad.Trans.Control (MonadBaseControl)
import Data.List (intercalate, sort)
import qualified Data.Sequence.Strict as Seq
import Data.Word (Word32)
import GHC.Exts (IsList (..))
import GHC.Stack (HasCallStack)
import System.Directory
import System.Directory.Extra (listDirectories)
import System.FilePath
Expand Down Expand Up @@ -83,14 +87,13 @@ tree root = do
-- @cabal test cardano-cli-golden --test-options '-p "/golden create testnet data/"'@
hprop_golden_create_testnet_data :: Property
hprop_golden_create_testnet_data =
golden_create_testnet_data Nothing

-- Execute this test with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden create testnet data with template/"'@
hprop_golden_create_testnet_data_with_template :: Property
hprop_golden_create_testnet_data_with_template =
golden_create_testnet_data $
Just "test/cardano-cli-golden/files/input/shelley/genesis/genesis.spec.json"
let supplyValues = [Nothing, Just "test/cardano-cli-golden/files/input/shelley/genesis/genesis.spec.json"]
in propertyOnce $ forM_ supplyValues $ \shelley ->
H.moduleWorkspace "tmp" $ \tempDir -> do
golden_create_testnet_data
tempDir
shelley
(Just "test/cardano-cli-golden/files/input/shelley/genesis/node-config.json")

-- | Semaphore protecting against locked file error, when running properties concurrently.
createTestnetDataOutSem :: FileSem
Expand All @@ -100,56 +103,67 @@ createTestnetDataOutSem = newFileSem "test/cardano-cli-golden/files/golden/conwa
-- | This test tests the non-transient case, i.e. it maximizes the files
-- that can be written to disk.
golden_create_testnet_data
:: ()
=> Maybe FilePath
-- ^ The path to the shelley template use, if any
-> Property
golden_create_testnet_data mShelleyTemplate =
propertyOnce $ moduleWorkspace "tmp" $ \tempDir -> do
let outputDir = tempDir </> "out"
templateArg :: [String] =
case mShelleyTemplate of
Nothing -> []
Just shelleyTemplate -> ["--spec-shelley", shelleyTemplate]
numStakeDelegs = 4

void $
execCardanoCLI $
mkArguments outputDir <> ["--stake-delegators", show numStakeDelegs] <> templateArg

generated <- liftIO $ tree outputDir
-- Sort output for stability, and make relative to avoid storing
-- a path that changes everytime (/tmp/nix-shell.[0-9]+/tmp-Test...)
let generated' = intercalate "\n" $ sort $ map (makeRelative outputDir) generated
-- On Windows, the path separator is backslash. Normalize it to slash, like on Unix
-- so that this test can run on all platforms.
generated'' = map (\c -> if c == '\\' then '/' else c) generated'
void $ H.note generated''

bracketSem createTestnetDataOutSem $
H.diffVsGoldenFile generated''

shelleyGenesis :: ShelleyGenesis StandardCrypto <-
H.readJsonFileOk $ outputDir </> "shelley-genesis.json"

sgNetworkMagic shelleyGenesis H.=== networkMagic
length (L.sgsPools $ sgStaking shelleyGenesis) H.=== numPools

forM_ (L.sgsPools $ sgStaking shelleyGenesis) $ \pool ->
Seq.length (L.ppRelays pool) H.=== 1

actualNumDReps <- liftIO $ listDirectories $ outputDir </> "drep-keys"
length actualNumDReps H.=== numDReps

actualNumUtxoKeys <- liftIO $ listDirectories $ outputDir </> "utxo-keys"
length actualNumUtxoKeys H.=== numUtxoKeys

conwayGenesis :: ConwayGenesis StandardCrypto <-
H.readJsonFileOk $ outputDir </> "conway-genesis.json"

length (cgInitialDReps conwayGenesis) H.=== numDReps

length (cgDelegs conwayGenesis) H.=== numStakeDelegs
:: (MonadBaseControl IO m, H.MonadTest m, MonadIO m, MonadCatch m, HasCallStack)
=> FilePath
-- ^ Temporary directory to use
-> Maybe FilePath
-- ^ The path to the shelley template to use, if any
-> Maybe FilePath
-- ^ The path to the node configuration to use, if any
-> m ()
golden_create_testnet_data tempDir mShelleyTemplate mNodeConfigTemplate = do
let outputDir = tempDir </> "out"
shelleyTemplateArg :: [String] =
case mShelleyTemplate of
Nothing -> []
Just shelleyTemplate -> ["--spec-shelley", shelleyTemplate]
nodeConfigTemplateArg :: [String] =
case mNodeConfigTemplate of
Nothing -> []
Just nodeConfigTemplate -> ["--node-configuration", nodeConfigTemplate]
numStakeDelegs = 4

void $
execCardanoCLI $
mkArguments
outputDir
<> ["--stake-delegators", show numStakeDelegs]
<> shelleyTemplateArg
<> nodeConfigTemplateArg

generated <- liftIO $ tree outputDir
-- Sort output for stability, and make relative to avoid storing
-- a path that changes everytime (/tmp/nix-shell.[0-9]+/tmp-Test...)
let generated' = intercalate "\n" $ sort $ map (makeRelative outputDir) generated
-- On Windows, the path separator is backslash. Normalize it to slash, like on Unix
-- so that this test can run on all platforms.
generated'' = map (\c -> if c == '\\' then '/' else c) generated'
void $ H.note generated''

bracketSem createTestnetDataOutSem $
H.diffVsGoldenFile generated''

shelleyGenesis :: ShelleyGenesis StandardCrypto <-
H.readJsonFileOk $ outputDir </> "shelley-genesis.json"

sgNetworkMagic shelleyGenesis H.=== networkMagic
length (L.sgsPools $ sgStaking shelleyGenesis) H.=== numPools

forM_ (L.sgsPools $ sgStaking shelleyGenesis) $ \pool ->
Seq.length (L.ppRelays pool) H.=== 1

actualNumDReps <- liftIO $ listDirectories $ outputDir </> "drep-keys"
length actualNumDReps H.=== numDReps

actualNumUtxoKeys <- liftIO $ listDirectories $ outputDir </> "utxo-keys"
length actualNumUtxoKeys H.=== numUtxoKeys

conwayGenesis :: ConwayGenesis StandardCrypto <-
H.readJsonFileOk $ outputDir </> "conway-genesis.json"

length (cgInitialDReps conwayGenesis) H.=== numDReps

length (cgDelegs conwayGenesis) H.=== numStakeDelegs

-- Execute this test with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden create testnet data deleg non deleg/"'@
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
alonzo-genesis.json
config.json
conway-genesis.json
delegate-keys/README.md
delegate-keys/delegate1/kes.skey
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"EnableLogMetrics": false,
"EnableLogging": true,
"EnableP2P": false,
"ExperimentalHardForksEnabled": true,
"ExperimentalProtocolsEnabled": true,
"LastKnownBlockVersion-Alt": 0,
"LastKnownBlockVersion-Major": 2,
"LastKnownBlockVersion-Minor": 0,
"MaxConcurrencyBulkSync": 1,
"MaxConcurrencyDeadline": 2,
"PBftSignatureThreshold": 0.6,
"Protocol": "Cardano",
"RequiresNetworkMagic": "RequiresMagic",
"SocketPath": "db/node.socket",
"TestShelleyHardForkAtEpoch": 0,
"TraceBlockFetchClient": false,
"TraceBlockFetchDecisions": false,
"TraceBlockFetchProtocol": false,
"TraceBlockFetchProtocolSerialised": false,
"TraceBlockFetchServer": false,
"TraceBlockchainTime": true,
"TraceChainDb": true,
"TraceChainSyncBlockServer": false,
"TraceChainSyncClient": false,
"TraceChainSyncHeaderServer": false,
"TraceChainSyncProtocol": false,
"TraceConnectionManager": true,
"TraceDnsResolver": true,
"TraceDnsSubscription": true,
"TraceErrorPolicy": true,
"TraceForge": true,
"TraceHandshake": false,
"TraceIpSubscription": true,
"TraceLocalChainSyncProtocol": false,
"TraceLocalConnectionManager": false,
"TraceLocalErrorPolicy": true,
"TraceLocalHandshake": false,
"TraceLocalRootPeers": true,
"TraceLocalServer": false,
"TraceLocalTxSubmissionProtocol": false,
"TraceLocalTxSubmissionServer": false,
"TraceMempool": true,
"TraceMux": false,
"TracePeerSelection": true,
"TracePeerSelectionActions": true,
"TracePublicRootPeers": true,
"TraceServer": true,
"TraceTxInbound": false,
"TraceTxOutbound": false,
"TraceTxSubmissionProtocol": false,
"TurnOnLogMetrics": false,
"defaultBackends": [
"KatipBK"
],
"defaultScribes": [
[
"FileSK",
"logs/mainnet.log"
],
[
"StdoutSK",
"stdout"
]
],
"minSeverity": "Debug",
"options": {},
"rotation": {
"rpKeepFilesNum": 3,
"rpLogLimitBytes": 5000000,
"rpMaxAgeHours": 24
},
"setupBackends": [
"KatipBK"
],
"setupScribes": [
{
"scFormat": "ScJson",
"scKind": "FileSK",
"scName": "logs/node.log"
},
{
"scFormat": "ScJson",
"scKind": "StdoutSK",
"scName": "stdout"
}
]
}

0 comments on commit 3ffa09e

Please sign in to comment.