Skip to content
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

Add cardanoMaxSupply :: Word64 field to CardanoTestnetOptions #4817

Merged
merged 1 commit into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cardano-testnet/src/Parsers/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Testnet
import Testnet.Cardano
import Testnet.Run (runTestnet)
import Testnet.Util.Runtime (readNodeLoggingFormat)

import Testnet.Utils

data CardanoOptions = CardanoOptions
{ maybeTestnetMagic :: Maybe Int
Expand Down Expand Up @@ -55,6 +55,7 @@ optsTestnet = CardanoTestnetOptions
<> OA.showDefault
<> OA.value (cardanoActiveSlotsCoeff defaultTestnetOptions)
)
<*> pMaxLovelaceSupply
<*> OA.option auto
( OA.long "enable-p2p"
<> OA.help "Enable P2P"
Expand Down
22 changes: 6 additions & 16 deletions cardano-testnet/src/Parsers/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@ module Parsers.Shelley
, runShelleyOptions
) where

import Prelude

import Data.Eq
import Data.Function
import Data.Int
import Data.Maybe
import Data.Semigroup
import Options.Applicative
import System.IO (IO)
import Testnet.Run (runTestnet)
import qualified Options.Applicative as OA

import Testnet
import Testnet.Run (runTestnet)
import Testnet.Shelley
import Text.Show
import Testnet.Utils

import qualified Options.Applicative as OA

data ShelleyOptions = ShelleyOptions
{ maybeTestnetMagic :: Maybe Int
Expand Down Expand Up @@ -68,13 +64,7 @@ optsTestnet = ShelleyTestnetOptions
<> OA.showDefault
<> OA.value (shelleySlotLength defaultTestnetOptions)
)
<*> OA.option auto
( OA.long "max-lovelace-supply"
<> OA.help "Max lovelace supply"
<> OA.metavar "INTEGER"
<> OA.showDefault
<> OA.value (shelleyMaxLovelaceSupply defaultTestnetOptions)
)
<*> pMaxLovelaceSupply
<*> OA.option auto
( OA.long "enable-p2p"
<> OA.help "Enable P2P"
Expand Down
45 changes: 25 additions & 20 deletions cardano-testnet/src/Testnet/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,54 @@ module Testnet.Cardano

import Prelude

import qualified Cardano.Crypto.Hash.Blake2b
import qualified Cardano.Crypto.Hash.Class
import Control.Monad
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Trans.Except
import Data.Aeson ((.=))
import qualified Data.Aeson as J
import qualified Data.ByteString as BS
import Data.ByteString.Lazy (ByteString)
import qualified Data.HashMap.Lazy as HM
import Data.List ((\\))
import qualified Data.List as L
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.String
import qualified Hedgehog as H
import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket (..))
import Hedgehog.Extras.Stock.Time (formatIso8601, showUTCTimeSeconds)
import Ouroboros.Network.PeerSelection.LedgerPeers (UseLedgerAfter (..))
import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPoint (..))
import qualified Data.Time.Clock as DTC
import Data.Word
import qualified System.Directory as IO
import System.FilePath.Posix ((</>))
import qualified System.Info as OS

import Cardano.Chain.Genesis (GenesisHash (unGenesisHash), readGenesisData)
import qualified Cardano.Crypto.Hash.Blake2b
import qualified Cardano.Crypto.Hash.Class
import Ouroboros.Network.PeerSelection.LedgerPeers (UseLedgerAfter (..))
import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPoint (..))

import qualified Cardano.Node.Configuration.Topology as NonP2P
import qualified Cardano.Node.Configuration.TopologyP2P as P2P
import qualified Data.Aeson as J
import qualified Data.HashMap.Lazy as HM
import qualified Data.List as L
import qualified Data.Map.Strict as M
import qualified Data.Time.Clock as DTC

import qualified Hedgehog as H
import qualified Hedgehog.Extras.Stock.Aeson as J
import qualified Hedgehog.Extras.Stock.IO.Network.Socket as IO
import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket (..))
import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO
import qualified Hedgehog.Extras.Stock.OS as OS
import qualified Hedgehog.Extras.Stock.String as S
import Hedgehog.Extras.Stock.Time (formatIso8601, showUTCTimeSeconds)
import qualified Hedgehog.Extras.Test.Base as H
import qualified Hedgehog.Extras.Test.Concurrent as H
import qualified Hedgehog.Extras.Test.File as H
import qualified Hedgehog.Extras.Test.Network as H
import qualified System.Directory as IO
import qualified System.Info as OS

import qualified Testnet.Conf as H
import qualified Testnet.Util.Assert as H
import qualified Testnet.Util.Process as H
import Testnet.Util.Process (execCli_)
import Testnet.Util.Runtime as TR (NodeLoggingFormat (..), PaymentKeyPair (..),
PoolNode (PoolNode), PoolNodeKeys (..), TestnetRuntime (..), startNode)

import qualified Testnet.Conf as H

{- HLINT ignore "Redundant flip" -}
{- HLINT ignore "Redundant id" -}
{- HLINT ignore "Use let" -}
Expand All @@ -87,6 +90,7 @@ data CardanoTestnetOptions = CardanoTestnetOptions
, cardanoEpochLength :: Int
, cardanoSlotLength :: Double
, cardanoActiveSlotsCoeff :: Double
, cardanoMaxSupply :: Word64 -- ^ The amount of ADA you are starting your testnet with
, cardanoEnableP2P :: Bool
, cardanoNodeLoggingFormat :: NodeLoggingFormat
} deriving (Eq, Show)
Expand All @@ -98,6 +102,7 @@ defaultTestnetOptions = CardanoTestnetOptions
, cardanoEpochLength = 1500
, cardanoSlotLength = 0.2
, cardanoActiveSlotsCoeff = 0.2
, cardanoMaxSupply = 10020000000
, cardanoEnableP2P = False
, cardanoNodeLoggingFormat = NodeLoggingFormatAsText
}
Expand Down Expand Up @@ -190,8 +195,8 @@ cardanoTestnet testnetOptions H.Conf {..} = do
bftNodeNames = ("node-bft" <>) . show @Int <$> bftNodesN
poolNodeNames = ("node-pool" <>) . show @Int <$> poolNodesN
allNodeNames = bftNodeNames <> poolNodeNames
maxByronSupply = 10020000000
fundsPerGenesisAddress = maxByronSupply `div` numBftNodes
maxByronSupply = cardanoMaxSupply testnetOptions
fundsPerGenesisAddress = maxByronSupply `div` fromIntegral numBftNodes
fundsPerByronAddress = fundsPerGenesisAddress - 100000000
userPoolN = poolNodesN
maxShelleySupply = 1000000000000
Expand Down Expand Up @@ -309,7 +314,7 @@ cardanoTestnet testnetOptions H.Conf {..} = do
, "--k", show @Int securityParam
, "--n-poor-addresses", "0"
, "--n-delegate-addresses", show @Int numBftNodes
, "--total-balance", show @Int maxByronSupply
, "--total-balance", show @Word64 maxByronSupply
, "--delegate-share", "1"
, "--avvm-entry-count", "0"
, "--avvm-entry-balance", "0"
Expand Down Expand Up @@ -359,7 +364,7 @@ cardanoTestnet testnetOptions H.Conf {..} = do
, "--tx", tempAbsPath </> "tx0.tx"
, "--wallet-key", tempAbsPath </> "byron/delegate-keys.000.key"
, "--rich-addr-from", richAddrFrom
, "--txout", show @(String, Int) (txAddr, fundsPerByronAddress)
, "--txout", show @(String, Word64) (txAddr, fundsPerByronAddress)
]

-- Update Proposal and votes
Expand Down
11 changes: 7 additions & 4 deletions cardano-testnet/src/Testnet/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ module Testnet.Shelley
, hprop_testnet_pause
) where

import Prelude


import Control.Monad
import Control.Monad.IO.Class (MonadIO (liftIO))
import Control.Monad.Trans.Resource (MonadResource (liftResourceT), resourceForkIO)
Expand All @@ -22,11 +25,11 @@ import Data.List ((\\))
import Data.Maybe
import Data.String
import Data.Time.Clock (UTCTime)
import Data.Word
import Hedgehog.Extras.Stock.Aeson (rewriteObject)
import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket (..))
import Ouroboros.Network.PeerSelection.LedgerPeers (UseLedgerAfter (..))
import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPoint (..))
import Prelude
import System.FilePath.Posix ((</>))

import qualified Cardano.Node.Configuration.Topology as NonP2P
Expand Down Expand Up @@ -67,7 +70,7 @@ data ShelleyTestnetOptions = ShelleyTestnetOptions
, shelleySecurityParam :: Int
, shelleyEpochLength :: Int
, shelleySlotLength :: Double
, shelleyMaxLovelaceSupply :: Integer
, shelleyMaxLovelaceSupply :: Word64
, shelleyEnableP2P :: Bool
} deriving (Eq, Show)

Expand Down Expand Up @@ -101,7 +104,7 @@ rewriteGenesisSpec testnetOptions startTime =
. HM.insert "securityParam" (J.toJSON @Int (shelleySecurityParam testnetOptions))
. HM.insert "epochLength" (J.toJSON @Int (shelleyEpochLength testnetOptions))
. HM.insert "slotLength" (J.toJSON @Double (shelleySlotLength testnetOptions))
. HM.insert "maxLovelaceSupply" (J.toJSON @Integer (shelleyMaxLovelaceSupply testnetOptions))
. HM.insert "maxLovelaceSupply" (J.toJSON @Word64 (shelleyMaxLovelaceSupply testnetOptions))
. HM.insert "systemStart" (J.toJSON @String (DTC.formatIso8601 startTime))
. flip HM.adjust "protocolParams"
( rewriteObject (HM.insert "decentralisationParam" (toJSON @Double 0.7))
Expand Down Expand Up @@ -362,7 +365,7 @@ shelleyTestnet testnetOptions H.Conf {..} = do
, "--invalid-hereafter", "1000"
, "--fee", "0"
, "--tx-in", genesisTxinResult
, "--tx-out", userNAddr <> "+" <> show @Integer (shelleyMaxLovelaceSupply testnetOptions)
, "--tx-out", userNAddr <> "+" <> show @Word64 (shelleyMaxLovelaceSupply testnetOptions)
, "--certificate-file", tempAbsPath </> "addresses/pool-owner" <> n <> "-stake.reg.cert"
, "--certificate-file", tempAbsPath </> "node-pool" <> n <> "/registration.cert"
, "--certificate-file", tempAbsPath </> "addresses/user" <> n <> "-stake.reg.cert"
Expand Down
27 changes: 23 additions & 4 deletions cardano-testnet/src/Testnet/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module Testnet.Utils
( QueryTipOutput(..)
, queryTip
, waitUntilEpoch

-- ** Parsers
, pMaxLovelaceSupply
) where

import Cardano.Api
Expand All @@ -15,16 +18,19 @@ import Control.Concurrent (threadDelay)
import Control.Exception.Safe (MonadCatch)
import Control.Monad
import Control.Monad.IO.Class
import Data.Aeson (fromJSON)
import Data.Aeson
import Data.Word
import GHC.Stack
import Hedgehog.Extras.Test.Process (ExecConfig)
import Hedgehog.Internal.Property (MonadTest)
import Options.Applicative
import System.Directory (doesFileExist, removeFile)

import qualified Hedgehog.Extras.Test.Base as H
import qualified Hedgehog.Extras.Test.File as H
import qualified Testnet.Util.Process as H
import Hedgehog.Extras.Test.Process (ExecConfig)
import Hedgehog.Internal.Property (MonadTest)

import Testnet.Cardano (CardanoTestnetOptions (..), defaultTestnetOptions)
import qualified Testnet.Util.Process as H

-- | Submit the desired epoch to wait to.
waitUntilEpoch
Expand Down Expand Up @@ -81,3 +87,16 @@ queryTip (QueryTipOutput fp) testnetMag execConfig = do
H.noteShowM $ H.jsonErrorFail $ fromJSON @QueryTipLocalStateOutput tipJSON

newtype QueryTipOutput = QueryTipOutput { unQueryTipOutput :: FilePath}


-- Parsers

pMaxLovelaceSupply :: Parser Word64
pMaxLovelaceSupply =
option auto
( long "max-lovelace-supply"
<> help "Max lovelace supply that your testnet starts with."
<> metavar "WORD64"
<> showDefault
<> value (cardanoMaxSupply defaultTestnetOptions)
)