Skip to content

Commit

Permalink
create-testnet-data: augment test
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Jan 19, 2024
1 parent 1e7a8c1 commit cf62f83
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ test-suite cardano-cli-golden
, cborg
, containers
, directory
, extra
, filepath
, hedgehog ^>= 1.3
, hedgehog-extras ^>= 0.6.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import Cardano.Api
import Cardano.Api.Shelley

import Cardano.CLI.EraBased.Commands.Genesis as Cmd
import qualified Cardano.CLI.EraBased.Commands.Governance.DRep as DRep
import qualified Cardano.CLI.EraBased.Commands.Node as Cmd
import Cardano.CLI.EraBased.Run.Address (runAddressKeyGenCmd)
import qualified Cardano.CLI.EraBased.Run.Governance.DRep as DRep
import qualified Cardano.CLI.EraBased.Commands.Governance.DRep as DRep
import qualified Cardano.CLI.EraBased.Run.Key as Key
import Cardano.CLI.EraBased.Run.Node (runNodeIssueOpCertCmd, runNodeKeyGenColdCmd,
runNodeKeyGenKesCmd, runNodeKeyGenVrfCmd)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE ScopedTypeVariables #-}
module Test.Golden.CreateTestnetData where

import Control.Monad (filterM, void)
Expand All @@ -12,20 +13,40 @@ import Hedgehog (Property)
import Hedgehog.Extras (moduleWorkspace, propertyOnce)
import qualified Hedgehog.Extras as H
import qualified Hedgehog.Extras.Test.Golden as H
import qualified Data.ByteString.Lazy as LBS
import Cardano.Api.Shelley (ShelleyGenesis (..))
import Cardano.Api.Ledger (StandardCrypto)
import qualified Data.Aeson as Aeson
import qualified Hedgehog as H
import Cardano.Ledger.Shelley.API (ShelleyGenesisStaking(..))
import Data.Word (Word32)
import System.Directory.Extra (listDirectories)

{- HLINT ignore "Use camelCase" -}

networkMagic :: Word32
networkMagic = 42

numDReps :: Int
numDReps = 5

numPools :: Int
numPools = 2

numUtxoKeys :: Int
numUtxoKeys = 3

-- | A function to create the arguments, so that they are shared
-- between the two tests, except for the possibly transient ones.
mkArguments :: String -> [String]
mkArguments outputDir =
["conway", "genesis", "create-testnet-data"
, "--genesis-keys", "2"
, "--utxo-keys", "3"
, "--utxo-keys", show numUtxoKeys
, "--out-dir", outputDir
, "--testnet-magic", "42"
, "--pools", "2"
, "--drep-keys", "5"
, "--testnet-magic", show networkMagic
, "--pools", show numPools
, "--drep-keys", show numDReps
]

-- | Given a root directory, returns files within this root (recursively)
Expand Down Expand Up @@ -61,6 +82,18 @@ hprop_golden_create_testnet_data =

H.diffVsGoldenFile generated'' "test/cardano-cli-golden/files/golden/conway/create-testnet-data.out"

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)

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

actualNumUtxoKeys <- liftIO $ listDirectories $ outputDir </> "utxo-keys"
H.assert $ length actualNumUtxoKeys == 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:
-- @cabal test cardano-cli-golden --test-options '-p "/golden create testnet data transient stake delegators/'@
Expand Down

0 comments on commit cf62f83

Please sign in to comment.