Skip to content

Commit

Permalink
Update cardano-testnet-test with path construction functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Jun 2, 2023
1 parent b24dcb0 commit ba18365
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 65 deletions.
Expand Up @@ -51,9 +51,10 @@ import Testnet.Util.Runtime
hprop_leadershipSchedule :: Property
hprop_leadershipSchedule = integrationRetryWorkspace 2 "alonzo-leadership-schedule" $ \tempAbsBasePath' -> do
H.note_ SYS.os
conf@Conf { tempBaseAbsPath, tempAbsPath } <- H.noteShowM $
mkConf Nothing tempAbsBasePath' Nothing
conf@Conf { tempAbsPath } <- H.noteShowM $ mkConf Nothing tempAbsBasePath' Nothing
let
tempAbsPath' = unTmpAbsPath tempAbsPath
tempBaseAbsPath = makeTmpBaseAbsPath tempAbsPath
fastTestnetOptions = CardanoOnlyTestnetOptions cardanoDefaultTestnetOptions
{ cardanoEpochLength = 500
, cardanoSlotLength = 0.01
Expand All @@ -70,13 +71,13 @@ hprop_leadershipSchedule = integrationRetryWorkspace 2 "alonzo-leadership-schedu
execConfig <- H.headM (bftSprockets tr) >>= H.mkExecConfig tempBaseAbsPath

-- First we note all the relevant files
work <- H.note tempAbsPath
work <- H.note tempAbsPath'

-- We get our UTxOs from here
utxoVKeyFile <- H.note $ tempAbsPath </> "shelley/utxo-keys/utxo1.vkey"
utxoSKeyFile <- H.note $ tempAbsPath </> "shelley/utxo-keys/utxo1.skey"
utxoVKeyFile2 <- H.note $ tempAbsPath </> "shelley/utxo-keys/utxo2.vkey"
utxoSKeyFile2 <- H.note $ tempAbsPath </> "shelley/utxo-keys/utxo2.skey"
utxoVKeyFile <- H.note $ tempAbsPath' </> "shelley/utxo-keys/utxo1.vkey"
utxoSKeyFile <- H.note $ tempAbsPath' </> "shelley/utxo-keys/utxo1.skey"
utxoVKeyFile2 <- H.note $ tempAbsPath' </> "shelley/utxo-keys/utxo2.vkey"
utxoSKeyFile2 <- H.note $ tempAbsPath' </> "shelley/utxo-keys/utxo2.skey"

utxoAddr <- execCli
[ "address", "build"
Expand All @@ -99,8 +100,8 @@ hprop_leadershipSchedule = integrationRetryWorkspace 2 "alonzo-leadership-schedu
txin <- H.noteShow $ head $ Map.keys utxo1

-- Staking keys
utxoStakingVkey2 <- H.note $ tempAbsPath </> "shelley/utxo-keys/utxo2-stake.vkey"
utxoStakingSkey2 <- H.note $ tempAbsPath </> "shelley/utxo-keys/utxo2-stake.skey"
utxoStakingVkey2 <- H.note $ tempAbsPath' </> "shelley/utxo-keys/utxo2-stake.vkey"
utxoStakingSkey2 <- H.note $ tempAbsPath' </> "shelley/utxo-keys/utxo2-stake.skey"

utxoaddrwithstaking <- execCli
[ "address", "build"
Expand All @@ -116,9 +117,9 @@ hprop_leadershipSchedule = integrationRetryWorkspace 2 "alonzo-leadership-schedu
]

-- Stake pool related
H.createDirectoryIfMissing_ $ tempAbsPath </> "addresses"
poolownerstakekey <- H.note $ tempAbsPath </> "addresses/pool-owner1-stake.vkey"
poolownerverkey <- H.note $ tempAbsPath </> "addresses/pool-owner1.vkey"
H.createDirectoryIfMissing_ $ tempAbsPath' </> "addresses"
poolownerstakekey <- H.note $ tempAbsPath' </> "addresses/pool-owner1-stake.vkey"
poolownerverkey <- H.note $ tempAbsPath' </> "addresses/pool-owner1.vkey"
poolownerstakeaddr <- filter (/= '\n') <$> execCli
[ "stake-address", "build"
, "--stake-verification-key-file", poolownerstakekey
Expand All @@ -132,8 +133,8 @@ hprop_leadershipSchedule = integrationRetryWorkspace 2 "alonzo-leadership-schedu
, "--testnet-magic", show @Int testnetMagic
]

poolcoldVkey <- H.note $ tempAbsPath </> "node-pool1/shelley/operator.vkey"
poolcoldSkey <- H.note $ tempAbsPath </> "node-pool1/shelley/operator.skey"
poolcoldVkey <- H.note $ tempAbsPath' </> "node-pool1/shelley/operator.vkey"
poolcoldSkey <- H.note $ tempAbsPath' </> "node-pool1/shelley/operator.skey"

stakePoolId <- filter ( /= '\n') <$> execCli
[ "stake-pool", "id"
Expand Down Expand Up @@ -307,7 +308,7 @@ hprop_leadershipSchedule = integrationRetryWorkspace 2 "alonzo-leadership-schedu
, "--tx-in", T.unpack $ Api.renderTxIn txin2
, "--tx-out", utxoAddr <> "+" <> show @Int 10000000
, "--witness-override", show @Int 3
, "--certificate-file", tempAbsPath </> "node-pool1/registration.cert"
, "--certificate-file", tempAbsPath' </> "node-pool1/registration.cert"
, "--certificate-file", work </> "pledger.delegcert"
, "--out-file", work </> "register-stake-pool.txbody"
]
Expand All @@ -318,7 +319,7 @@ hprop_leadershipSchedule = integrationRetryWorkspace 2 "alonzo-leadership-schedu
, "--testnet-magic", show @Int testnetMagic
, "--signing-key-file", utxoSKeyFile
, "--signing-key-file", poolcoldSkey
, "--signing-key-file", tempAbsPath </> "node-pool1/owner.skey"
, "--signing-key-file", tempAbsPath' </> "node-pool1/owner.skey"
, "--out-file", work </> "register-stake-pool.tx"
]

Expand Down Expand Up @@ -465,7 +466,7 @@ hprop_leadershipSchedule = integrationRetryWorkspace 2 "alonzo-leadership-schedu
H.note_ "Done"

let poolVrfSkey = poolNodeKeysVrfSkey $ poolKeys poolNode1
scheduleFile <- H.noteTempFile tempAbsPath "schedule.log"
scheduleFile <- H.noteTempFile tempAbsPath' "schedule.log"

void $ execCli' execConfig
[ "query", "leadership-schedule"
Expand Down
Expand Up @@ -44,12 +44,12 @@ import Testnet.Util.Runtime
hprop_leadershipSchedule :: Property
hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-schedule" $ \tempAbsBasePath' -> do
H.note_ SYS.os
conf@Conf { tempBaseAbsPath, tempAbsPath } <- H.noteShowM $
mkConf Nothing tempAbsBasePath' Nothing

work <- H.createDirectoryIfMissing $ tempAbsPath </> "work"
conf@Conf { tempAbsPath } <- H.noteShowM $ mkConf Nothing tempAbsBasePath' Nothing
let tempAbsPath' = unTmpAbsPath tempAbsPath
work <- H.createDirectoryIfMissing $ tempAbsPath' </> "work"

let
tempBaseAbsPath = makeTmpBaseAbsPath $ TmpAbsolutePath tempAbsPath'
testnetOptions = BabbageOnlyTestnetOptions $ babbageDefaultTestnetOptions
{ babbageNodeLoggingFormat = NodeLoggingFormatAsJson
}
Expand Down Expand Up @@ -93,7 +93,7 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
let poolVrfSkey = poolNodeKeysVrfSkey $ poolKeys poolNode1

id do
scheduleFile <- H.noteTempFile tempAbsPath "schedule.log"
scheduleFile <- H.noteTempFile tempAbsPath' "schedule.log"

leadershipScheduleDeadline <- H.noteShowM $ DTC.addUTCTime 180 <$> H.noteShowIO DTC.getCurrentTime

Expand Down Expand Up @@ -141,7 +141,7 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
H.assert $ L.null (expectedLeadershipSlotNumbers \\ leaderSlots)

id do
scheduleFile <- H.noteTempFile tempAbsPath "schedule.log"
scheduleFile <- H.noteTempFile tempAbsPath' "schedule.log"

leadershipScheduleDeadline <- H.noteShowM $ DTC.addUTCTime 180 <$> H.noteShowIO DTC.getCurrentTime

Expand Down
Expand Up @@ -43,12 +43,12 @@ import Testnet.Util.Runtime
hprop_stakeSnapshot :: Property
hprop_stakeSnapshot = H.integrationRetryWorkspace 2 "babbage-stake-snapshot" $ \tempAbsBasePath' -> do
H.note_ SYS.os
conf@Conf { tempBaseAbsPath, tempAbsPath } <- H.noteShowM $
mkConf Nothing tempAbsBasePath' Nothing

work <- H.createDirectoryIfMissing $ tempAbsPath </> "work"
conf@Conf { tempAbsPath } <- H.noteShowM $ mkConf Nothing tempAbsBasePath' Nothing
let tempAbsPath' = unTmpAbsPath tempAbsPath
work <- H.createDirectoryIfMissing $ tempAbsPath' </> "work"

let
tempBaseAbsPath = makeTmpBaseAbsPath $ TmpAbsolutePath tempAbsPath'
testnetOptions = BabbageOnlyTestnetOptions $ babbageDefaultTestnetOptions
{ babbageNodeLoggingFormat = NodeLoggingFormatAsJson
}
Expand Down
36 changes: 19 additions & 17 deletions cardano-testnet/test/cardano-testnet-test/Test/Cli/KesPeriodInfo.hs
Expand Up @@ -39,11 +39,13 @@ import Testnet.Util.Runtime
hprop_kes_period_info :: Property
hprop_kes_period_info = H.integrationRetryWorkspace 2 "kes-period-info" $ \tempAbsBasePath' -> do
H.note_ SYS.os
conf@Conf { tempBaseAbsPath, tempAbsPath }
conf@Conf { tempAbsPath }
-- TODO: Move yaml filepath specification into individual node options
<- H.noteShowM $ mkConf Nothing tempAbsBasePath' Nothing

let fastTestnetOptions = CardanoOnlyTestnetOptions $ cardanoDefaultTestnetOptions
let tempAbsPath' = unTmpAbsPath tempAbsPath
tempBaseAbsPath = makeTmpBaseAbsPath tempAbsPath
fastTestnetOptions = CardanoOnlyTestnetOptions $ cardanoDefaultTestnetOptions
{ cardanoNodes = cardanoDefaultTestnetNodeOptions
, cardanoEpochLength = 500
, cardanoSlotLength = 0.02
Expand All @@ -54,13 +56,13 @@ hprop_kes_period_info = H.integrationRetryWorkspace 2 "kes-period-info" $ \tempA
execConfig <- H.headM (bftSprockets runTime) >>= H.mkExecConfig tempBaseAbsPath

-- First we note all the relevant files
work <- H.note tempAbsPath
work <- H.note tempAbsPath'

-- We get our UTxOs from here
utxoVKeyFile <- H.note $ tempAbsPath </> "shelley/utxo-keys/utxo1.vkey"
utxoSKeyFile <- H.note $ tempAbsPath </> "shelley/utxo-keys/utxo1.skey"
utxoVKeyFile2 <- H.note $ tempAbsPath </> "shelley/utxo-keys/utxo2.vkey"
utxoSKeyFile2 <- H.note $ tempAbsPath </> "shelley/utxo-keys/utxo2.skey"
utxoVKeyFile <- H.note $ tempAbsPath' </> "shelley/utxo-keys/utxo1.vkey"
utxoSKeyFile <- H.note $ tempAbsPath' </> "shelley/utxo-keys/utxo1.skey"
utxoVKeyFile2 <- H.note $ tempAbsPath' </> "shelley/utxo-keys/utxo2.vkey"
utxoSKeyFile2 <- H.note $ tempAbsPath' </> "shelley/utxo-keys/utxo2.skey"

utxoAddr <- execCli
[ "address", "build"
Expand All @@ -83,8 +85,8 @@ hprop_kes_period_info = H.integrationRetryWorkspace 2 "kes-period-info" $ \tempA
txin <- H.noteShow =<< H.headM (Map.keys utxo1)

-- Staking keys
utxoStakingVkey2 <- H.note $ tempAbsPath </> "shelley/utxo-keys/utxo2-stake.vkey"
utxoStakingSkey2 <- H.note $ tempAbsPath </> "shelley/utxo-keys/utxo2-stake.skey"
utxoStakingVkey2 <- H.note $ tempAbsPath' </> "shelley/utxo-keys/utxo2-stake.vkey"
utxoStakingSkey2 <- H.note $ tempAbsPath' </> "shelley/utxo-keys/utxo2-stake.skey"

utxoaddrwithstaking <- execCli [ "address", "build"
, "--payment-verification-key-file", utxoVKeyFile2
Expand All @@ -101,8 +103,8 @@ hprop_kes_period_info = H.integrationRetryWorkspace 2 "kes-period-info" $ \tempA


-- Stake pool related
poolownerstakekey <- H.note $ tempAbsPath </> "addresses/pool-owner1-stake.vkey"
poolownerverkey <- H.note $ tempAbsPath </> "addresses/pool-owner1.vkey"
poolownerstakekey <- H.note $ tempAbsPath' </> "addresses/pool-owner1-stake.vkey"
poolownerverkey <- H.note $ tempAbsPath' </> "addresses/pool-owner1.vkey"
poolownerstakeaddr <- filter (/= '\n')
<$> execCli
[ "stake-address", "build"
Expand All @@ -115,8 +117,8 @@ hprop_kes_period_info = H.integrationRetryWorkspace 2 "kes-period-info" $ \tempA
, "--stake-verification-key-file", poolownerstakekey
, "--testnet-magic", show @Int testnetMagic
]
poolcoldVkey <- H.note $ tempAbsPath </> "node-pool1/shelley/operator.vkey"
poolcoldSkey <- H.note $ tempAbsPath </> "node-pool1/shelley/operator.skey"
poolcoldVkey <- H.note $ tempAbsPath' </> "node-pool1/shelley/operator.vkey"
poolcoldSkey <- H.note $ tempAbsPath' </> "node-pool1/shelley/operator.skey"

stakePoolId <- filter ( /= '\n') <$>
execCli [ "stake-pool", "id"
Expand Down Expand Up @@ -286,7 +288,7 @@ hprop_kes_period_info = H.integrationRetryWorkspace 2 "kes-period-info" $ \tempA
, "--tx-in", T.unpack $ renderTxIn txin2
, "--tx-out", utxoAddr <> "+" <> show @Int 10000000
, "--witness-override", show @Int 3
, "--certificate-file", tempAbsPath </> "node-pool1/registration.cert"
, "--certificate-file", tempAbsPath' </> "node-pool1/registration.cert"
, "--certificate-file", work </> "pledger.delegcert"
, "--out-file", work </> "register-stake-pool.txbody"
]
Expand All @@ -297,7 +299,7 @@ hprop_kes_period_info = H.integrationRetryWorkspace 2 "kes-period-info" $ \tempA
, "--testnet-magic", show @Int testnetMagic
, "--signing-key-file", utxoSKeyFile
, "--signing-key-file", poolcoldSkey
, "--signing-key-file", tempAbsPath </> "node-pool1/owner.skey"
, "--signing-key-file", tempAbsPath' </> "node-pool1/owner.skey"
, "--out-file", work </> "register-stake-pool.tx"
]

Expand Down Expand Up @@ -345,7 +347,7 @@ hprop_kes_period_info = H.integrationRetryWorkspace 2 "kes-period-info" $ \tempA
H.note_ "We have a fully functioning stake pool at this point."

-- TODO: Linking directly to the node certificate is fragile
nodeOperationalCertFp <- H.note $ tempAbsPath </> "node-pool1/shelley/node.cert"
nodeOperationalCertFp <- H.note $ tempAbsPath' </> "node-pool1/shelley/node.cert"

void $ execCli' execConfig
[ "query", "kes-period-info"
Expand Down Expand Up @@ -437,5 +439,5 @@ hprop_kes_period_info = H.integrationRetryWorkspace 2 "kes-period-info" $ \tempA
]

-- TODO: Linking to the node log file like this is fragile.
spoLogFile <- H.note $ tempAbsPath </> "logs/node-pool1.stdout.log"
spoLogFile <- H.note $ tempAbsPath' </> "logs/node-pool1.stdout.log"
prop_node_minted_block spoLogFile
Expand Up @@ -25,29 +25,25 @@ import qualified Hedgehog.Extras.Test.Base as H
import qualified Hedgehog.Extras.Test.Process as H
import qualified Hedgehog.Internal.Property as H
import Prelude
import qualified System.Directory as IO
import System.Environment (getEnvironment)
import System.FilePath ((</>))
import qualified System.Info as SYS

import Cardano.Testnet
import qualified Testnet.Util.Base as H
import Testnet.Util.Process
import qualified Testnet.Util.Runtime as TR
import Testnet.Util.Runtime

-- | Tests @query slot-number@ cardano-cli command that it returns correct slot numbers for provided utc time
hprop_querySlotNumber :: Property
hprop_querySlotNumber = H.integrationRetryWorkspace 2 "query-slot-number" $ \tempAbsBasePath' -> do
H.note_ SYS.os
base <- H.note =<< H.noteIO . IO.canonicalizePath =<< H.getProjectBase
configurationTemplate <- H.noteShow $ base </> "configuration/defaults/byron-mainnet/configuration.yaml"
conf@Conf { tempBaseAbsPath } <- H.noteShowM $
mkConf (Just $ YamlFilePath configurationTemplate) tempAbsBasePath' Nothing

let
testnetOptions = BabbageOnlyTestnetOptions $ babbageDefaultTestnetOptions
{ babbageNodeLoggingFormat = NodeLoggingFormatAsJson
}
conf <- H.noteShowM $ mkConf Nothing tempAbsBasePath' Nothing

let tempBaseAbsPath' = TR.makeTmpBaseAbsPath $ tempAbsPath conf
testnetOptions = BabbageOnlyTestnetOptions $ babbageDefaultTestnetOptions
{ babbageNodeLoggingFormat = NodeLoggingFormatAsJson
}
tr@TestnetRuntime
{ testnetMagic
, poolNodes
Expand All @@ -71,7 +67,7 @@ hprop_querySlotNumber = H.integrationRetryWorkspace 2 "query-slot-number" $ \tem
-- The environment must be passed onto child process on Windows in order to
-- successfully start that process.
<> env
, H.execConfigCwd = Last $ Just tempBaseAbsPath
, H.execConfigCwd = Last $ Just tempBaseAbsPath'
}

id do
Expand Down
7 changes: 4 additions & 3 deletions cardano-testnet/test/cardano-testnet-test/Test/FoldBlocks.hs
Expand Up @@ -39,7 +39,8 @@ prop_foldBlocks = H.integrationRetryWorkspace 2 "foldblocks" $ \tempAbsBasePath'
-- Start testnet
conf <- HE.noteShowM $ TN.mkConf Nothing (tempAbsBasePath' <> "/") Nothing

let options = CardanoOnlyTestnetOptions $ cardanoDefaultTestnetOptions
let tempAbsPath' = unTmpAbsPath $ tempAbsPath conf
options = CardanoOnlyTestnetOptions $ cardanoDefaultTestnetOptions
-- NB! The `activeSlotsCoeff` value is very important for
-- chain extension for the two-node/one-pool testnet that
-- `defaultTestnetOptions` define. The default 0.2 often fails
Expand All @@ -51,9 +52,9 @@ prop_foldBlocks = H.integrationRetryWorkspace 2 "foldblocks" $ \tempAbsBasePath'
-- Get socketPath
socketPathAbs <- do
socketPath' <- HE.sprocketArgumentName <$> HE.headM (nodeSprocket <$> bftNodes runtime)
H.noteIO (IO.canonicalizePath $ tempAbsPath conf </> socketPath')
H.noteIO (IO.canonicalizePath $ tempAbsPath' </> socketPath')

configFile <- H.noteShow $ tempAbsPath conf </> "configuration.yaml"
configFile <- H.noteShow $ tempAbsPath' </> "configuration.yaml"

-- Start foldBlocks in a separate thread
lock <- H.evalIO IO.newEmptyMVar
Expand Down
16 changes: 10 additions & 6 deletions cardano-testnet/test/cardano-testnet-test/Test/Node/Shutdown.hs
Expand Up @@ -38,6 +38,7 @@ import Testnet.Commands.Genesis
import Testnet.Options
import Testnet.Topology
import Testnet.Util.Process (execCli_, procNode)
import qualified Testnet.Util.Runtime as TR
import Testnet.Utils

{- HLINT ignore "Redundant <&>" -}
Expand All @@ -46,11 +47,16 @@ hprop_shutdown :: Property
hprop_shutdown = H.integrationRetryWorkspace 2 "shutdown" $ \tempAbsBasePath' -> do
conf <- H.noteShowM $
mkConf Nothing tempAbsBasePath' Nothing
let tempBaseAbsPath' = tempBaseAbsPath conf
tempAbsPath' = tempAbsPath conf
logDir' = logDir conf
socketDir' = socketDir conf
let tempBaseAbsPath' = TR.makeTmpBaseAbsPath $ tempAbsPath conf
tempAbsPath' = TR.unTmpAbsPath $ tempAbsPath conf
logDir' = TR.makeLogDir $ tempAbsPath conf
socketDir' = TR.makeSocketDir $ tempAbsPath conf
testnetMagic' = testnetMagic conf

-- TODO: We need to uniformly create these directories
H.createDirectoryIfMissing_ logDir'
H.createSubdirectoryIfMissing_ tempBaseAbsPath' socketDir'

[port] <- H.noteShowIO $ IO.allocateRandomPorts 1

sprocket <- H.noteShow $ IO.Sprocket tempBaseAbsPath' (socketDir' </> "node")
Expand Down Expand Up @@ -97,8 +103,6 @@ hprop_shutdown = H.integrationRetryWorkspace 2 "shutdown" $ \tempAbsBasePath' ->
]




byronGenesisHash <- getByronGenesisHash $ tempAbsPath' </> "byron/genesis.json"
shelleyGenesisHash <- getShelleyGenesisHash (tempAbsPath' </> "shelley/genesis.json") "ShelleyGenesisHash"
alonzoGenesisHash <- getShelleyGenesisHash (tempAbsPath' </> "shelley/genesis.alonzo.json") "AlonzoGenesisHash"
Expand Down

0 comments on commit ba18365

Please sign in to comment.