Skip to content

Commit

Permalink
Add new test + check create-testnet-data fails for the expected reason
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Mar 11, 2024
1 parent a17552d commit 08c71fa
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cardano-cli/test/cardano-cli-test/Test/Cli/CreateTestnetData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Test.Cli.CreateTestnetData where

import Control.Monad
import Data.Aeson (FromJSON, ToJSON)
import Data.List (isInfixOf)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as M
import Data.Text (Text)
Expand Down Expand Up @@ -50,6 +51,7 @@ hprop_create_testnet_data_create_nonegative_supply = do
, (1_100_000_000, 1_000_000_000, ExitSuccess)
, (1_000_000_000, 1_000_000_000, ExitSuccess)
, (1_000_000_000_000, 1_000_000_000, ExitSuccess)
, (1_000_000_000, 1_000_000_001, ExitFailure 1)
, (1_000_000_000, 1_100_000_001, ExitFailure 1)
, (1_000_000_000, 2_000_000_000, ExitFailure 1)
] :: [(Int, Int, ExitCode)]
Expand All @@ -58,7 +60,7 @@ hprop_create_testnet_data_create_nonegative_supply = do
moduleWorkspace "tmp" $ \tempDir -> do
let outputDir = tempDir </> "out"

(exitCode, _, _) <- H.noteShowM $ execDetailCardanoCLI
(exitCode, _stdout, stderr) <- H.noteShowM $ execDetailCardanoCLI
["conway", "genesis", "create-testnet-data"
, "--testnet-magic", "42"
, "--pools", "3"
Expand All @@ -73,7 +75,8 @@ hprop_create_testnet_data_create_nonegative_supply = do
H.note_ "check that exit code is equal to the expected one"
exitCode === expectedExitCode

when (exitCode == ExitSuccess) $ do
if exitCode == ExitSuccess
then do
testGenesis@TestGenesis{maxLovelaceSupply, initialFunds} <- H.leftFailM . H.readJsonFile $ outputDir </> "genesis.json"
H.note_ $ show testGenesis

Expand All @@ -87,6 +90,11 @@ hprop_create_testnet_data_create_nonegative_supply = do
H.assertWith initialFunds $ \initialFunds' -> do
let totalDistributed = sum . M.elems $ initialFunds'
totalDistributed <= maxLovelaceSupply
else do
H.assertWith stderr (`contains` "delegated supply should be less or equal to the total supply")
where
contains s1 s2 = s2 `isInfixOf` s1


data TestGenesis = TestGenesis
{ maxLovelaceSupply :: Int
Expand Down

0 comments on commit 08c71fa

Please sign in to comment.