-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create-staked: add test #498
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
cardano-cli/test/cardano-cli-golden/Test/Golden/CreateStaked.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module Test.Golden.CreateStaked where | ||
|
||
import Cardano.Api.Shelley (ShelleyGenesis (sgNetworkMagic, sgStaking)) | ||
|
||
import Cardano.Api.Ledger (StandardCrypto) | ||
import Cardano.Ledger.Shelley.Genesis (ShelleyGenesisStaking (sgsPools, sgsStake)) | ||
|
||
import Control.Monad (filterM, 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 System.Directory | ||
import System.FilePath | ||
|
||
import Test.Cardano.CLI.Util (execCardanoCLI) | ||
|
||
import Hedgehog (Property) | ||
import qualified Hedgehog as H | ||
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_staked :: Property | ||
hprop_golden_create_staked = | ||
propertyOnce $ moduleWorkspace "tmp" $ \tempDir -> do | ||
|
||
let alonzo = "genesis.alonzo.spec.json" | ||
conway = "genesis.conway.spec.json" | ||
networkMagic = 42 | ||
numPools = 4 | ||
numStake = 8 | ||
|
||
liftIO $ copyFile ("test/cardano-cli-golden/files/input/alonzo/" <> alonzo) (tempDir </> alonzo) | ||
liftIO $ copyFile ("test/cardano-cli-golden/files/input/conway/" <> conway) (tempDir </> conway) | ||
|
||
void $ H.note (tempDir </> alonzo) | ||
void $ H.note (tempDir </> conway) | ||
|
||
void $ | ||
execCardanoCLI | ||
["conway", "genesis", "create-staked" | ||
, "--gen-genesis-keys", "2" | ||
, "--gen-pools", show numPools | ||
, "--gen-utxo-keys", "3" | ||
, "--gen-stake-delegs", show numStake | ||
, "--supply", "1000000000000" | ||
, "--supply-delegated", "1000000000000" | ||
, "--testnet-magic", show networkMagic | ||
, "--bulk-pool-cred-files", "2" | ||
, "--bulk-pools-per-file", "2" | ||
, "--num-stuffed-utxo", "7" | ||
, "--genesis-dir", tempDir | ||
] | ||
|
||
generated <- liftIO $ tree tempDir | ||
-- 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 tempDir) 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-staked.out" | ||
|
||
bs <- liftIO $ LBS.readFile $ tempDir </> "genesis.json" | ||
genesis :: ShelleyGenesis StandardCrypto <- Aeson.throwDecode bs | ||
|
||
H.assert (sgNetworkMagic genesis == networkMagic) | ||
H.assert ((length . sgsPools . sgStaking $ genesis) == numPools) | ||
H.assert ((length . sgsStake . sgStaking $ genesis) == numStake) |
75 changes: 75 additions & 0 deletions
75
cardano-cli/test/cardano-cli-golden/files/golden/conway/create-staked.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
delegate-keys/delegate1.counter | ||
delegate-keys/delegate1.kes.skey | ||
delegate-keys/delegate1.kes.vkey | ||
delegate-keys/delegate1.skey | ||
delegate-keys/delegate1.vkey | ||
delegate-keys/delegate1.vrf.skey | ||
delegate-keys/delegate1.vrf.vkey | ||
delegate-keys/delegate2.counter | ||
delegate-keys/delegate2.kes.skey | ||
delegate-keys/delegate2.kes.vkey | ||
delegate-keys/delegate2.skey | ||
delegate-keys/delegate2.vkey | ||
delegate-keys/delegate2.vrf.skey | ||
delegate-keys/delegate2.vrf.vkey | ||
delegate-keys/opcert1.cert | ||
delegate-keys/opcert2.cert | ||
genesis-keys/genesis1.skey | ||
genesis-keys/genesis1.vkey | ||
genesis-keys/genesis2.skey | ||
genesis-keys/genesis2.vkey | ||
genesis.alonzo.json | ||
genesis.alonzo.spec.json | ||
genesis.conway.json | ||
genesis.conway.spec.json | ||
genesis.json | ||
genesis.spec.json | ||
module | ||
pools/bulk1.creds | ||
pools/bulk2.creds | ||
pools/cold1.skey | ||
pools/cold1.vkey | ||
pools/cold2.skey | ||
pools/cold2.vkey | ||
pools/cold3.skey | ||
pools/cold3.vkey | ||
pools/cold4.skey | ||
pools/cold4.vkey | ||
pools/kes1.skey | ||
pools/kes1.vkey | ||
pools/kes2.skey | ||
pools/kes2.vkey | ||
pools/kes3.skey | ||
pools/kes3.vkey | ||
pools/kes4.skey | ||
pools/kes4.vkey | ||
pools/opcert1.cert | ||
pools/opcert1.counter | ||
pools/opcert2.cert | ||
pools/opcert2.counter | ||
pools/opcert3.cert | ||
pools/opcert3.counter | ||
pools/opcert4.cert | ||
pools/opcert4.counter | ||
pools/staking-reward1.skey | ||
pools/staking-reward1.vkey | ||
pools/staking-reward2.skey | ||
pools/staking-reward2.vkey | ||
pools/staking-reward3.skey | ||
pools/staking-reward3.vkey | ||
pools/staking-reward4.skey | ||
pools/staking-reward4.vkey | ||
pools/vrf1.skey | ||
pools/vrf1.vkey | ||
pools/vrf2.skey | ||
pools/vrf2.vkey | ||
pools/vrf3.skey | ||
pools/vrf3.vkey | ||
pools/vrf4.skey | ||
pools/vrf4.vkey | ||
utxo-keys/utxo1.skey | ||
utxo-keys/utxo1.vkey | ||
utxo-keys/utxo2.skey | ||
utxo-keys/utxo2.vkey | ||
utxo-keys/utxo3.skey | ||
utxo-keys/utxo3.vkey |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the order of the files? If
listDirectory
does not give us any orderguarantees, it would be nice to sort the list to have consistency between filesystems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@carbolymer> actually it's the caller that postprocesses the result of
tree
to make it stable, along with normalization and making it relative (to avoid depending on a temporary directory name) 👍