From 44aef75bc45417c466807ed858394261d75a7327 Mon Sep 17 00:00:00 2001 From: MarcFontaine Date: Wed, 2 Nov 2022 12:48:58 +0100 Subject: [PATCH] Reorder module hierarchy --- .../test/Spec/Chairman/Byron.hs | 2 +- .../test/Spec/Chairman/Cardano.hs | 4 +- .../test/Spec/Chairman/Chairman.hs | 2 +- .../test/Spec/Chairman/Shelley.hs | 4 +- cardano-testnet/cardano-testnet.cabal | 40 +++---- cardano-testnet/src/Parsers/Babbage.hs | 14 +-- cardano-testnet/src/Parsers/Cardano.hs | 18 +-- cardano-testnet/src/Testnet/Babbage.hs | 13 +- cardano-testnet/src/Testnet/Byron.hs | 2 +- cardano-testnet/src/Testnet/Cardano.hs | 12 +- cardano-testnet/src/Testnet/Conf.hs | 13 -- cardano-testnet/src/Testnet/Run.hs | 2 +- cardano-testnet/src/Testnet/Shelley.hs | 9 +- cardano-testnet/src/Testnet/SubmitApi.hs | 111 ------------------ cardano-testnet/src/Testnet/Utils.hs | 2 +- cardano-testnet/src/{Test => Util}/Assert.hs | 6 +- cardano-testnet/src/{Test => Util}/Base.hs | 2 +- .../{test/Test/Util.hs => src/Util/Ignore.hs} | 2 +- cardano-testnet/src/{Test => Util}/Process.hs | 2 +- cardano-testnet/src/{Test => Util}/Runtime.hs | 5 +- cardano-testnet/test/Main.hs | 26 ++-- .../Cli/Alonzo/LeadershipSchedule.hs | 12 +- .../Cli/Babbage/LeadershipSchedule.hs | 12 +- .../test/{Spec => Test}/Cli/KesPeriodInfo.hs | 19 ++- .../Cli/KesPeriodInfo.hs => Test/Misc.hs} | 2 +- .../test/{Spec => Test}/Node/Shutdown.hs | 14 +-- .../{Spec => Test}/ShutdownOnSlotSynced.hs | 29 ++--- 27 files changed, 117 insertions(+), 262 deletions(-) delete mode 100644 cardano-testnet/src/Testnet/SubmitApi.hs rename cardano-testnet/src/{Test => Util}/Assert.hs (97%) rename cardano-testnet/src/{Test => Util}/Base.hs (96%) rename cardano-testnet/{test/Test/Util.hs => src/Util/Ignore.hs} (98%) rename cardano-testnet/src/{Test => Util}/Process.hs (99%) rename cardano-testnet/src/{Test => Util}/Runtime.hs (98%) rename cardano-testnet/test/{Spec => Test}/Cli/Alonzo/LeadershipSchedule.hs (98%) rename cardano-testnet/test/{Spec => Test}/Cli/Babbage/LeadershipSchedule.hs (96%) rename cardano-testnet/test/{Spec => Test}/Cli/KesPeriodInfo.hs (98%) rename cardano-testnet/test/{Testnet/Properties/Cli/KesPeriodInfo.hs => Test/Misc.hs} (97%) rename cardano-testnet/test/{Spec => Test}/Node/Shutdown.hs (93%) rename cardano-testnet/test/{Spec => Test}/ShutdownOnSlotSynced.hs (83%) diff --git a/cardano-node-chairman/test/Spec/Chairman/Byron.hs b/cardano-node-chairman/test/Spec/Chairman/Byron.hs index cdadd6fa6b5..d3f53eb51b4 100644 --- a/cardano-node-chairman/test/Spec/Chairman/Byron.hs +++ b/cardano-node-chairman/test/Spec/Chairman/Byron.hs @@ -14,9 +14,9 @@ import qualified Hedgehog as H import qualified Hedgehog.Extras.Test.Base as H import qualified Hedgehog.Extras.Test.Process as H import qualified System.Directory as IO -import qualified Test.Base as H import qualified Testnet.Byron as H import qualified Testnet.Conf as H +import qualified Util.Base as H {- HLINT ignore "Reduce duplication" -} {- HLINT ignore "Redundant <&>" -} diff --git a/cardano-node-chairman/test/Spec/Chairman/Cardano.hs b/cardano-node-chairman/test/Spec/Chairman/Cardano.hs index 3d20dc78d84..f7f743b162c 100644 --- a/cardano-node-chairman/test/Spec/Chairman/Cardano.hs +++ b/cardano-node-chairman/test/Spec/Chairman/Cardano.hs @@ -17,10 +17,10 @@ import qualified Hedgehog as H import qualified Hedgehog.Extras.Test.Base as H import qualified Hedgehog.Extras.Test.Process as H import qualified System.Directory as IO -import qualified Test.Base as H -import qualified Test.Runtime as H import qualified Testnet.Cardano as H import qualified Testnet.Conf as H +import qualified Util.Base as H +import qualified Util.Runtime as H {- HLINT ignore "Reduce duplication" -} {- HLINT ignore "Redundant <&>" -} diff --git a/cardano-node-chairman/test/Spec/Chairman/Chairman.hs b/cardano-node-chairman/test/Spec/Chairman/Chairman.hs index 5f1c192d429..8a3942b5ac2 100644 --- a/cardano-node-chairman/test/Spec/Chairman/Chairman.hs +++ b/cardano-node-chairman/test/Spec/Chairman/Chairman.hs @@ -31,8 +31,8 @@ import qualified Hedgehog.Extras.Test.Process as H import qualified System.Environment as IO import qualified System.IO as IO import qualified System.Process as IO -import qualified Test.Process as H import qualified Testnet.Conf as H +import qualified Util.Process as H {- HLINT ignore "Reduce duplication" -} {- HLINT ignore "Redundant <&>" -} diff --git a/cardano-node-chairman/test/Spec/Chairman/Shelley.hs b/cardano-node-chairman/test/Spec/Chairman/Shelley.hs index 0da2b6a054a..7b7cc23ed2e 100644 --- a/cardano-node-chairman/test/Spec/Chairman/Shelley.hs +++ b/cardano-node-chairman/test/Spec/Chairman/Shelley.hs @@ -12,10 +12,10 @@ import qualified Hedgehog as H import qualified Hedgehog.Extras.Test.Base as H import qualified Hedgehog.Extras.Test.Process as H import qualified System.Directory as IO -import qualified Test.Base as H -import qualified Test.Runtime as H import qualified Testnet.Conf as H import qualified Testnet.Shelley as H +import qualified Util.Base as H +import qualified Util.Runtime as H hprop_chairman :: H.Property hprop_chairman = H.integration . H.runFinallies . H.workspace "chairman" $ \tempAbsPath' -> do diff --git a/cardano-testnet/cardano-testnet.cabal b/cardano-testnet/cardano-testnet.cabal index 07994cfcf7f..cf4f6c5a2f6 100644 --- a/cardano-testnet/cardano-testnet.cabal +++ b/cardano-testnet/cardano-testnet.cabal @@ -30,7 +30,6 @@ library build-depends: aeson , ansi-terminal - , base16-bytestring , bytestring , cardano-api , cardano-cli @@ -42,8 +41,6 @@ library , filepath , hedgehog , hedgehog-extras - , http-client - , http-types , optparse-applicative-fork , ouroboros-network , process @@ -51,6 +48,9 @@ library , resourcet , safe-exceptions , stm + , tasty + , tasty-expected-failure + , tasty-hedgehog , text , time , transformers @@ -63,10 +63,11 @@ library Parsers.Cardano Parsers.Shelley Parsers.Version - Test.Assert - Test.Base - Test.Process - Test.Runtime + Util.Assert + Util.Base + Util.Ignore + Util.Process + Util.Runtime Testnet Testnet.Babbage Testnet.Byron @@ -74,7 +75,6 @@ library Testnet.Conf Testnet.Run Testnet.Shelley - Testnet.SubmitApi Testnet.Utils other-modules: Paths_cardano_testnet @@ -100,33 +100,31 @@ test-suite cardano-testnet-tests main-is: Main.hs + other-modules: Test.Cli.Alonzo.LeadershipSchedule + Test.Cli.Babbage.LeadershipSchedule + Test.Cli.KesPeriodInfo + Test.Misc + Test.Node.Shutdown + Test.ShutdownOnSlotSynced + type: exitcode-stdio-1.0 - build-depends: cardano-testnet - , aeson >= 2.1.0.0 + build-depends: aeson , cardano-api , cardano-cli + , cardano-testnet , containers , directory , filepath - , hedgehog + , hedgehog , hedgehog-extras , process , tasty - , tasty-expected-failure - , tasty-hedgehog , text , time + other-modules: - Spec.Cli.Alonzo.LeadershipSchedule - Spec.Cli.Babbage.LeadershipSchedule - Spec.Cli.KesPeriodInfo - Spec.Node.Shutdown - Spec.ShutdownOnSlotSynced - Testnet.Properties.Cli.KesPeriodInfo - - Test.Util ghc-options: -threaded -rtsopts -with-rtsopts=-N -with-rtsopts=-T diff --git a/cardano-testnet/src/Parsers/Babbage.hs b/cardano-testnet/src/Parsers/Babbage.hs index b0e109215e0..f6c3a0c3ab7 100644 --- a/cardano-testnet/src/Parsers/Babbage.hs +++ b/cardano-testnet/src/Parsers/Babbage.hs @@ -4,20 +4,14 @@ module Parsers.Babbage , runBabbageOptions ) where -import Data.Eq -import Data.Function -import Data.Int -import Data.Maybe -import Data.Semigroup +import Prelude import Options.Applicative -import System.IO (IO) -import Test.Runtime (readNodeLoggingFormat) +import qualified Options.Applicative as OA + import Testnet import Testnet.Babbage import Testnet.Run (runTestnet) -import Text.Show - -import qualified Options.Applicative as OA +import Util.Runtime (readNodeLoggingFormat) data BabbageOptions = BabbageOptions { maybeTestnetMagic :: Maybe Int diff --git a/cardano-testnet/src/Parsers/Cardano.hs b/cardano-testnet/src/Parsers/Cardano.hs index 55aaa667b2c..104834028db 100644 --- a/cardano-testnet/src/Parsers/Cardano.hs +++ b/cardano-testnet/src/Parsers/Cardano.hs @@ -6,23 +6,17 @@ module Parsers.Cardano , runCardanoOptions ) where -import Data.Eq -import Data.Function -import Data.Int -import Data.Maybe -import Data.Semigroup -import GHC.Enum +import Prelude +import qualified Data.List as L import Options.Applicative -import System.IO (IO) -import Test.Runtime (readNodeLoggingFormat) +import qualified Options.Applicative as OA +import Text.Read + +import Util.Runtime (readNodeLoggingFormat) import Testnet import Testnet.Cardano import Testnet.Run (runTestnet) -import Text.Read -import Text.Show -import qualified Data.List as L -import qualified Options.Applicative as OA data CardanoOptions = CardanoOptions { maybeTestnetMagic :: Maybe Int diff --git a/cardano-testnet/src/Testnet/Babbage.hs b/cardano-testnet/src/Testnet/Babbage.hs index 50633367fd6..50cc4160f60 100644 --- a/cardano-testnet/src/Testnet/Babbage.hs +++ b/cardano-testnet/src/Testnet/Babbage.hs @@ -25,10 +25,6 @@ import Data.Aeson (encode, object, toJSON, (.=)) import Hedgehog.Extras.Stock.Time (showUTCTimeSeconds) import System.FilePath.Posix (()) -import Test.Runtime (Delegator (..), NodeLoggingFormat (..), PaymentKeyPair (..), - PoolNode (PoolNode), PoolNodeKeys (..), StakingKeyPair (..), - TestnetRuntime (..), startNode) - import qualified Data.HashMap.Lazy as HM import qualified Data.List as L import qualified Data.Time.Clock as DTC @@ -37,10 +33,15 @@ import qualified Hedgehog.Extras.Stock.OS as OS import qualified Hedgehog.Extras.Test.Base as H import qualified Hedgehog.Extras.Test.File as H import qualified System.Info as OS -import qualified Test.Assert as H + +import qualified Util.Assert as H +import Util.Process (execCli_) +import Util.Runtime (Delegator (..), NodeLoggingFormat (..), PaymentKeyPair (..), + PoolNode (PoolNode), PoolNodeKeys (..), StakingKeyPair (..), + TestnetRuntime (..), startNode) import qualified Testnet.Conf as H -import Test.Process (execCli_) + {- HLINT ignore "Redundant flip" -} diff --git a/cardano-testnet/src/Testnet/Byron.hs b/cardano-testnet/src/Testnet/Byron.hs index e344a7d922c..065260821b2 100644 --- a/cardano-testnet/src/Testnet/Byron.hs +++ b/cardano-testnet/src/Testnet/Byron.hs @@ -52,8 +52,8 @@ import qualified Hedgehog.Extras.Test.Process as H import qualified System.Info as OS import qualified System.IO as IO import qualified System.Process as IO -import qualified Test.Process as H import qualified Testnet.Conf as H +import qualified Util.Process as H {- HLINT ignore "Reduce duplication" -} {- HLINT ignore "Redundant <&>" -} diff --git a/cardano-testnet/src/Testnet/Cardano.hs b/cardano-testnet/src/Testnet/Cardano.hs index cd9a355694b..f6d8f1d34b0 100644 --- a/cardano-testnet/src/Testnet/Cardano.hs +++ b/cardano-testnet/src/Testnet/Cardano.hs @@ -30,10 +30,6 @@ import Hedgehog.Extras.Stock.Time (formatIso8601, showUTCTimeSeconds) import Ouroboros.Network.PeerSelection.LedgerPeers (UseLedgerAfter (..)) import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPoint (..)) import System.FilePath.Posix (()) -import Test.Runtime as TR (NodeLoggingFormat (..), PaymentKeyPair (..), PoolNode (PoolNode), - PoolNodeKeys (..), TestnetRuntime (..), startNode) - -import Test.Process (execCli_) import qualified Cardano.Node.Configuration.Topology as NonP2P import qualified Cardano.Node.Configuration.TopologyP2P as P2P @@ -53,8 +49,12 @@ 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 Test.Assert as H -import qualified Test.Process as H +import qualified Util.Assert as H +import qualified Util.Process as H +import Util.Process (execCli_) +import Util.Runtime as TR (NodeLoggingFormat (..), PaymentKeyPair (..), PoolNode (PoolNode), + PoolNodeKeys (..), TestnetRuntime (..), startNode) + import qualified Testnet.Conf as H {- HLINT ignore "Redundant flip" -} diff --git a/cardano-testnet/src/Testnet/Conf.hs b/cardano-testnet/src/Testnet/Conf.hs index ae67a00f8e2..24c31a630d4 100644 --- a/cardano-testnet/src/Testnet/Conf.hs +++ b/cardano-testnet/src/Testnet/Conf.hs @@ -6,8 +6,6 @@ module Testnet.Conf , YamlFilePath(..) , Conf(..) , mkConf - - , SubmitApiConfig(..) ) where import Control.Monad @@ -15,7 +13,6 @@ import Data.Eq import Data.Function import Data.Int import Data.Maybe -import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket (..)) import System.FilePath.Posix (()) import System.IO (FilePath) import Text.Show @@ -52,13 +49,3 @@ mkConf (ProjectBase base) (YamlFilePath configurationTemplate) tempAbsPath maybe logDir <- H.noteTempFile tempAbsPath "logs" return $ Conf {..} - -data SubmitApiConfig = SubmitApiConfig - { tempBaseAbsPath :: FilePath - , base :: FilePath - , configFile :: FilePath - , sprocket :: Sprocket - , testnetMagic :: Int - , stdoutFile :: FilePath - , stderrFile :: FilePath - } deriving (Eq, Show) diff --git a/cardano-testnet/src/Testnet/Run.hs b/cardano-testnet/src/Testnet/Run.hs index 0f3fa50bca7..46227ab9c18 100644 --- a/cardano-testnet/src/Testnet/Run.hs +++ b/cardano-testnet/src/Testnet/Run.hs @@ -22,8 +22,8 @@ import qualified System.Console.ANSI as ANSI import qualified System.Directory as IO import qualified System.Exit as IO import qualified System.IO as IO -import qualified Test.Base as H import qualified Testnet.Conf as H +import qualified Util.Base as H testnetProperty :: Maybe Int -> (H.Conf -> H.Integration ()) -> H.Property testnetProperty maybeTestnetMagic tn = H.integration . H.runFinallies . H.workspace "chairman" $ \tempAbsPath' -> do diff --git a/cardano-testnet/src/Testnet/Shelley.hs b/cardano-testnet/src/Testnet/Shelley.hs index 08ad12add10..a5a4a31ae90 100644 --- a/cardano-testnet/src/Testnet/Shelley.hs +++ b/cardano-testnet/src/Testnet/Shelley.hs @@ -28,8 +28,6 @@ import Hedgehog.Extras.Stock.IO.Network.Sprocket (Sprocket(..)) import Ouroboros.Network.PeerSelection.LedgerPeers (UseLedgerAfter(..)) import Ouroboros.Network.PeerSelection.RelayAccessPoint (RelayAccessPoint(..)) import System.FilePath.Posix (()) -import Test.Process (execCli_) -import Test.Runtime hiding (allNodes) import qualified Cardano.Node.Configuration.Topology as NonP2P import qualified Cardano.Node.Configuration.TopologyP2P as P2P @@ -52,9 +50,12 @@ import qualified Hedgehog.Extras.Test.Network as H import qualified Hedgehog.Extras.Test.Process as H import qualified System.Directory as IO import qualified System.Info as OS -import qualified Test.Base as H -import qualified Test.Process as H import qualified Testnet.Conf as H +import qualified Util.Base as H +import qualified Util.Process as H +import Util.Process (execCli_) +import Util.Runtime hiding (allNodes) + {- HLINT ignore "Redundant <&>" -} {- HLINT ignore "Redundant flip" -} diff --git a/cardano-testnet/src/Testnet/SubmitApi.hs b/cardano-testnet/src/Testnet/SubmitApi.hs deleted file mode 100644 index b481d2e1270..00000000000 --- a/cardano-testnet/src/Testnet/SubmitApi.hs +++ /dev/null @@ -1,111 +0,0 @@ -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE RecordWildCards #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeApplications #-} - -module Testnet.SubmitApi - ( submitApi - , submitApiSubmitTransaction - ) where - -import Control.Monad -import Data.Aeson (FromJSON (..), (.:)) -import Data.Eq -import Data.Function -import Data.Functor -import Data.Int -import Data.Maybe -import Data.Semigroup -import Data.Text (Text) -import GHC.Generics -import System.IO (FilePath) -import Text.Show - -import qualified Data.Aeson as J -import qualified Data.ByteString.Base16 as Base16 -import qualified Data.ByteString.Lazy as LBS -import qualified Data.Text as Text -import qualified Data.Text.Encoding as Text -import qualified GHC.Stack as GHC -import qualified Hedgehog as H -import qualified Hedgehog.Extras.Stock.IO.Network.Socket as IO -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 -import qualified Hedgehog.Extras.Test.Process as H -import qualified Network.HTTP.Client as HTTP -import qualified Network.HTTP.Types.Status as HTTP -import qualified System.IO as IO -import qualified System.Process as IO -import qualified Test.Process as H -import qualified Testnet.Conf as H - -{- HLINT ignore "Reduce duplication" -} -{- HLINT ignore "Redundant <&>" -} -{- HLINT ignore "Redundant flip" -} -{- HLINT ignore "Use head" -} - -submitApi :: H.SubmitApiConfig -> H.Integration Int -submitApi H.SubmitApiConfig {..} = do - hStdout <- H.openFile stdoutFile IO.WriteMode - hStderr <- H.openFile stderrFile IO.WriteMode - - H.note_ tempBaseAbsPath - - [port] <- H.noteShowIO $ IO.allocateRandomPorts 1 - - void $ H.createProcess =<< - ( H.procSubmitApi - [ "--config", configFile - , "--socket-path", IO.sprocketArgumentName sprocket - , "--port", show @Int port - , "--testnet-magic", show @Int testnetMagic - ] <&> - ( \cp -> cp - { IO.std_in = IO.CreatePipe - , IO.std_out = IO.UseHandle hStdout - , IO.std_err = IO.UseHandle hStderr - , IO.cwd = Just tempBaseAbsPath - } - ) - ) - - return port - -newtype ObjectWithCBorHexField = ObjectWithCBorHexField - { cborHex :: Text - } deriving (Eq, Show, Generic) - -instance FromJSON ObjectWithCBorHexField where - parseJSON = J.withObject "ObjectWithCBorHexField" $ \obj -> ObjectWithCBorHexField - <$> obj .: "cborHex" - -submitApiSubmitTransaction :: Int -> FilePath -> H.Integration LBS.ByteString -submitApiSubmitTransaction port txFile = GHC.withFrozenCallStack $ do - txJson <- H.readJsonFile txFile & H.leftFailM - - objectWithCBorHexField <- J.fromJSON @ObjectWithCBorHexField txJson & H.jsonErrorFail - - bs <- Base16.decode (Text.encodeUtf8 (cborHex objectWithCBorHexField)) & H.leftFail - - let url = "http://localhost:" <> show @Int port <> "/api/submit/tx" - - manager <- H.evalIO $ HTTP.newManager HTTP.defaultManagerSettings - request <- H.evalIO $ HTTP.parseRequest url <&> \r -> r - { HTTP.method = "POST" - , HTTP.requestBody = HTTP.RequestBodyLBS (LBS.fromStrict bs) - , HTTP.requestHeaders = - [ ("Content-Type", "application/cbor") - ] - } - response <- H.evalIO $ HTTP.httpLbs request manager - - let status = HTTP.responseStatus response - - unless (HTTP.statusIsSuccessful status) $ do - H.failWithCustom GHC.callStack Nothing (show status) - - H.note_ $ "Transaction ID: " <> Text.unpack (Text.decodeUtf8 (LBS.toStrict (HTTP.responseBody response))) - - return $ HTTP.responseBody response diff --git a/cardano-testnet/src/Testnet/Utils.hs b/cardano-testnet/src/Testnet/Utils.hs index d223881110c..9fb1686e703 100644 --- a/cardano-testnet/src/Testnet/Utils.hs +++ b/cardano-testnet/src/Testnet/Utils.hs @@ -23,7 +23,7 @@ import System.Directory (doesFileExist, removeFile) import qualified Hedgehog.Extras.Test.Base as H import qualified Hedgehog.Extras.Test.File as H -import qualified Test.Process as H +import qualified Util.Process as H -- | Submit the desired epoch to wait to. diff --git a/cardano-testnet/src/Test/Assert.hs b/cardano-testnet/src/Util/Assert.hs similarity index 97% rename from cardano-testnet/src/Test/Assert.hs rename to cardano-testnet/src/Util/Assert.hs index 6f0c20d93a1..1a1aba0fe53 100644 --- a/cardano-testnet/src/Test/Assert.hs +++ b/cardano-testnet/src/Util/Assert.hs @@ -4,7 +4,7 @@ {- HLINT ignore "Redundant return" -} -module Test.Assert +module Util.Assert ( readJsonLines , assertChainExtended , getRelevantLeaderSlots @@ -30,7 +30,6 @@ import Hedgehog (MonadTest) import Hedgehog.Extras.Internal.Test.Integration (IntegrationState) import System.FilePath (FilePath) import System.IO (IO) -import Test.Runtime (NodeLoggingFormat (..)) import Text.Show (Show (..)) import qualified Data.Aeson as Aeson @@ -42,7 +41,8 @@ import qualified Data.Time.Clock as DTC import qualified Hedgehog as H import qualified Hedgehog.Extras.Stock.IO.File as IO import qualified Hedgehog.Extras.Test.Base as H -import qualified Test.Process as H +import qualified Util.Process as H +import Util.Runtime (NodeLoggingFormat (..)) newlineBytes :: Word8 newlineBytes = 10 diff --git a/cardano-testnet/src/Test/Base.hs b/cardano-testnet/src/Util/Base.hs similarity index 96% rename from cardano-testnet/src/Test/Base.hs rename to cardano-testnet/src/Util/Base.hs index 86608eec3e5..1a6b68c7d4a 100644 --- a/cardano-testnet/src/Test/Base.hs +++ b/cardano-testnet/src/Util/Base.hs @@ -1,4 +1,4 @@ -module Test.Base +module Util.Base ( integration , isLinux ) where diff --git a/cardano-testnet/test/Test/Util.hs b/cardano-testnet/src/Util/Ignore.hs similarity index 98% rename from cardano-testnet/test/Test/Util.hs rename to cardano-testnet/src/Util/Ignore.hs index 5b874221a75..5546c871be1 100644 --- a/cardano-testnet/test/Test/Util.hs +++ b/cardano-testnet/src/Util/Ignore.hs @@ -1,5 +1,5 @@ -module Test.Util +module Util.Ignore ( ignoreOn , ignoreOnWindows , ignoreOnMac diff --git a/cardano-testnet/src/Test/Process.hs b/cardano-testnet/src/Util/Process.hs similarity index 99% rename from cardano-testnet/src/Test/Process.hs rename to cardano-testnet/src/Util/Process.hs index ca08e3d2460..499f5e5fd7e 100644 --- a/cardano-testnet/src/Test/Process.hs +++ b/cardano-testnet/src/Util/Process.hs @@ -1,4 +1,4 @@ -module Test.Process +module Util.Process ( assertByDeadlineIOCustom , assertByDeadlineMCustom , bashPath diff --git a/cardano-testnet/src/Test/Runtime.hs b/cardano-testnet/src/Util/Runtime.hs similarity index 98% rename from cardano-testnet/src/Test/Runtime.hs rename to cardano-testnet/src/Util/Runtime.hs index 6ad393b7712..d4ed2e07102 100644 --- a/cardano-testnet/src/Test/Runtime.hs +++ b/cardano-testnet/src/Util/Runtime.hs @@ -3,7 +3,7 @@ {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE LambdaCase #-} -module Test.Runtime +module Util.Runtime ( LeadershipSlot(..) , NodeLoggingFormat(..) , PaymentKeyPair(..) @@ -36,13 +36,14 @@ import qualified Hedgehog.Extras.Stock.String as S import qualified Hedgehog.Extras.Test.Base as H import qualified Hedgehog.Extras.Test.File as H import qualified Hedgehog.Extras.Test.Process as H -import qualified Test.Process as H import System.FilePath.Posix (()) import qualified System.Info as OS import qualified System.IO as IO import qualified System.Process as IO +import qualified Util.Process as H + data NodeLoggingFormat = NodeLoggingFormatAsJson | NodeLoggingFormatAsText deriving (Eq, Show) data TestnetRuntime = TestnetRuntime diff --git a/cardano-testnet/test/Main.hs b/cardano-testnet/test/Main.hs index 32e302b09f4..78eae51a579 100644 --- a/cardano-testnet/test/Main.hs +++ b/cardano-testnet/test/Main.hs @@ -6,32 +6,32 @@ module Main import Prelude import Test.Tasty (TestTree) - -import qualified Spec.Cli.Alonzo.LeadershipSchedule -import qualified Spec.Cli.Babbage.LeadershipSchedule -import qualified Spec.Cli.KesPeriodInfo -import qualified Spec.Node.Shutdown -import qualified Spec.ShutdownOnSlotSynced -import qualified System.Environment as E import qualified Test.Tasty as T import qualified Test.Tasty.Ingredients as T -import qualified Test.Util as H +import qualified System.Environment as E + +import qualified Test.Cli.Alonzo.LeadershipSchedule +import qualified Test.Cli.Babbage.LeadershipSchedule +import qualified Test.Cli.KesPeriodInfo +import qualified Test.Node.Shutdown +import qualified Test.ShutdownOnSlotSynced +import qualified Util.Ignore as H tests :: IO TestTree tests = pure $ T.testGroup "test/Spec.hs" [ T.testGroup "Spec" - [ H.ignoreOnWindows "Shutdown" Spec.Node.Shutdown.hprop_shutdown - , H.ignoreOnWindows "ShutdownOnSlotSynced" Spec.ShutdownOnSlotSynced.hprop_shutdownOnSlotSynced + [ H.ignoreOnWindows "Shutdown" Test.Node.Shutdown.hprop_shutdown + , H.ignoreOnWindows "ShutdownOnSlotSynced" Test.ShutdownOnSlotSynced.hprop_shutdownOnSlotSynced , T.testGroup "Alonzo" - [ H.ignoreOnMacAndWindows "leadership-schedule" Spec.Cli.Alonzo.LeadershipSchedule.hprop_leadershipSchedule + [ H.ignoreOnMacAndWindows "leadership-schedule" Test.Cli.Alonzo.LeadershipSchedule.hprop_leadershipSchedule ] , T.testGroup "Babbage" - [ H.ignoreOnMacAndWindows "leadership-schedule" Spec.Cli.Babbage.LeadershipSchedule.hprop_leadershipSchedule + [ H.ignoreOnMacAndWindows "leadership-schedule" Test.Cli.Babbage.LeadershipSchedule.hprop_leadershipSchedule ] -- Ignored on Windows due to : commitBuffer: invalid argument (invalid character) -- as a result of the kes-period-info output to stdout. -- TODO: Babbage temporarily ignored due to broken protocol-state query - , H.disabled "kes-period-info" Spec.Cli.KesPeriodInfo.hprop_kes_period_info + , H.disabled "kes-period-info" Test.Cli.KesPeriodInfo.hprop_kes_period_info ] ] diff --git a/cardano-testnet/test/Spec/Cli/Alonzo/LeadershipSchedule.hs b/cardano-testnet/test/Test/Cli/Alonzo/LeadershipSchedule.hs similarity index 98% rename from cardano-testnet/test/Spec/Cli/Alonzo/LeadershipSchedule.hs rename to cardano-testnet/test/Test/Cli/Alonzo/LeadershipSchedule.hs index b14ac2dcf19..cc6a928aa8b 100644 --- a/cardano-testnet/test/Spec/Cli/Alonzo/LeadershipSchedule.hs +++ b/cardano-testnet/test/Test/Cli/Alonzo/LeadershipSchedule.hs @@ -10,7 +10,7 @@ {- HLINT ignore "Redundant return" -} {- HLINT ignore "Use let" -} -module Spec.Cli.Alonzo.LeadershipSchedule +module Test.Cli.Alonzo.LeadershipSchedule ( hprop_leadershipSchedule ) where @@ -42,15 +42,15 @@ import qualified System.Directory as IO import System.Environment (getEnvironment) import System.FilePath (()) import qualified System.Info as SYS -import qualified Test.Assert as H -import qualified Test.Base as H -import qualified Test.Process as H -import qualified Test.Runtime as TR -import Test.Runtime (LeadershipSlot (..)) import Testnet ( TestnetOptions (CardanoOnlyTestnetOptions), testnet) import Testnet.Cardano as TC (CardanoTestnetOptions (..), defaultTestnetOptions) import qualified Testnet.Conf as H import Testnet.Utils (waitUntilEpoch) +import qualified Util.Assert as H +import qualified Util.Base as H +import qualified Util.Process as H +import Util.Runtime (LeadershipSlot (..)) +import qualified Util.Runtime as TR hprop_leadershipSchedule :: Property hprop_leadershipSchedule = H.integration . H.runFinallies . H.workspace "alonzo" $ \tempAbsBasePath' -> do diff --git a/cardano-testnet/test/Spec/Cli/Babbage/LeadershipSchedule.hs b/cardano-testnet/test/Test/Cli/Babbage/LeadershipSchedule.hs similarity index 96% rename from cardano-testnet/test/Spec/Cli/Babbage/LeadershipSchedule.hs rename to cardano-testnet/test/Test/Cli/Babbage/LeadershipSchedule.hs index dadd26d72a8..53789c66326 100644 --- a/cardano-testnet/test/Spec/Cli/Babbage/LeadershipSchedule.hs +++ b/cardano-testnet/test/Test/Cli/Babbage/LeadershipSchedule.hs @@ -12,7 +12,7 @@ {- HLINT ignore "Use head" -} {- HLINT ignore "Use let" -} -module Spec.Cli.Babbage.LeadershipSchedule +module Test.Cli.Babbage.LeadershipSchedule ( hprop_leadershipSchedule ) where @@ -38,15 +38,15 @@ import qualified Hedgehog.Extras.Test.File as H import qualified Hedgehog.Extras.Test.Process as H import qualified System.Directory as IO import qualified System.Info as SYS -import qualified Test.Assert as H -import qualified Test.Base as H -import qualified Test.Process as H -import qualified Test.Runtime as TR -import Test.Runtime (LeadershipSlot (..)) import Testnet ( TestnetOptions (BabbageOnlyTestnetOptions), testnet) import Testnet.Babbage (BabbageTestnetOptions (..)) import qualified Testnet.Babbage as TC import qualified Testnet.Conf as H +import qualified Util.Assert as H +import qualified Util.Base as H +import qualified Util.Process as H +import qualified Util.Runtime as TR +import Util.Runtime (LeadershipSlot (..)) hprop_leadershipSchedule :: Property hprop_leadershipSchedule = H.integration . H.runFinallies . H.workspace "alonzo" $ \tempAbsBasePath' -> do diff --git a/cardano-testnet/test/Spec/Cli/KesPeriodInfo.hs b/cardano-testnet/test/Test/Cli/KesPeriodInfo.hs similarity index 98% rename from cardano-testnet/test/Spec/Cli/KesPeriodInfo.hs rename to cardano-testnet/test/Test/Cli/KesPeriodInfo.hs index 7454ab62d7d..572baf08d0b 100644 --- a/cardano-testnet/test/Spec/Cli/KesPeriodInfo.hs +++ b/cardano-testnet/test/Test/Cli/KesPeriodInfo.hs @@ -4,7 +4,7 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} -module Spec.Cli.KesPeriodInfo +module Test.Cli.KesPeriodInfo ( hprop_kes_period_info ) where @@ -22,10 +22,6 @@ import System.FilePath (()) import Cardano.CLI.Shelley.Output import Cardano.CLI.Shelley.Run.Query -import Testnet.Cardano (CardanoTestnetOptions (..), TestnetRuntime (..), - defaultTestnetNodeOptions, defaultTestnetOptions) -import Testnet.Utils (waitUntilEpoch) - import qualified Data.Aeson as J import qualified Data.Map.Strict as Map import qualified Data.Set as Set @@ -37,16 +33,19 @@ import qualified Hedgehog.Extras.Test.File as H import qualified Hedgehog.Extras.Test.Process as H import qualified System.Directory as IO import qualified System.Info as SYS -import qualified Test.Base as H -import qualified Test.Process as H -import qualified Test.Runtime as TR + +import Test.Misc +import Testnet.Cardano (CardanoTestnetOptions (..), TestnetRuntime (..), + defaultTestnetNodeOptions, defaultTestnetOptions) import Testnet (TestnetOptions (CardanoOnlyTestnetOptions), testnet) import qualified Testnet.Cardano as TC - import qualified Testnet.Conf as H import Testnet.Conf (ProjectBase (..), YamlFilePath (..)) +import Testnet.Utils (waitUntilEpoch) +import qualified Util.Base as H +import qualified Util.Process as H +import qualified Util.Runtime as TR -import Testnet.Properties.Cli.KesPeriodInfo hprop_kes_period_info :: Property hprop_kes_period_info = H.integration . H.runFinallies . H.workspace "chairman" $ \tempAbsBasePath' -> do diff --git a/cardano-testnet/test/Testnet/Properties/Cli/KesPeriodInfo.hs b/cardano-testnet/test/Test/Misc.hs similarity index 97% rename from cardano-testnet/test/Testnet/Properties/Cli/KesPeriodInfo.hs rename to cardano-testnet/test/Test/Misc.hs index 4e5ab64f8b4..b6d202c6452 100644 --- a/cardano-testnet/test/Testnet/Properties/Cli/KesPeriodInfo.hs +++ b/cardano-testnet/test/Test/Misc.hs @@ -1,4 +1,4 @@ -module Testnet.Properties.Cli.KesPeriodInfo where +module Test.Misc where import Prelude diff --git a/cardano-testnet/test/Spec/Node/Shutdown.hs b/cardano-testnet/test/Test/Node/Shutdown.hs similarity index 93% rename from cardano-testnet/test/Spec/Node/Shutdown.hs rename to cardano-testnet/test/Test/Node/Shutdown.hs index 0bdadcdb6ec..225b8ef1404 100644 --- a/cardano-testnet/test/Spec/Node/Shutdown.hs +++ b/cardano-testnet/test/Test/Node/Shutdown.hs @@ -4,22 +4,18 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} -module Spec.Node.Shutdown +module Test.Node.Shutdown ( hprop_shutdown ) where +import Prelude import Control.Monad -import Data.Function import Data.Functor ((<&>)) -import Data.Int +import qualified Data.List as L import Data.Maybe -import Data.Ord -import GHC.Num import Hedgehog (Property, (===)) import System.FilePath (()) -import Text.Show (Show (..)) -import qualified Data.List as L import qualified Hedgehog as H import qualified Hedgehog.Extras.Stock.IO.Network.Socket as IO import qualified Hedgehog.Extras.Stock.IO.Network.Sprocket as IO @@ -31,9 +27,9 @@ import qualified System.Directory as IO import qualified System.Exit as IO import qualified System.IO as IO import qualified System.Process as IO -import qualified Test.Base as H -import qualified Test.Process as H import qualified Testnet.Conf as H +import qualified Util.Base as H +import qualified Util.Process as H {- HLINT ignore "Redundant <&>" -} diff --git a/cardano-testnet/test/Spec/ShutdownOnSlotSynced.hs b/cardano-testnet/test/Test/ShutdownOnSlotSynced.hs similarity index 83% rename from cardano-testnet/test/Spec/ShutdownOnSlotSynced.hs rename to cardano-testnet/test/Test/ShutdownOnSlotSynced.hs index 376fef03341..4a9b92fe268 100644 --- a/cardano-testnet/test/Spec/ShutdownOnSlotSynced.hs +++ b/cardano-testnet/test/Test/ShutdownOnSlotSynced.hs @@ -2,39 +2,34 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} -module Spec.ShutdownOnSlotSynced +module Test.ShutdownOnSlotSynced ( hprop_shutdownOnSlotSynced ) where +import Prelude import Control.Monad -import Data.Bool ((&&)) -import Data.Either (Either (Right), isRight) -import Data.Function -import Data.Int -import Data.List (find, isInfixOf, lines, reverse, words, (++)) +import Data.Either (isRight) +import Data.List (find, isInfixOf) import Data.Maybe -import Data.Ord import GHC.IO.Exception (ExitCode (ExitSuccess)) -import GHC.Num import GHC.Stack (callStack) -import Hedgehog (Property, assert, (===)) -import Prelude (fromIntegral, round) import System.FilePath (()) -import Text.Read (readMaybe) -import Text.Show (Show (..)) +import qualified System.Directory as IO +import Text.Read (readMaybe) +import Hedgehog (Property, assert, (===)) import qualified Hedgehog.Extras.Test.Base as H import qualified Hedgehog.Extras.Test.File as H import qualified Hedgehog.Extras.Test.Process as H -import qualified System.Directory as IO -import qualified Test.Base as H -import Test.Runtime (NodeRuntime (..)) + import Testnet (TestnetOptions( CardanoOnlyTestnetOptions), testnet) import Testnet.Cardano (TestnetNodeOptions (TestnetNodeOptions), CardanoTestnetOptions (..), TestnetRuntime (..), defaultTestnetNodeOptions, defaultTestnetOptions) import qualified Testnet.Cardano as TC import qualified Testnet.Conf as H +import qualified Util.Base as H +import Util.Runtime (NodeRuntime (..)) hprop_shutdownOnSlotSynced :: Property hprop_shutdownOnSlotSynced = H.integration . H.runFinallies . H.workspace "chairman" $ \tempAbsBasePath' -> do @@ -68,8 +63,8 @@ hprop_shutdownOnSlotSynced = H.integration . H.runFinallies . H.workspace "chair H.cat (nodeStdout node) H.cat (nodeStderr node) mExitCodeRunning === Right ExitSuccess - log <- H.readFile (nodeStdout node) - slotTip <- case find (isInfixOf "Closed db with immutable tip") (reverse (lines log)) of + logs <- H.readFile (nodeStdout node) + slotTip <- case find (isInfixOf "Closed db with immutable tip") (reverse (lines logs)) of Nothing -> H.failMessage callStack "Could not find current tip in node's log." Just line -> case listToMaybe (reverse (words line)) of Nothing -> H.failMessage callStack "Impossible"