Skip to content

Commit

Permalink
Move integration framework context to dedicated module.
Browse files Browse the repository at this point in the history
The `Context` type is not really related to the `Request` type, and yet
it's currently located in the `Request` module.

This change moves `Context` into its own module, so that contexts and
requests can be kept separate from one another.
  • Loading branch information
jonathanknowles committed Sep 21, 2020
1 parent 37c70ff commit 4bb7e3a
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 65 deletions.
1 change: 1 addition & 0 deletions lib/core-integration/cardano-wallet-core-integration.cabal
Expand Up @@ -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
Expand Down
65 changes: 65 additions & 0 deletions 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
12 changes: 6 additions & 6 deletions lib/core-integration/src/Test/Integration/Framework/DSL.hs
Expand Up @@ -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
)
Expand Down Expand Up @@ -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)

Expand Down
53 changes: 2 additions & 51 deletions lib/core-integration/src/Test/Integration/Framework/Request.hs
@@ -1,5 +1,4 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -64,51 +51,15 @@ 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
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
Expand Down
2 changes: 1 addition & 1 deletion lib/shelley/src/Cardano/Wallet/Shelley/Pools.hs
Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions lib/shelley/test/integration/Main.hs
Expand Up @@ -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
Expand Down

0 comments on commit 4bb7e3a

Please sign in to comment.