Skip to content

Commit

Permalink
PLT-4186 - implement e2e tests for get transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
ladamesny committed Mar 30, 2023
1 parent 5afdd67 commit 6fe34eb
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions marlowe-integration-tests/marlowe-integration-tests.cabal
Expand Up @@ -70,6 +70,7 @@ executable marlowe-integration-tests
Language.Marlowe.Runtime.Web.GetContracts
Language.Marlowe.Runtime.Web.GetContract
Language.Marlowe.Runtime.Web.GetTransactions
Language.Marlowe.Runtime.Web.GetTransaction
Language.Marlowe.Runtime.CliSpec
build-depends:
base >= 4.9 && < 5
Expand Down
@@ -0,0 +1,95 @@
{-# OPTIONS_GHC -Wno-unused-imports #-}
module Language.Marlowe.Runtime.Web.GetTransaction
where

import Control.Monad.IO.Class (MonadIO(liftIO))

import Control.Exception (throw)
import qualified Language.Marlowe.Runtime.ChainSync.Api as Chain
import Language.Marlowe.Runtime.Integration.Common (getGenesisWallet, runIntegrationTest, runWebClient)
import qualified Language.Marlowe.Runtime.Web as Web
import Language.Marlowe.Runtime.Web.Client (getTransaction)
import Language.Marlowe.Runtime.Web.Common (createCloseContract, waitUntilConfirmed)
import Language.Marlowe.Runtime.Web.Server.DTO (ToDTO(toDTO))
import Language.Marlowe.Runtime.Web.StandardContract (createFullyExecutedStandardContract)
import Network.HTTP.Types (Status(..))
import Servant.Client (ClientError(FailureResponse))
import Servant.Client.Streaming (ResponseF(Response, responseStatusCode))
import Test.Hspec (Spec, describe, it, shouldBe)
import Test.Integration.Marlowe.Local (withLocalMarloweRuntime)

spec :: Spec
spec = describe "GET /contract/{contractId}/transactions/{transactionId}" do
getTransactionValidSpec
-- getTransactionInvalidSpec

getTransactionValidSpec :: Spec
getTransactionValidSpec = describe "Valid GET /contract/{contractId}/transactions/{transactionId}" do
getsFirstTransactionValidSpec
getsSecondTransactionValidSpec
getsThirdTransactionValidSpec

-- getTransactionInvalidSpec :: Spec
-- getTransactionInvalidSpec = describe "Invalid GET /contract/{contractId}/transactions/{transactionId}" do
-- invalidTxIdSpec

getsFirstTransactionValidSpec :: Spec
getsFirstTransactionValidSpec = it "returns the first transaction" $ withLocalMarloweRuntime $ runIntegrationTest do
wallet1 <- getGenesisWallet 0
wallet2 <- getGenesisWallet 1

either throw pure =<< runWebClient do
(contractId, transactionIds) <- createFullyExecutedStandardContract wallet1 wallet2
case transactionIds of
(txId1:_) -> do
Web.Tx{transactionId = actualTransactionId } <- getTransaction contractId txId1

liftIO $ actualTransactionId `shouldBe` txId1

_ -> do
liftIO $ fail "Expected at least two transactions"

getsSecondTransactionValidSpec :: Spec
getsSecondTransactionValidSpec = it "returns the second transaction" $ withLocalMarloweRuntime $ runIntegrationTest do
wallet1 <- getGenesisWallet 0
wallet2 <- getGenesisWallet 1

either throw pure =<< runWebClient do
(contractId, transactionIds) <- createFullyExecutedStandardContract wallet1 wallet2
case transactionIds of
(_:txId2:_) -> do
Web.Tx{transactionId = actualTransactionId } <- getTransaction contractId txId2

liftIO $ actualTransactionId `shouldBe` txId2

_ -> do
liftIO $ fail "Expected at least two transactions"


getsThirdTransactionValidSpec :: Spec
getsThirdTransactionValidSpec = it "returns the third transaction" $ withLocalMarloweRuntime $ runIntegrationTest do
wallet1 <- getGenesisWallet 0
wallet2 <- getGenesisWallet 1

either throw pure =<< runWebClient do
(contractId, transactionIds) <- createFullyExecutedStandardContract wallet1 wallet2
case transactionIds of
(_:_:txId3:_) -> do
Web.Tx{transactionId = actualTransactionId } <- getTransaction contractId txId3

liftIO $ actualTransactionId `shouldBe` txId3

_ -> do
liftIO $ fail "Expected at least three transactions"


-- invalidTxIdSpec :: Spec
-- invalidTxIdSpec = it "returns not found for invalid transaction id" $ withLocalMarloweRuntime $ runIntegrationTest do
-- result <- runWebClient do
-- let
-- invalidTxId = Web.TxOutRef (toDTO @Chain.TxId "0000000000000000000000000000000000000000000000000000000000000000") 1
-- getTransaction invalidTxId

-- case result of
-- Left (FailureResponse _ Response { responseStatusCode = Status { statusCode = 404 } } ) -> pure ()
-- _ -> fail $ "Expected 404 response code - got " <> show result
@@ -1,8 +1,10 @@
{-# OPTIONS_GHC -Wno-unused-imports #-}
module Language.Marlowe.Runtime.WebSpec
where

import qualified Language.Marlowe.Runtime.Web.GetContract as GetContract
import qualified Language.Marlowe.Runtime.Web.GetContracts as GetContracts
import qualified Language.Marlowe.Runtime.Web.GetTransactions as GetTransaction
import qualified Language.Marlowe.Runtime.Web.GetTransactions as GetTransactions
import Test.Hspec (Spec, describe)

Expand All @@ -11,3 +13,4 @@ spec = describe "Marlowe runtime Web API" do
GetContracts.spec
GetContract.spec
GetTransactions.spec
GetTransaction.spec

0 comments on commit 6fe34eb

Please sign in to comment.