Skip to content

Commit

Permalink
create-testnet-data: Extend existing test to test relays
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Mar 6, 2024
1 parent 69ddf03 commit 829f70e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ test-suite cardano-cli-golden
, cardano-crypto-wrapper
, cardano-ledger-byron
, cardano-ledger-shelley >=1.7.0.0
, cardano-strict-containers ^>= 0.1
, cborg
, containers
, directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ module Test.Golden.CreateTestnetData where
import Cardano.Api.Ledger (StandardCrypto)
import Cardano.Api.Shelley (ShelleyGenesis (..))

import Cardano.Ledger.Shelley.API (ShelleyGenesisStaking (..))
import qualified Cardano.Ledger.Shelley.API as L

import Control.Monad (filterM, void)
import Control.Monad (filterM, forM_, void)
import Control.Monad.IO.Class
import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Lazy as LBS
import Data.List (intercalate, sort)
import qualified Data.Sequence.Strict as Seq
import Data.Word (Word32)
import System.Directory
import System.Directory.Extra (listDirectories)
Expand All @@ -24,6 +25,7 @@ import Hedgehog.Extras (moduleWorkspace, propertyOnce)
import qualified Hedgehog.Extras as H
import qualified Hedgehog.Extras.Test.Golden as H

{- HLINT ignore "Move brackets to avoid $" -}
{- HLINT ignore "Use camelCase" -}

networkMagic :: Word32
Expand All @@ -49,6 +51,8 @@ mkArguments outputDir =
, "--testnet-magic", show networkMagic
, "--pools", show numPools
, "--drep-keys", show numDReps
-- Relays file specifies two relays, like the number of SPOs
, "--relays", "test/cardano-cli-golden/files/input/shelley/genesis/relays.json"
]

-- | Given a root directory, returns files within this root (recursively)
Expand Down Expand Up @@ -104,14 +108,17 @@ golden_create_testnet_data mShelleyTemplate =
bs <- liftIO $ LBS.readFile $ outputDir </> "genesis.json"
genesis :: ShelleyGenesis StandardCrypto <- Aeson.throwDecode bs

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

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

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

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

-- | This test tests the transient case, i.e. it writes strictly
-- less things to disk than 'hprop_golden_create_testnet_data'. Execute this test with:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"0": [
{
"single host name": {
"dnsName": "node-0",
"port": 30000
}
}
],
"1": [
{
"single host name": {
"dnsName": "node-1",
"port": 30001
}
}
]
}

0 comments on commit 829f70e

Please sign in to comment.