Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
NanuIjaz committed Mar 7, 2024
2 parents e992771 + 3cbbace commit 09f2827
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 125 deletions.
1 change: 0 additions & 1 deletion bench/cardano-topology/cardano-topology.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ license: Apache-2.0
license-files: LICENSE
NOTICE
build-type: Simple
extra-source-files: README.md
data-files: data/bench-torus-52.json
data/bench-torus-dense-52.json
data/ci-test-nomadcwqa.json
Expand Down
11 changes: 7 additions & 4 deletions cardano-testnet/cardano-testnet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ library
, cardano-cli ^>= 8.20.3.0
, cardano-crypto-class
, cardano-crypto-wrapper
, cardano-git-rev
, cardano-ledger-alonzo
, cardano-ledger-binary
, cardano-ledger-byron
, cardano-ledger-conway
, cardano-ledger-conway
, cardano-ledger-core
, cardano-ledger-core:testlib
, cardano-git-rev
, cardano-ledger-core
, cardano-ledger-binary
, cardano-ledger-byron
, cardano-ledger-shelley
, cardano-node
, cardano-ping ^>= 0.2.0.10
Expand Down Expand Up @@ -183,6 +183,7 @@ test-suite cardano-testnet-test
Cardano.Testnet.Test.LedgerEvents.Gov.InfoAction
Cardano.Testnet.Test.LedgerEvents.Gov.ProposeNewConstitutionSPO
Cardano.Testnet.Test.LedgerEvents.SanityCheck
Cardano.Testnet.Test.LedgerEvents.TreasuryGrowth

Cardano.Testnet.Test.Node.Shutdown
Cardano.Testnet.Test.SubmitApi.Babbage.Transaction
Expand All @@ -198,8 +199,10 @@ test-suite cardano-testnet-test
, cardano-cli
, cardano-crypto-class
, cardano-ledger-conway
, cardano-ledger-core
, cardano-ledger-shelley
, cardano-node
, cardano-strict-containers ^>= 0.1
, cardano-testnet
, containers
, directory
Expand Down
22 changes: 14 additions & 8 deletions cardano-testnet/src/Testnet/Components/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import Data.Bifunctor
import qualified Data.ByteString.Lazy as LBS
import qualified Data.List as List
import Data.String
import Data.Word (Word32)
import GHC.Stack (HasCallStack)
import qualified GHC.Stack as GHC
import Lens.Micro
Expand Down Expand Up @@ -98,7 +97,7 @@ createSPOGenesisAndFiles (NumPools numPoolNodes) era shelleyGenesis (TmpAbsolute
genesisShelleyDirAbs = takeDirectory genesisShelleyFpAbs
genesisShelleyDir <- H.createDirectoryIfMissing genesisShelleyDirAbs
let testnetMagic = sgNetworkMagic shelleyGenesis
numStakeDelegators = 3
numStakeDelegators = 3 :: Int
startTime = sgSystemStart shelleyGenesis

-- TODO: We need to read the genesis files into Haskell and modify them
Expand All @@ -115,6 +114,8 @@ createSPOGenesisAndFiles (NumPools numPoolNodes) era shelleyGenesis (TmpAbsolute
-- 50 second epochs
-- Epoch length should be "10 * k / f" where "k = securityParam, f = activeSlotsCoeff"
H.rewriteJsonFile @Value genesisShelleyFpAbs $ \o -> o
-- TODO: remove rho and tau adjustment after https://github.com/IntersectMBO/cardano-api/pull/425 gets
-- integrated with newer cardano-api into node
& L.key "protocolParams" . L.key "rho" . L._Number .~ 0.1
& L.key "protocolParams" . L.key "tau" . L._Number .~ 0.1
& L.key "securityParam" . L._Integer .~ 5
Expand All @@ -130,11 +131,11 @@ createSPOGenesisAndFiles (NumPools numPoolNodes) era shelleyGenesis (TmpAbsolute
execCli_
[ convertToEraString era, "genesis", "create-testnet-data"
, "--spec-shelley", genesisShelleyFpAbs
, "--testnet-magic", show @Word32 testnetMagic
, "--pools", show @Int numPoolNodes
, "--testnet-magic", show testnetMagic
, "--pools", show numPoolNodes
, "--total-supply", show @Int 2_000_000_000_000
, "--delegated-supply", show @Int 1_000_000_000_000
, "--stake-delegators", show @Int numStakeDelegators
, "--stake-delegators", show numStakeDelegators
, "--utxo-keys", show numSeededUTxOKeys
, "--drep-keys", "3"
, "--start-time", DTC.formatIso8601 startTime
Expand All @@ -152,7 +153,6 @@ createSPOGenesisAndFiles (NumPools numPoolNodes) era shelleyGenesis (TmpAbsolute
forM_ files $ \file -> do
H.note file


-- TODO: This conway and alonzo genesis creation should be ultimately moved to create-testnet-data
alonzoConwayTestGenesisJsonTargetFile <- H.noteShow (genesisShelleyDir </> "genesis.alonzo.json")
gen <- H.evalEither $ first prettyError defaultAlonzoGenesis
Expand All @@ -161,10 +161,16 @@ createSPOGenesisAndFiles (NumPools numPoolNodes) era shelleyGenesis (TmpAbsolute
conwayConwayTestGenesisJsonTargetFile <- H.noteShow (genesisShelleyDir </> "genesis.conway.json")
H.evalIO $ LBS.writeFile conwayConwayTestGenesisJsonTargetFile $ Aeson.encode defaultConwayGenesis

H.renameFile (tempAbsPath' </> "byron-gen-command/genesis.json") (genesisByronDir </> "genesis.json")
-- TODO: create-testnet-data outputs the new shelley genesis do genesis.json
H.renameFile (tempAbsPath' </> "byron-gen-command" </> "genesis.json") (genesisByronDir </> "genesis.json")
-- TODO: create-testnet-data outputs the new shelley genesis to genesis.json
H.renameFile (tempAbsPath' </> "genesis.json") (genesisShelleyDir </> "genesis.shelley.json")

-- TODO: move this to create-testnet-data
-- For some reason when setting "--total-supply 10E16" in create-testnet-data, we're getting negative
-- treasury
H.rewriteJsonFile @Value (genesisShelleyDir </> "genesis.shelley.json") $ \o -> o
& L.key "maxLovelaceSupply" . L._Integer .~ 10_000_000_000_000_000

return genesisShelleyDir

ifaceAddress :: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module Cardano.Testnet.Test.Cli.Babbage.LeadershipSchedule
) where

import Cardano.Api
import qualified Cardano.Api as Api

import Cardano.CLI.Types.Output (QueryTipLocalStateOutput (..))
import Cardano.Node.Configuration.Topology
import Cardano.Testnet

Expand All @@ -32,7 +32,6 @@ import qualified Data.Map.Strict as Map
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Time.Clock as DTC
import GHC.Stack (callStack)
import qualified GHC.Stack as GHC
import System.FilePath ((</>))
import qualified System.Info as SYS
Expand All @@ -49,6 +48,7 @@ import Testnet.Runtime
import Hedgehog (Property, (===))
import qualified Hedgehog as H
import Hedgehog.Extras (threadDelay)
import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO
import qualified Hedgehog.Extras.Test.Base as H
import qualified Hedgehog.Extras.Test.File as H

Expand Down Expand Up @@ -193,6 +193,7 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
, "--tx-file", delegRegTestDelegatorTxFp
]

-- TODO: Can be removed if checkStakeKeyRegistered uses foldEpochState
threadDelay 15_000000

-------------------------------------------------------------------
Expand Down Expand Up @@ -253,74 +254,56 @@ hprop_leadershipSchedule = H.integrationRetryWorkspace 2 "babbage-leadership-sch
testPoolStdOutFp <- case eRuntime of
Left e -> H.failMessage GHC.callStack $ "Failed to start node: " <> show e
Right runtime -> return $ nodeStdout runtime
threadDelay 5_000000

-- Wait for 2 epochs to pass
void $ waitUntilEpoch (Api.File configurationFile)
(Api.File $ IO.sprocketSystemName node1sprocket) (EpochNo 3)

tipDeadline <- H.noteShowM $ DTC.addUTCTime 210 <$> H.noteShowIO DTC.getCurrentTime
currentLeaderShipScheduleFile <- H.noteTempFile work "current-schedule.log"

H.byDeadlineM 10 tipDeadline "Wait for two epochs" $ do
void $ execCli' execConfig
[ "query", "tip"
, "--out-file", work </> "current-tip.json"
]

tipJson <- H.leftFailM . H.readJsonFile $ work </> "current-tip.json"
tip <- H.noteShowM $ H.jsonErrorFail $ J.fromJSON @QueryTipLocalStateOutput tipJson

currEpoch <- case mEpoch tip of
Nothing -> H.failMessage callStack "cardano-cli query tip returned Nothing for EpochNo"
Just currEpoch -> return currEpoch

H.note_ $ "Current Epoch: " <> show currEpoch
H.assert $ currEpoch > 2

id do
currentLeaderShipScheduleFile <- H.noteTempFile work "current-schedule.log"

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

H.byDeadlineM 5 leadershipScheduleDeadline "Failed to query for leadership schedule" $ do
void $ execCli' execConfig
[ "query", "leadership-schedule"
, "--genesis", shelleyGenesisFile tr
, "--stake-pool-id", stakePoolIdNewSpo
, "--vrf-signing-key-file", vrfSkey
, "--out-file", currentLeaderShipScheduleFile
, "--current"
]
void $ execCli' execConfig
[ "query", "leadership-schedule"
, "--genesis", shelleyGenesisFile tr
, "--stake-pool-id", stakePoolIdNewSpo
, "--vrf-signing-key-file", vrfSkey
, "--out-file", currentLeaderShipScheduleFile
, "--current"
]

currentScheduleJson <- H.leftFailM $ H.readJsonFile currentLeaderShipScheduleFile
currentScheduleJson <- H.leftFailM $ H.readJsonFile currentLeaderShipScheduleFile

expectedLeadershipSlotNumbers <- H.noteShowM $ fmap (fmap slotNumber) $ H.leftFail $ J.parseEither (J.parseJSON @[LeadershipSlot]) currentScheduleJson
expectedLeadershipSlotNumbers <- H.noteShowM $ fmap (fmap slotNumber) $ H.leftFail $ J.parseEither (J.parseJSON @[LeadershipSlot]) currentScheduleJson

maxSlotExpected <- H.noteShow $ maximum expectedLeadershipSlotNumbers
maxSlotExpected <- H.noteShow $ maximum expectedLeadershipSlotNumbers

H.assert $ not (L.null expectedLeadershipSlotNumbers)
H.assert $ not (L.null expectedLeadershipSlotNumbers)

leadershipDeadline <- H.noteShowM $ DTC.addUTCTime 90 <$> H.noteShowIO DTC.getCurrentTime
leadershipDeadline <- H.noteShowM $ DTC.addUTCTime 90 <$> H.noteShowIO DTC.getCurrentTime

-- We need enough time to pass such that the expected leadership slots generated by the
-- leadership-schedule command have actually occurred.
(leaderSlots, notLeaderSlots) <- H.byDeadlineM 10 leadershipDeadline "Wait for chain to surpass all expected leadership slots" $ do
(someLeaderSlots, someNotLeaderSlots) <- getRelevantSlots testPoolStdOutFp (minimum expectedLeadershipSlotNumbers)
if L.null someLeaderSlots
then H.failure
else do
maxActualSlot <- H.noteShow $ maximum someLeaderSlots
H.assert $ maxActualSlot >= maxSlotExpected
pure (someLeaderSlots, someNotLeaderSlots)

H.noteShow_ expectedLeadershipSlotNumbers
H.noteShow_ leaderSlots
H.noteShow_ notLeaderSlots
-- TODO: We can further improve this if parameterize foldEpochState's callback on
-- the current slot and current block number.
(leaderSlots, notLeaderSlots) <- H.byDeadlineM 10 leadershipDeadline "Wait for chain to surpass all expected leadership slots" $ do
(someLeaderSlots, someNotLeaderSlots) <- getRelevantSlots testPoolStdOutFp (minimum expectedLeadershipSlotNumbers)
if L.null someLeaderSlots
then H.failure
else do
maxActualSlot <- H.noteShow $ maximum someLeaderSlots
H.assert $ maxActualSlot >= maxSlotExpected
pure (someLeaderSlots, someNotLeaderSlots)

H.noteShow_ expectedLeadershipSlotNumbers
H.noteShow_ leaderSlots
H.noteShow_ notLeaderSlots

-- Double check that we've seen all slots
H.noteShow_ ("Slots not seen as TraceNodeIsLeader nor TraceNodeNotLeader" :: Text)
([minimum expectedLeadershipSlotNumbers .. maxSlotExpected] \\ leaderSlots) \\ notLeaderSlots === []
H.noteShow_ ("Slots not seen as TraceNodeIsLeader nor TraceNodeNotLeader" :: Text)
([minimum expectedLeadershipSlotNumbers .. maxSlotExpected] \\ leaderSlots) \\ notLeaderSlots === []

-- As there are no BFT nodes, the next leadership schedule should match slots assigned exactly
H.noteShow_ (expectedLeadershipSlotNumbers \\ leaderSlots)
H.assert $ L.null (expectedLeadershipSlotNumbers \\ leaderSlots)
H.noteShow_ (expectedLeadershipSlotNumbers \\ leaderSlots)
H.assert $ L.null (expectedLeadershipSlotNumbers \\ leaderSlots)
-- TODO: Re-enable --next leadership schedule test
{-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ module Cardano.Testnet.Test.Cli.Babbage.StakeSnapshot
) where

import Cardano.Api
import qualified Cardano.Api as Api

import Cardano.CLI.Types.Output (QueryTipLocalStateOutput (..))
import Cardano.Testnet

import Prelude

import Control.Monad
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.KeyMap as KM
import qualified Data.Time.Clock as DTC
import GHC.Stack (callStack)
import qualified System.Info as SYS

import Testnet.Process.Cli (execCliStdoutToJson)
Expand All @@ -29,6 +28,7 @@ import Testnet.Runtime

import Hedgehog (Property, (===))
import qualified Hedgehog as H
import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO
import qualified Hedgehog.Extras.Test.Base as H

hprop_stakeSnapshot :: Property
Expand All @@ -49,22 +49,15 @@ hprop_stakeSnapshot = H.integrationRetryWorkspace 2 "babbage-stake-snapshot" $ \
TestnetRuntime
{ testnetMagic
, poolNodes
, configurationFile
} <- cardanoTestnetDefault options conf

poolNode1 <- H.headM poolNodes
poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1
execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic
tipDeadline <- H.noteShowM $ DTC.addUTCTime 210 <$> H.noteShowIO DTC.getCurrentTime

H.byDeadlineM 10 tipDeadline "Wait for two epochs" $ do
tip <- execCliStdoutToJson execConfig [ "query", "tip" ]

currEpoch <- case mEpoch tip of
Nothing -> H.failMessage callStack "cardano-cli query tip returned Nothing for EpochNo"
Just currEpoch -> return currEpoch

H.note_ $ "Current Epoch: " <> show currEpoch
H.assert $ currEpoch > 2
void $ waitUntilEpoch (Api.File configurationFile)
(Api.File $ IO.sprocketSystemName poolSprocket1) (EpochNo 3)

json <- execCliStdoutToJson execConfig [ "query", "stake-snapshot", "--all-stake-pools" ]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ module Cardano.Testnet.Test.Cli.Conway.StakeSnapshot
( hprop_stakeSnapshot
) where

import Cardano.Api
import Cardano.Api as Api

import Cardano.CLI.Types.Output (QueryTipLocalStateOutput (..))
import Cardano.Testnet

import Prelude

import Control.Monad
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.KeyMap as KM
import qualified Data.Time.Clock as DTC
import GHC.Stack (callStack)
import qualified System.Info as SYS

import Testnet.Process.Cli (execCliStdoutToJson)
Expand All @@ -29,6 +27,7 @@ import Testnet.Runtime

import Hedgehog (Property, (===))
import qualified Hedgehog as H
import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO
import qualified Hedgehog.Extras.Test.Base as H

hprop_stakeSnapshot :: Property
Expand All @@ -48,23 +47,16 @@ hprop_stakeSnapshot = H.integrationRetryWorkspace 2 "conway-stake-snapshot" $ \t
TestnetRuntime
{ testnetMagic
, poolNodes
, configurationFile
} <- cardanoTestnetDefault options conf

poolNode1 <- H.headM poolNodes
poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1
execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic

tipDeadline <- H.noteShowM $ DTC.addUTCTime 210 <$> H.noteShowIO DTC.getCurrentTime
void $ waitUntilEpoch (Api.File configurationFile)
(Api.File $ IO.sprocketSystemName poolSprocket1) (EpochNo 3)

H.byDeadlineM 10 tipDeadline "Wait for two epochs" $ do
tip <- execCliStdoutToJson execConfig [ "query", "tip" ]

currEpoch <- case mEpoch tip of
Nothing -> H.failMessage callStack "cardano-cli query tip returned Nothing for EpochNo"
Just currEpoch -> return currEpoch

H.note_ $ "Current Epoch: " <> show currEpoch
H.assert $ currEpoch > 2

json <- execCliStdoutToJson execConfig [ "query", "stake-snapshot", "--all-stake-pools" ]

Expand Down
Loading

0 comments on commit 09f2827

Please sign in to comment.