diff --git a/lib/core-integration/cardano-wallet-core-integration.cabal b/lib/core-integration/cardano-wallet-core-integration.cabal index d61df8c95fd..6dec6865119 100644 --- a/lib/core-integration/cardano-wallet-core-integration.cabal +++ b/lib/core-integration/cardano-wallet-core-integration.cabal @@ -75,6 +75,7 @@ library src exposed-modules: Test.Integration.Faucet + Test.Integration.Framework.Context Test.Integration.Framework.DSL Test.Integration.Framework.Request Test.Integration.Framework.TestData diff --git a/lib/core-integration/src/Test/Integration/Framework/Context.hs b/lib/core-integration/src/Test/Integration/Framework/Context.hs new file mode 100644 index 00000000000..737611d55af --- /dev/null +++ b/lib/core-integration/src/Test/Integration/Framework/Context.hs @@ -0,0 +1,65 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE DeriveGeneric #-} + +module Test.Integration.Framework.Context + ( Context (..) + , TxDescription (..) + ) where + +import Prelude + +import Cardano.CLI + ( Port (..) ) +import Cardano.Wallet.Primitive.Types + ( NetworkParameters ) +import Cardano.Wallet.Transaction + ( DelegationAction ) +import Data.Proxy + ( Proxy (..) ) +import Data.Text + ( Text ) +import GHC.Generics + ( Generic ) +import Network.HTTP.Client + ( Manager ) +import Numeric.Natural + ( Natural ) +import Test.Integration.Faucet + ( Faucet ) + +-- | Context for integration tests. +-- +data Context t = Context + { _cleanup + :: IO () + -- ^ A cleanup action. + , _manager + :: (Text, Manager) + -- ^ The underlying base URL and manager used by the wallet client. + , _walletPort + :: Port "wallet" + -- ^ Server TCP port. + , _faucet + :: Faucet + -- ^ Provides access to funded wallets. + , _feeEstimator :: TxDescription -> (Natural, Natural) + -- ^ A fee estimator. + , _networkParameters :: NetworkParameters + -- ^ Blockchain parameters for the underlying chain. + , _target + :: Proxy t + } + deriving Generic + +-- | Describe a transaction in terms of its inputs and outputs. +data TxDescription + = DelegDescription DelegationAction + | PaymentDescription + { nInputs + :: Int + , nOutputs + :: Int + , nChanges + :: Int + } + deriving Show diff --git a/lib/core-integration/src/Test/Integration/Framework/DSL.hs b/lib/core-integration/src/Test/Integration/Framework/DSL.hs index 4a1eb13df2d..77066c46c3c 100644 --- a/lib/core-integration/src/Test/Integration/Framework/DSL.hs +++ b/lib/core-integration/src/Test/Integration/Framework/DSL.hs @@ -300,12 +300,12 @@ import Test.Hspec.Expectations.Lifted ( shouldBe, shouldContain, shouldSatisfy ) import Test.Integration.Faucet ( nextTxBuilder, nextWallet ) +import Test.Integration.Framework.Context + ( Context (..), TxDescription (..) ) import Test.Integration.Framework.Request - ( Context (..) - , Headers (..) + ( Headers (..) , Payload (..) , RequestException (..) - , TxDescription (..) , request , unsafeRequest ) @@ -1642,12 +1642,12 @@ postTransactionViaCLI ctx passphrase args = do hClose stdin out <- TIO.hGetContents stdout err <- TIO.hGetContents stderr - -- For some reason, when - -- - waitForProcess is called before hGetContents + -- For some reason, when + -- - waitForProcess is called before hGetContents -- - os is windows -- - postTransactionViaCLI was called with >= 5 outputs -- waitForProcess blocks indefinetely. Hence we call waitForProcess - -- last. + -- last. c <- waitForProcess h return (c, T.unpack out, err) diff --git a/lib/core-integration/src/Test/Integration/Framework/Request.hs b/lib/core-integration/src/Test/Integration/Framework/Request.hs index 2236e6f07bf..597be88bcc5 100644 --- a/lib/core-integration/src/Test/Integration/Framework/Request.hs +++ b/lib/core-integration/src/Test/Integration/Framework/Request.hs @@ -1,5 +1,4 @@ {-# LANGUAGE DataKinds #-} -{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE LambdaCase #-} @@ -15,18 +14,10 @@ module Test.Integration.Framework.Request , Headers(..) , Payload(..) , RequestException(..) - , Context(..) - , TxDescription(..) ) where import Prelude -import Cardano.CLI - ( Port (..) ) -import Cardano.Wallet.Primitive.Types - ( NetworkParameters ) -import Cardano.Wallet.Transaction - ( DelegationAction ) import Control.Monad.Catch ( Exception (..), MonadCatch (..), throwM ) import Control.Monad.IO.Class @@ -39,12 +30,8 @@ import Data.Generics.Internal.VL.Lens ( (^.) ) import Data.Generics.Product.Typed ( HasType, typed ) -import Data.Proxy - ( Proxy (..) ) import Data.Text ( Text ) -import GHC.Generics - ( Generic ) import Network.HTTP.Client ( HttpException (..) , HttpExceptionContent @@ -64,10 +51,8 @@ import Network.HTTP.Types.Method ( Method ) import Network.HTTP.Types.Status ( status500 ) -import Numeric.Natural - ( Natural ) -import Test.Integration.Faucet - ( Faucet ) +import Test.Integration.Framework.Context + ( Context ) import qualified Data.Aeson as Aeson import qualified Data.ByteString.Lazy.Char8 as BL8 @@ -75,40 +60,6 @@ import qualified Data.Text as T import qualified Network.HTTP.Client as HTTP import qualified Network.HTTP.Types.Status as HTTP - --- | Running Context for our integration test -data Context t = Context - { _cleanup - :: IO () - -- ^ Cleanup action for the context - , _manager - :: (Text, Manager) - -- ^ The underlying BaseUrl and Manager used by the Wallet Client - , _walletPort - :: Port "wallet" - -- ^ Server TCP port - , _faucet - :: Faucet - -- ^ A 'Faucet' handle in to have access to funded wallets in - -- integration tests. - , _feeEstimator :: TxDescription -> (Natural, Natural) - -- ^ A fee estimator for the integration tests - , _networkParameters :: NetworkParameters - -- ^ Blockchain parameters for the underlying chain - , _target - :: Proxy t - } deriving Generic - --- | Describe a transaction in terms of its inputs and outputs -data TxDescription - = DelegDescription DelegationAction - | PaymentDescription - { nInputs :: Int - , nOutputs :: Int - , nChanges :: Int - } - deriving (Show) - -- | The result when 'request' fails. data RequestException = DecodeFailure ByteString diff --git a/lib/shelley/src/Cardano/Wallet/Shelley/Pools.hs b/lib/shelley/src/Cardano/Wallet/Shelley/Pools.hs index 0d1eac8e1d0..f51a55365e7 100644 --- a/lib/shelley/src/Cardano/Wallet/Shelley/Pools.hs +++ b/lib/shelley/src/Cardano/Wallet/Shelley/Pools.hs @@ -96,7 +96,7 @@ import Control.Concurrent import Control.Exception ( try ) import Control.Monad - ( forM, forM_, forever, unless, void, when, (<=<) ) + ( forM, forM_, forever, void, when, (<=<) ) import Control.Monad.IO.Class ( liftIO ) import Control.Monad.Trans.Except diff --git a/lib/shelley/test/integration/Main.hs b/lib/shelley/test/integration/Main.hs index 0912724265d..19e67fa25f4 100644 --- a/lib/shelley/test/integration/Main.hs +++ b/lib/shelley/test/integration/Main.hs @@ -98,14 +98,10 @@ import Test.Hspec.Extra ( aroundAll ) import Test.Integration.Faucet ( genRewardAccounts, mirMnemonics, shelleyIntegrationTestFunds ) +import Test.Integration.Framework.Context + ( Context (..) ) import Test.Integration.Framework.DSL - ( Context (..) - , Headers (..) - , KnownCommand (..) - , Payload (..) - , request - , unsafeRequest - ) + ( Headers (..), KnownCommand (..), Payload (..), request, unsafeRequest ) import qualified Cardano.Wallet.Api.Link as Link import qualified Data.Aeson as Aeson