Skip to content

Commit

Permalink
Common runtime types for cardan-testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Jun 24, 2022
1 parent b9b24d7 commit ac3d28e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 46 deletions.
1 change: 1 addition & 0 deletions cardano-testnet/cardano-testnet.cabal
Expand Up @@ -57,6 +57,7 @@ library
hs-source-dirs: src
exposed-modules: Test.Base
Test.Process
Test.Runtime
Testnet.Babbage
Testnet.Byron
Testnet.Cardano
Expand Down
37 changes: 37 additions & 0 deletions cardano-testnet/src/Test/Runtime.hs
@@ -0,0 +1,37 @@
module Test.Runtime
( TestnetRuntime(..)
, TestnetNode(..)
, Wallet(..)
) where

import Data.Eq (Eq)
import Data.Int (Int)
import Data.String (String)
import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket (..))
import System.IO (FilePath)
import Text.Show (Show)

import qualified System.IO as IO
import qualified System.Process as IO

data TestnetRuntime = TestnetRuntime
{ configurationFile :: FilePath
, testnetMagic :: Int
, bftNodes :: [TestnetNode]
, poolNodes :: [TestnetNode]
, wallets :: [Wallet]
}

data TestnetNode = TestnetNode
{ nodeName :: String
, nodeSprocket :: Sprocket
, nodeStdinHandle :: IO.Handle
, nodeStdout :: FilePath
, nodeStderr :: FilePath
, nodeProcessHandle :: IO.ProcessHandle
}

data Wallet = Wallet
{ paymentVKey :: FilePath
, paymentSKey :: FilePath
} deriving (Eq, Show)
26 changes: 3 additions & 23 deletions cardano-testnet/src/Testnet/Babbage.hs
Expand Up @@ -38,7 +38,7 @@ import GHC.Float (Double)
import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket (..))
import Hedgehog.Extras.Stock.Time (showUTCTimeSeconds)
import System.FilePath.Posix ((</>))
import System.IO (FilePath)
import Test.Runtime (TestnetRuntime(..), TestnetNode(..), Wallet(..))
import Text.Show (Show(show))

import qualified Data.Aeson as J
Expand Down Expand Up @@ -88,27 +88,6 @@ data TestnetNodeOptions = TestnetNodeOptions deriving (Eq, Show)
defaultTestnetNodeOptions :: TestnetNodeOptions
defaultTestnetNodeOptions = TestnetNodeOptions

data TestnetRuntime = TestnetRuntime
{ configurationFile :: FilePath
, testnetMagic :: Int
, poolNodes :: [TestnetNode]
, wallets :: [Wallet]
}

data TestnetNode = TestnetNode
{ nodeName :: String
, nodeSprocket :: Sprocket
, nodeStdinHandle :: IO.Handle
, nodeStdout :: FilePath
, nodeStderr :: FilePath
, nodeProcessHandle :: IO.ProcessHandle
}

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

-- | For an unknown reason, CLI commands are a lot slower on Windows than on Linux and
-- MacOS. We need to allow a lot more time to set up a testnet.
startTimeOffsetSeconds :: DTC.NominalDiffTime
Expand Down Expand Up @@ -399,5 +378,6 @@ testnet testnetOptions H.Conf {..} = do
poolStdouts
poolStderrs
poolProcessHandles
, wallets = []
, wallets = wallets
, bftNodes = []
}
24 changes: 1 addition & 23 deletions cardano-testnet/src/Testnet/Cardano.hs
Expand Up @@ -47,7 +47,7 @@ import Hedgehog.Extras.Stock.Time (formatIso8601, showUTCTimeSeconds)
import Ouroboros.Network.PeerSelection.LedgerPeers (UseLedgerAfter (..))
import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPoint (..))
import System.FilePath.Posix ((</>))
import System.IO (FilePath)
import Test.Runtime (TestnetRuntime(..), TestnetNode(..), Wallet(..))
import Text.Read (Read)
import Text.Show (Show(show))

Expand Down Expand Up @@ -124,34 +124,12 @@ defaultTestnetNodeOptions = TestnetNodeOptions
{ extraNodeCliArgs = []
}

data TestnetRuntime = TestnetRuntime
{ configurationFile :: FilePath
, testnetMagic :: Int
, bftNodes :: [TestnetNode]
, poolNodes :: [TestnetNode]
, wallets :: [Wallet]
}

bftSprockets :: TestnetRuntime -> [Sprocket]
bftSprockets = fmap nodeSprocket . bftNodes

allNodes :: TestnetRuntime -> [TestnetNode]
allNodes tr = bftNodes tr <> poolNodes tr

data TestnetNode = TestnetNode
{ nodeName :: String
, nodeSprocket :: Sprocket
, nodeStdinHandle :: IO.Handle
, nodeStdout :: FilePath
, nodeStderr :: FilePath
, nodeProcessHandle :: IO.ProcessHandle
}

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

ifaceAddress :: String
ifaceAddress = "127.0.0.1"

Expand Down

0 comments on commit ac3d28e

Please sign in to comment.