Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed May 6, 2024
1 parent 5fd9691 commit 0cb17bb
Show file tree
Hide file tree
Showing 31 changed files with 232 additions and 200 deletions.
15 changes: 8 additions & 7 deletions cardano-testnet/cardano-testnet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,25 @@ library
hs-source-dirs: src
exposed-modules: Cardano.Testnet
Parsers.Run
Testnet.Start.Byron
Testnet.Start.Types
Testnet.Components.Configuration
Testnet.Components.DReps
Testnet.Components.SPO
Testnet.Components.Query
Testnet.Components.SPO
Testnet.Components.TestWatchdog
Testnet.Defaults
Testnet.Filepath
Testnet.EpochStateProcessing
Testnet.Filepath
Testnet.Ping
Testnet.Process.Cli
Testnet.Process.Run
Testnet.Property.Assert
Testnet.Property.Run
Testnet.Property.Utils
Testnet.Process.Cli
Testnet.Process.Run
Testnet.Runtime
Testnet.Start.Byron
Testnet.Start.Types
Testnet.SubmitApi
Testnet.Ping
Testnet.Types

other-modules: Parsers.Cardano
Parsers.Help
Expand Down
2 changes: 1 addition & 1 deletion cardano-testnet/src/Cardano/Testnet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ import Testnet.EpochStateProcessing
import Testnet.Filepath
import Testnet.Process.Run (procChairman)
import Testnet.Property.Utils
import Testnet.Runtime
import Testnet.Start.Cardano
import Testnet.Start.Types
import Testnet.Types
2 changes: 1 addition & 1 deletion cardano-testnet/src/Parsers/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import qualified Options.Applicative as OA

import Testnet.Process.Cli
import Testnet.Property.Utils
import Testnet.Runtime (readNodeLoggingFormat)
import Testnet.Start.Cardano
import Testnet.Start.Types
import Testnet.Types (readNodeLoggingFormat)


optsTestnet :: EnvCli -> Parser CardanoTestnetOptions
Expand Down
4 changes: 2 additions & 2 deletions cardano-testnet/src/Testnet/Components/DReps.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ import Testnet.Components.Query (EpochStateView, findLargestUtxoForPay
getCurrentEpochNo, getMinDRepDeposit, waitUntilEpoch)
import qualified Testnet.Process.Cli as H
import qualified Testnet.Process.Run as H
import Testnet.Runtime (KeyPair (..),
import Testnet.Start.Types (anyEraToString)
import Testnet.Types (KeyPair (..),
PaymentKeyInfo (paymentKeyInfoAddr, paymentKeyInfoPair), PaymentKeyPair (..),
SomeKeyPair (..), StakingKeyPair (..))
import Testnet.Start.Types (anyEraToString)

import Hedgehog (MonadTest, evalMaybe)
import qualified Hedgehog.Extras as H
Expand Down
3 changes: 1 addition & 2 deletions cardano-testnet/src/Testnet/Components/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module Testnet.Components.Query
, findUtxosWithAddress
, findLargestUtxoWithAddress
, findLargestUtxoForPaymentKey
, startLedgerNewEpochStateLogging
) where

import Cardano.Api as Api
Expand Down Expand Up @@ -54,7 +53,7 @@ import Lens.Micro (to, (^.))

import Testnet.Property.Assert
import Testnet.Property.Utils (runInBackground)
import Testnet.Runtime
import Testnet.Types

import qualified Hedgehog as H
import Hedgehog.Extras (MonadAssertion)
Expand Down
2 changes: 1 addition & 1 deletion cardano-testnet/src/Testnet/Components/SPO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ import Testnet.Process.Cli hiding (File, unFile)
import qualified Testnet.Process.Run as H
import Testnet.Process.Run (execCli, execCli', execCli_)
import Testnet.Property.Utils
import Testnet.Runtime (PoolNodeKeys (poolNodeKeysColdVkey))
import Testnet.Start.Types
import Testnet.Types (PoolNodeKeys (poolNodeKeysColdVkey))

import Hedgehog
import Hedgehog.Extras (ExecConfig)
Expand Down
4 changes: 2 additions & 2 deletions cardano-testnet/src/Testnet/Defaults.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ import Numeric.Natural
import System.FilePath ((</>))

import Test.Cardano.Ledger.Core.Rational
import Testnet.Runtime (PaymentKeyPair (PaymentKeyPair), PoolNodeKeys (..),
SPOColdKeyPair (..), StakingKeyPair (StakingKeyPair))
import Testnet.Start.Types
import Testnet.Types (PaymentKeyPair (PaymentKeyPair), PoolNodeKeys (..),
SPOColdKeyPair (..), StakingKeyPair (StakingKeyPair))

{- HLINT ignore "Use underscore" -}

Expand Down
164 changes: 2 additions & 162 deletions cardano-testnet/src/Testnet/Runtime.hs
Original file line number Diff line number Diff line change
@@ -1,63 +1,26 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Testnet.Runtime
( LeadershipSlot(..)
, NodeLoggingFormat(..)
, PaymentKeyInfo(..)
, PaymentKeyPair(..)
, StakingKeyPair(..)
, TestnetRuntime(..)
, NodeRuntime(..)
, PoolNode(..)
, PoolNodeKeys(..)
, Delegator(..)
, SPOColdKeyPair(..)
, KeyPair(..)
, SomeKeyPair(..)
, allNodes
, poolSprockets
, poolNodeStdout
, readNodeLoggingFormat
, startNode
, ShelleyGenesis(..)
, shelleyGenesis
, getStartTime
, fromNominalDiffTimeMicro
( startNode
, startLedgerNewEpochStateLogging
) where

import Cardano.Api
import qualified Cardano.Api as Api

import qualified Cardano.Chain.Genesis as G
import Cardano.Crypto.ProtocolMagic (RequiresNetworkMagic (..))
import Cardano.Ledger.Crypto (StandardCrypto)
import Cardano.Ledger.Shelley.Genesis
import Cardano.Node.Configuration.POM
import qualified Cardano.Node.Protocol.Byron as Byron
import Cardano.Node.Types

import Prelude

import Control.Exception.Safe
import Control.Monad
import Control.Monad.State.Strict (StateT)
import Control.Monad.Trans.Resource
import qualified Data.Aeson as A
import qualified Data.List as List
import Data.Text (Text, unpack)
import Data.Time.Clock (UTCTime)
import GHC.Generics (Generic)
import qualified GHC.IO.Handle as IO
import GHC.Stack
import qualified GHC.Stack as GHC
import Network.Socket (PortNumber)
Expand All @@ -71,137 +34,14 @@ import Testnet.Filepath
import qualified Testnet.Ping as Ping
import Testnet.Process.Run
import Testnet.Property.Utils (runInBackground)
import Testnet.Start.Types
import Testnet.Types hiding (testnetMagic)

import Hedgehog (MonadTest)
import qualified Hedgehog as H
import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket (..))
import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as H
import qualified Hedgehog.Extras.Test.Base as H

data TestnetRuntime = TestnetRuntime
{ configurationFile :: !FilePath
, shelleyGenesisFile :: !FilePath
, testnetMagic :: !Int
, poolNodes :: ![PoolNode]
, wallets :: ![PaymentKeyInfo]
, delegators :: ![Delegator]
}

data NodeRuntime = NodeRuntime
{ nodeName :: !String
, nodeIpv4 :: !Text
, nodePort :: !PortNumber
, nodeSprocket :: !Sprocket
, nodeStdinHandle :: !IO.Handle
, nodeStdout :: !FilePath
, nodeStderr :: !FilePath
, nodeProcessHandle :: !IO.ProcessHandle
}

data PoolNode = PoolNode
{ poolRuntime :: NodeRuntime
, poolKeys :: PoolNodeKeys
}

data PoolNodeKeys = PoolNodeKeys
{ poolNodeKeysColdVkey :: FilePath
, poolNodeKeysColdSkey :: FilePath
, poolNodeKeysVrfVkey :: FilePath
, poolNodeKeysVrfSkey :: FilePath
, poolNodeKeysStakingVkey :: FilePath
, poolNodeKeysStakingSkey :: FilePath
} deriving (Eq, Show)

data SPOColdKeyPair = SPOColdKeyPair
{ spoColdVKey :: FilePath
, spoColdSKey :: FilePath
} deriving (Eq, Show)

data PaymentKeyPair = PaymentKeyPair
{ paymentVKey :: FilePath
, paymentSKey :: FilePath
} deriving (Eq, Show)

data PaymentKeyInfo = PaymentKeyInfo
{ paymentKeyInfoPair :: PaymentKeyPair
, paymentKeyInfoAddr :: Text
} deriving (Eq, Show)

data StakingKeyPair = StakingKeyPair
{ stakingVKey :: FilePath
, stakingSKey :: FilePath
} deriving (Eq, Show)

data Delegator = Delegator
{ paymentKeyPair :: PaymentKeyPair
, stakingKeyPair :: StakingKeyPair
} deriving (Eq, Show)

data LeadershipSlot = LeadershipSlot
{ slotNumber :: Int
, slotTime :: Text
} deriving (Eq, Show, Generic, FromJSON)

class KeyPair a where
secretKey :: a -> FilePath

instance KeyPair PaymentKeyPair where
secretKey :: PaymentKeyPair -> FilePath
secretKey = paymentSKey

instance KeyPair StakingKeyPair where
secretKey :: StakingKeyPair -> FilePath
secretKey = stakingSKey

instance KeyPair SPOColdKeyPair where
secretKey :: SPOColdKeyPair -> FilePath
secretKey = spoColdSKey

data SomeKeyPair = forall a . KeyPair a => SomeKeyPair a

instance KeyPair SomeKeyPair where
secretKey :: SomeKeyPair -> FilePath
secretKey (SomeKeyPair x) = secretKey x

poolNodeStdout :: PoolNode -> FilePath
poolNodeStdout = nodeStdout . poolRuntime

poolSprockets :: TestnetRuntime -> [Sprocket]
poolSprockets = fmap (nodeSprocket . poolRuntime) . poolNodes

shelleyGenesis :: (H.MonadTest m, MonadIO m, HasCallStack) => TestnetRuntime -> m (ShelleyGenesis StandardCrypto)
shelleyGenesis TestnetRuntime{shelleyGenesisFile} = withFrozenCallStack $
H.evalEither =<< H.evalIO (A.eitherDecodeFileStrict' shelleyGenesisFile)

getStartTime
:: (H.MonadTest m, MonadIO m, HasCallStack)
=> FilePath -> TestnetRuntime -> m UTCTime
getStartTime tempRootPath TestnetRuntime{configurationFile} = withFrozenCallStack $ H.evalEither <=< H.evalIO . runExceptT $ do
byronGenesisFile <-
decodeNodeConfiguration configurationFile >>= \case
NodeProtocolConfigurationCardano NodeByronProtocolConfiguration{npcByronGenesisFile} _ _ _ _ ->
pure $ unGenesisFile npcByronGenesisFile
let byronGenesisFilePath = tempRootPath </> byronGenesisFile
G.gdStartTime . G.configGenesisData <$> decodeGenesisFile byronGenesisFilePath
where
decodeNodeConfiguration :: FilePath -> ExceptT String IO NodeProtocolConfiguration
decodeNodeConfiguration file = do
partialNodeCfg <- ExceptT $ A.eitherDecodeFileStrict' file
fmap ncProtocolConfig . liftEither . makeNodeConfiguration $ defaultPartialNodeConfiguration <> partialNodeCfg
decodeGenesisFile :: FilePath -> ExceptT String IO G.Config
decodeGenesisFile fp = withExceptT (docToString . prettyError) $
Byron.readGenesis (GenesisFile fp) Nothing RequiresNoMagic

readNodeLoggingFormat :: String -> Either String NodeLoggingFormat
readNodeLoggingFormat = \case
"json" -> Right NodeLoggingFormatAsJson
"text" -> Right NodeLoggingFormatAsText
s -> Left $ "Unrecognised node logging format: " <> show s <> ". Valid options: \"json\", \"text\""

allNodes :: TestnetRuntime -> [NodeRuntime]
allNodes tr = fmap poolRuntime (poolNodes tr)

data NodeStartFailure
= ProcessRelatedFailure ProcessError
| ExecutableRelatedFailure ExecutableError
Expand Down
3 changes: 2 additions & 1 deletion cardano-testnet/src/Testnet/Start/Cardano.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ import Testnet.Filepath
import qualified Testnet.Process.Run as H
import Testnet.Process.Run
import qualified Testnet.Property.Assert as H
import Testnet.Runtime as TR hiding (shelleyGenesis)
import Testnet.Runtime as TR
import qualified Testnet.Start.Byron as Byron
import Testnet.Start.Types
import Testnet.Types as TR hiding (shelleyGenesis)

import Hedgehog (MonadTest)
import qualified Hedgehog as H
Expand Down

0 comments on commit 0cb17bb

Please sign in to comment.