-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
167 additions
and
0 deletions.
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.Ledger.Crypto (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 |