Skip to content

Commit

Permalink
create-testnet-data: add a golden test
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Nov 30, 2023
1 parent d261926 commit 0c601ab
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ test-suite cardano-cli-golden
, cardano-ledger-byron
, cborg
, containers
, directory
, filepath
, hedgehog ^>= 1.3
, hedgehog-extras ^>= 0.4.7.0
Expand All @@ -372,6 +373,7 @@ test-suite cardano-cli-golden
Test.Golden.Byron.UpdateProposal
Test.Golden.Byron.Vote
Test.Golden.Byron.Witness
Test.Golden.CreateTestnetData
Test.Golden.Conway.Transaction.Assemble
Test.Golden.EraBased.Governance.AnswerPoll
Test.Golden.EraBased.Governance.CreatePoll
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module Test.Golden.CreateTestnetData where

import Control.Monad (filterM, void)
import Control.Monad.IO.Class
import Data.List (intercalate, sort)
import System.Directory
import System.FilePath

import Test.Cardano.CLI.Util (execCardanoCLI)

import Hedgehog (Property)
import Hedgehog.Extras (moduleWorkspace, propertyOnce)
import qualified Hedgehog.Extras as H
import qualified Hedgehog.Extras.Test.Golden as H

{- HLINT ignore "Use camelCase" -}

-- | Given a root directory, returns files within this root (recursively)
tree :: FilePath -> IO [FilePath]
tree root = do
-- listDirectory returns a path relative to 'root'. We need to prepend
-- root to it for queries below.
content <- map (root </>) <$> listDirectory root
files <- filterM doesFileExist content
subs <- filterM doesDirectoryExist content
subTrees <- mapM tree subs
return $ files ++ concat subTrees

hprop_golden_create_testnet_data :: Property
hprop_golden_create_testnet_data =
propertyOnce $ moduleWorkspace "tmp" $ \tempDir -> do

let outputDir = tempDir </> "out"

void $
execCardanoCLI
["conway", "genesis", "create-testnet-data"
, "--genesis-keys", "2"
, "--utxo-keys", "3"
, "--out-dir", outputDir
, "--testnet-magic", "42"
, "--pools", "2"
]

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''

H.diffVsGoldenFile generated'' "test/cardano-cli-golden/files/golden/conway/create-testnet-data.out"
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
delegate-keys/delegate1/kes.skey
delegate-keys/delegate1/kes.vkey
delegate-keys/delegate1/key.skey
delegate-keys/delegate1/key.vkey
delegate-keys/delegate1/opcert.cert
delegate-keys/delegate1/opcert.counter
delegate-keys/delegate1/vrf.skey
delegate-keys/delegate1/vrf.vkey
delegate-keys/delegate2/kes.skey
delegate-keys/delegate2/kes.vkey
delegate-keys/delegate2/key.skey
delegate-keys/delegate2/key.vkey
delegate-keys/delegate2/opcert.cert
delegate-keys/delegate2/opcert.counter
delegate-keys/delegate2/vrf.skey
delegate-keys/delegate2/vrf.vkey
genesis-keys/genesis1/key.skey
genesis-keys/genesis1/key.vkey
genesis-keys/genesis2/key.skey
genesis-keys/genesis2/key.vkey
genesis-shelley.json
genesis.json
pools-keys/pool1/cold.skey
pools-keys/pool1/cold.vkey
pools-keys/pool1/kes.skey
pools-keys/pool1/kes.vkey
pools-keys/pool1/opcert.cert
pools-keys/pool1/opcert.counter
pools-keys/pool1/staking-reward.skey
pools-keys/pool1/staking-reward.vkey
pools-keys/pool1/vrf.skey
pools-keys/pool1/vrf.vkey
pools-keys/pool2/cold.skey
pools-keys/pool2/cold.vkey
pools-keys/pool2/kes.skey
pools-keys/pool2/kes.vkey
pools-keys/pool2/opcert.cert
pools-keys/pool2/opcert.counter
pools-keys/pool2/staking-reward.skey
pools-keys/pool2/staking-reward.vkey
pools-keys/pool2/vrf.skey
pools-keys/pool2/vrf.vkey
utxo-keys/utxo1/utxo.skey
utxo-keys/utxo1/utxo.vkey
utxo-keys/utxo2/utxo.skey
utxo-keys/utxo2/utxo.vkey
utxo-keys/utxo3/utxo.skey
utxo-keys/utxo3/utxo.vkey

0 comments on commit 0c601ab

Please sign in to comment.