From 71410d41b644ae091ab9815993787ef4f522a1f7 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Thu, 24 Oct 2019 15:17:48 +0200 Subject: [PATCH 1/5] reuse postTx method in tests --- .../Integration/Scenario/API/Transactions.hs | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs index 482644848f7..bbe3c9e05af 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs @@ -130,26 +130,12 @@ spec = do it "TRANS_CREATE_01 - Single Output Transaction" $ \ctx -> do (wa, wb) <- (,) <$> fixtureWallet ctx <*> fixtureWallet ctx - addrs <- listAddresses ctx wb - - let amt = 1 - let destination = (addrs !! 1) ^. #id - let payload = Json [json|{ - "payments": [{ - "address": #{destination}, - "amount": { - "quantity": #{amt}, - "unit": "lovelace" - } - }], - "passphrase": "cardano-wallet" - }|] let (feeMin, feeMax) = ctx ^. feeEstimator $ TxDescription { nInputs = 1 , nOutputs = 1 } - - r <- request @(ApiTransaction t) ctx (postTxEp wa) Default payload + let amt = (1 :: Natural) + r <- postTx ctx wa wb amt verify r [ expectSuccess , expectResponseCode HTTP.status202 @@ -1720,6 +1706,23 @@ spec = do else expectErrorMessage errMsg404NoEndpoint r + postTx ctx wSrc wDest amt = do + addrs <- listAddresses ctx wDest + let destination = (addrs !! 1) ^. #id + let payload = Json [json|{ + "payments": [{ + "address": #{destination}, + "amount": { + "quantity": #{amt}, + "unit": "lovelace" + } + }], + "passphrase": "cardano-wallet" + }|] + r <- request @(ApiTransaction t) ctx (postTxEp wSrc) Default payload + expectResponseCode HTTP.status202 r + return r + unsafeGetTransactionTime :: [ApiTransaction t] -> UTCTime From 45f3f54d0dbc79d26d3e3857d90383b318f5def9 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Thu, 24 Oct 2019 17:27:49 +0200 Subject: [PATCH 2/5] more TRANS_DELETE tests via API --- .../Integration/Scenario/API/Transactions.hs | 62 ++++++++++++++++++- .../Jormungandr/Scenario/API/Transactions.hs | 32 ++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs index bbe3c9e05af..fcccb8703ec 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs @@ -15,7 +15,14 @@ module Test.Integration.Scenario.API.Transactions import Prelude import Cardano.Wallet.Api.Types - ( ApiFee, ApiT, ApiTransaction, ApiTxId (..), ApiWallet, insertedAt, time ) + ( ApiFee + , ApiT (..) + , ApiTransaction + , ApiTxId (..) + , ApiWallet + , insertedAt + , time + ) import Cardano.Wallet.Primitive.Types ( DecodeAddress (..) , Direction (..) @@ -33,6 +40,8 @@ import Data.Generics.Product.Typed ( HasType ) import Data.Text ( Text ) +import Data.Text.Class + ( ToText (..) ) import Data.Time.Clock ( UTCTime, addUTCTime ) import Data.Time.Utils @@ -110,6 +119,7 @@ import Test.Integration.Framework.TestData , errMsg406 , errMsg415 , falseWalletIds + , getHeaderCases , kanjiWalletName , polishWalletName , wildcardsWalletName @@ -1513,6 +1523,56 @@ spec = do transactionDeleteTest04 "byron-wallets" + it "TRANS_DELETE_06 -\ + \ Cannot forget tx that is performed from different wallet -> 404" + $ \ctx -> do + wDifferent <- emptyWallet ctx + (wSrc, wDest) <- (,) <$> fixtureWallet ctx <*> emptyWallet ctx + rMkTx <- postTx ctx wSrc wDest (1 :: Natural) + let txId = toText $ getApiT $ getFromResponse #id rMkTx + let endpoint = "v2/wallets/" + <> wDifferent ^. walletId + <> "/transactions/" + <> txId + ra <- request @ApiTxId @IO ctx ("DELETE", endpoint) Default Empty + expectResponseCode @IO HTTP.status404 ra + expectErrorMessage (errMsg404CannotFindTx txId) ra + + describe "TRANS_DELETE_07 - invalid tx id" $ do + let txIds = + [ replicate 63 '1' + , replicate 65 '1' + , replicate 64 'ś' + ] + forM_ txIds $ \tid -> it (show tid) $ \ctx -> do + w <- emptyWallet ctx + let wid = w ^. walletId + let endpoint = "v2/wallets/" <> wid <> "/transactions/" <> T.pack tid + r <- request @ApiTxId @IO ctx ("DELETE", endpoint) Default Empty + expectResponseCode @IO HTTP.status404 r + expectErrorMessage errMsg404NoEndpoint r + + describe "TRANS_DELETE_08 - HTTP headers" $ do + forM_ (getHeaderCases HTTP.status204) + $ \(title, headers, expectations) -> it title $ \ctx -> do + (wSrc, wDest) <- (,) <$> fixtureWallet ctx <*> emptyWallet ctx + rMkTx <- postTx ctx wSrc wDest (1 :: Natural) + let txId = getFromResponse #id rMkTx + let ep = deleteTxEp wSrc (ApiTxId txId) + r <- request @ApiTxId @IO ctx ep headers Empty + verify r expectations + + describe "TRANS_DELETE_09 -\ + \ v2/wallets/{id}/transactions/id - Methods Not Allowed" $ do + let matrix = ["POST", "CONNECT", "TRACE", "OPTIONS", "PUT", "GET"] + forM_ matrix $ \method -> it (show method) $ \ctx -> do + let txId = replicate 64 '1' + let wid = replicate 40 '1' + let endpoint = "v2/wallets/" <> wid <> "/transactions/" <> txId + r <- request @ApiTxId @IO ctx (method, T.pack endpoint) Default Empty + expectResponseCode @IO HTTP.status405 r + expectErrorMessage errMsg405 r + it "BYRON_TRANS_DELETE -\ \ Cannot delete tx on Byron wallet using shelley ep" $ \ctx -> do w <- emptyByronWallet ctx diff --git a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs index 3e400bed697..373292ca1f6 100644 --- a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs +++ b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs @@ -67,6 +67,8 @@ import Data.Quantity ( Quantity (..) ) import Data.Text ( Text ) +import Data.Text.Class + ( ToText (..) ) import Numeric.Natural ( Natural ) import Test.Hspec @@ -78,6 +80,7 @@ import Test.Integration.Framework.DSL , TxDescription (..) , balanceAvailable , balanceTotal + , deleteTxEp , emptyWallet , expectErrorMessage , expectEventually @@ -108,6 +111,7 @@ import Test.Integration.Framework.Request import Test.Integration.Framework.TestData ( errMsg400MalformedTxPayload , errMsg403TxTooBig + , errMsg404CannotFindTx , errMsg405 , errMsg406 , errMsg415OctetStream @@ -210,6 +214,34 @@ spec = do expectEventually' ctx getWalletEp balanceAvailable amt w expectEventually' ctx getWalletEp balanceTotal amt w + it "TRANS_DELETE_05 - \ + \Cannot forget external tx -> 404" $ \ctx -> do + + w <- emptyWallet ctx + addr:_ <- listAddresses ctx w + let addrStr = encodeAddress (Proxy @t) (getApiT $ fst $ addr ^. #id) + let amt = 1234 + + txBlob <- prepExternalTxViaJcli (ctx ^. typed @(Port "node")) addrStr amt + let payload = (NonJson . BL.fromStrict . toRawBytes Base16) txBlob + let headers = Headers + [ ("Content-Type", "application/octet-stream") + , ("Accept", "application/json")] + + r <- request @ApiTxId ctx postExternalTxEp headers payload + let txId = getFromResponse #id r + let txIdH = toText $ getApiT txId + + -- try to forget external tx + let endpoint = (deleteTxEp w (ApiTxId txId)) + ra <- request @ApiTxId @IO ctx endpoint Default Empty + expectResponseCode @IO HTTP.status404 ra + expectErrorMessage (errMsg404CannotFindTx txIdH) ra + + -- tx eventually gets into ledger (funds are on the wallet) + expectEventually' ctx getWalletEp balanceAvailable amt w + expectEventually' ctx getWalletEp balanceTotal amt w + it "TRANS_EXTERNAL_CREATE_01 - proper single output transaction and \ \proper binary format" $ \ctx -> do let toSend = 1 :: Natural From 3a8b3c89b751aba7803f42f895557e6b76305194 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 25 Oct 2019 11:12:54 +0200 Subject: [PATCH 3/5] reuse tests for byron-wallets --- .../Integration/Scenario/API/Transactions.hs | 155 ++++++++---------- .../Jormungandr/Scenario/API/Transactions.hs | 64 ++++---- 2 files changed, 106 insertions(+), 113 deletions(-) diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs index fcccb8703ec..37891a8a76c 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs @@ -145,7 +145,7 @@ spec = do , nOutputs = 1 } let amt = (1 :: Natural) - r <- postTx ctx wa wb amt + r <- postTx ctx (wa, postTxEp) wb amt verify r [ expectSuccess , expectResponseCode HTTP.status202 @@ -1496,24 +1496,22 @@ spec = do length <$> [txs1, txs2] `shouldSatisfy` all (== 0) transactionDeleteTest01 - "wallets" it fixtureWallet ("cardano-wallet" :: Text) - postTxEp listTxEp deleteTxEp getWalletEp + "wallets" it fixtureWallet postTxEp listTxEp deleteTxEp getWalletEp -- xit -> it when submitting byron tx is supported by Jormungadr -- Then we need also to add impl of fixtureByronWallet in DSL transactionDeleteTest01 - "byron-wallets" xit fixtureByronWallet ("Secure Passphrase" :: Text) - postByronTxEp listByronTxEp deleteByronTxEp getByronWalletEp + "byron-wallets" xit fixtureByronWallet postByronTxEp listByronTxEp + deleteByronTxEp getByronWalletEp transactionDeleteTest02 - "wallets" it fixtureWallet emptyWallet ("cardano-wallet" :: Text) - postTxEp listTxEp deleteTxEp + "wallets" it fixtureWallet emptyWallet postTxEp listTxEp deleteTxEp -- xit -> it when submitting byron tx is supported by Jormungadr -- Then we need also to add impl of fixtureByronWallet in DSL transactionDeleteTest02 - "byron-wallets" xit fixtureByronWallet emptyWallet ("Secure Passphrase" :: Text) - postByronTxEp listByronTxEp deleteByronTxEp + "byron-wallets" xit fixtureByronWallet emptyWallet postByronTxEp + listByronTxEp deleteByronTxEp transactionDeleteTest03 emptyWallet "wallets" @@ -1523,12 +1521,24 @@ spec = do transactionDeleteTest04 "byron-wallets" + transactionDeleteTest07 emptyWallet "wallets" + + transactionDeleteTest07 emptyByronWallet "byron-wallets" + + transactionDeleteTest08 emptyWallet "wallets" + + transactionDeleteTest08 emptyByronWallet "byron-wallets" + + transactionDeleteTest09 "wallets" + + transactionDeleteTest09 "byron-wallets" + it "TRANS_DELETE_06 -\ \ Cannot forget tx that is performed from different wallet -> 404" $ \ctx -> do wDifferent <- emptyWallet ctx (wSrc, wDest) <- (,) <$> fixtureWallet ctx <*> emptyWallet ctx - rMkTx <- postTx ctx wSrc wDest (1 :: Natural) + rMkTx <- postTx ctx (wSrc, postTxEp) wDest (1 :: Natural) let txId = toText $ getApiT $ getFromResponse #id rMkTx let endpoint = "v2/wallets/" <> wDifferent ^. walletId @@ -1538,41 +1548,6 @@ spec = do expectResponseCode @IO HTTP.status404 ra expectErrorMessage (errMsg404CannotFindTx txId) ra - describe "TRANS_DELETE_07 - invalid tx id" $ do - let txIds = - [ replicate 63 '1' - , replicate 65 '1' - , replicate 64 'ś' - ] - forM_ txIds $ \tid -> it (show tid) $ \ctx -> do - w <- emptyWallet ctx - let wid = w ^. walletId - let endpoint = "v2/wallets/" <> wid <> "/transactions/" <> T.pack tid - r <- request @ApiTxId @IO ctx ("DELETE", endpoint) Default Empty - expectResponseCode @IO HTTP.status404 r - expectErrorMessage errMsg404NoEndpoint r - - describe "TRANS_DELETE_08 - HTTP headers" $ do - forM_ (getHeaderCases HTTP.status204) - $ \(title, headers, expectations) -> it title $ \ctx -> do - (wSrc, wDest) <- (,) <$> fixtureWallet ctx <*> emptyWallet ctx - rMkTx <- postTx ctx wSrc wDest (1 :: Natural) - let txId = getFromResponse #id rMkTx - let ep = deleteTxEp wSrc (ApiTxId txId) - r <- request @ApiTxId @IO ctx ep headers Empty - verify r expectations - - describe "TRANS_DELETE_09 -\ - \ v2/wallets/{id}/transactions/id - Methods Not Allowed" $ do - let matrix = ["POST", "CONNECT", "TRACE", "OPTIONS", "PUT", "GET"] - forM_ matrix $ \method -> it (show method) $ \ctx -> do - let txId = replicate 64 '1' - let wid = replicate 40 '1' - let endpoint = "v2/wallets/" <> wid <> "/transactions/" <> txId - r <- request @ApiTxId @IO ctx (method, T.pack endpoint) Default Empty - expectResponseCode @IO HTTP.status405 r - expectErrorMessage errMsg405 r - it "BYRON_TRANS_DELETE -\ \ Cannot delete tx on Byron wallet using shelley ep" $ \ctx -> do w <- emptyByronWallet ctx @@ -1636,32 +1611,19 @@ spec = do => String -> (String -> (Context t -> IO ()) -> SpecWith (Context t) ) -> (Context t -> IO wal) - -> Text -> (wal -> (Method, Text)) -> (wal -> Text -> (Method, Text)) -> (wal -> ApiTxId -> (Method, Text)) -> (wal -> (Method, Text)) -> SpecWith (Context t) transactionDeleteTest01 - str action fWallet passwd + str action fWallet postTxEndp listTxEndpSrc deleteTxEndp getWalletEndp = action ("TRANS_DELETE_01 - Single Output Transaction for " <> str) $ \ctx -> do (wSrc, wDest) <- (,) <$> fWallet ctx <*> emptyWallet ctx - -- post transaction - addrs <- listAddresses ctx wDest - let amt = 1 :: Int - let destination = (addrs !! 1) ^. #id - let payload = Json [json|{ - "payments": [{ - "address": #{destination}, - "amount": { - "quantity": #{amt}, - "unit": "lovelace" - } - }], - "passphrase": #{passwd} - }|] - rMkTx <- request @(ApiTransaction t) ctx (postTxEndp wSrc) Default payload + -- post tx + let amt = (1 :: Natural) + rMkTx <- postTx ctx (wSrc, postTxEndp) wDest amt let txId = getFromResponse #id rMkTx verify rMkTx [ expectSuccess @@ -1704,30 +1666,13 @@ spec = do ] transactionDeleteTest02 - str action fWallet eWallet passwd postTxEndp listTxEndp deleteTxEndp = + str action fWallet eWallet postTxEndp listTxEndp deleteTxEndp = action ("TRANS_DELETE_02 - checking not pending anymore error for " <> str) $ \ctx -> do (wSrc, wDest) <- (,) <$> fWallet ctx <*> eWallet ctx -- post transaction - addrs <- listAddresses ctx wDest - let amt = 1 :: Int - let destination = (addrs !! 1) ^. #id - let payload = Json [json|{ - "payments": [{ - "address": #{destination}, - "amount": { - "quantity": #{amt}, - "unit": "lovelace" - } - }], - "passphrase": #{passwd} - }|] - rMkTx <- request @(ApiTransaction t) ctx (postTxEndp wSrc) Default payload - let txId = getFromResponse #id rMkTx - verify rMkTx - [ expectSuccess - , expectResponseCode HTTP.status202 - ] + rTx <- postTx ctx (wSrc, postTxEndp) wDest (1 :: Int) + let txId = getFromResponse #id rTx -- Wait for the transaction to be accepted eventually $ do @@ -1766,7 +1711,49 @@ spec = do else expectErrorMessage errMsg404NoEndpoint r - postTx ctx wSrc wDest amt = do + transactionDeleteTest07 eWallet resource = + describe ("TRANS_DELETE_07 - invalid tx id " <> resource) $ do + let txIds = + [ replicate 63 '1' + , replicate 65 '1' + , replicate 64 'ś' + ] + forM_ txIds $ \tid -> it (show tid) $ \ctx -> do + w <- eWallet ctx + let wid = w ^. walletId + let ep = "v2/" <> T.pack resource <> "/" <> wid + <> "/transactions/" <> T.pack tid + r <- request @ApiTxId @IO ctx ("DELETE", ep) Default Empty + expectResponseCode @IO HTTP.status404 r + expectErrorMessage errMsg404NoEndpoint r + + transactionDeleteTest08 eWallet resource = + describe ("TRANS_DELETE_08 - HTTP headers " <> resource) $ do + forM_ (getHeaderCases HTTP.status404) + $ \(title, headers, expectations) -> it title $ \ctx -> do + w <- eWallet ctx + let wid = w ^. walletId + let txId = T.pack $ replicate 64 '1' + let ep = "v2/" <> T.pack resource <> "/" <> wid + <> "/transactions/" <> txId + r <- request @ApiTxId @IO ctx ("DELETE", ep) headers Empty + verify r expectations + + transactionDeleteTest09 res = + describe ("TRANS_DELETE_09 -\ + \ v2/" <> res <> "/{id}/transactions/id - Methods Not Allowed") $ do + let matrix = + ["POST", "CONNECT", "TRACE", "OPTIONS", "PUT", "GET"] + forM_ matrix $ \m -> it (show m) $ \ctx -> do + let txId = T.pack $ replicate 64 '1' + let wid = T.pack $ replicate 40 '1' + let ep = "v2/" <> T.pack res <> "/" <> wid + <> "/transactions/" <> txId + r <- request @ApiTxId @IO ctx (m, ep) Default Empty + expectResponseCode @IO HTTP.status405 r + expectErrorMessage errMsg405 r + + postTx ctx (wSrc, postTxEndp) wDest amt = do addrs <- listAddresses ctx wDest let destination = (addrs !! 1) ^. #id let payload = Json [json|{ @@ -1779,7 +1766,7 @@ spec = do }], "passphrase": "cardano-wallet" }|] - r <- request @(ApiTransaction t) ctx (postTxEp wSrc) Default payload + r <- request @(ApiTransaction t) ctx (postTxEndp wSrc) Default payload expectResponseCode HTTP.status202 r return r diff --git a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs index 373292ca1f6..11512161a71 100644 --- a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs +++ b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE NumericUnderscores #-} {-# LANGUAGE OverloadedLabels #-} {-# LANGUAGE QuasiQuotes #-} @@ -80,7 +81,7 @@ import Test.Integration.Framework.DSL , TxDescription (..) , balanceAvailable , balanceTotal - , deleteTxEp + , emptyByronWallet , emptyWallet , expectErrorMessage , expectEventually @@ -104,6 +105,7 @@ import Test.Integration.Framework.DSL , prepExternalTxViaJcli , request , verify + , walletId , walletName ) import Test.Integration.Framework.Request @@ -123,6 +125,7 @@ import qualified Data.ByteArray as BA import qualified Data.ByteString.Lazy as BL import qualified Data.List.NonEmpty as NE import qualified Data.Map as Map +import qualified Data.Text as T import qualified Data.Text.Encoding as T import qualified Network.HTTP.Types.Status as HTTP @@ -214,33 +217,37 @@ spec = do expectEventually' ctx getWalletEp balanceAvailable amt w expectEventually' ctx getWalletEp balanceTotal amt w - it "TRANS_DELETE_05 - \ - \Cannot forget external tx -> 404" $ \ctx -> do - - w <- emptyWallet ctx - addr:_ <- listAddresses ctx w - let addrStr = encodeAddress (Proxy @t) (getApiT $ fst $ addr ^. #id) - let amt = 1234 - - txBlob <- prepExternalTxViaJcli (ctx ^. typed @(Port "node")) addrStr amt - let payload = (NonJson . BL.fromStrict . toRawBytes Base16) txBlob - let headers = Headers - [ ("Content-Type", "application/octet-stream") - , ("Accept", "application/json")] - - r <- request @ApiTxId ctx postExternalTxEp headers payload - let txId = getFromResponse #id r - let txIdH = toText $ getApiT txId - - -- try to forget external tx - let endpoint = (deleteTxEp w (ApiTxId txId)) - ra <- request @ApiTxId @IO ctx endpoint Default Empty - expectResponseCode @IO HTTP.status404 ra - expectErrorMessage (errMsg404CannotFindTx txIdH) ra - - -- tx eventually gets into ledger (funds are on the wallet) - expectEventually' ctx getWalletEp balanceAvailable amt w - expectEventually' ctx getWalletEp balanceTotal amt w + describe "TRANS_DELETE_05 - Cannot forget external tx -> 404" $ do + let txDeleteTest05 res eWallet = it (show res) $ \ctx -> do + -- post external tx + wal <- emptyWallet ctx + addr:_ <- listAddresses ctx wal + let addrStr = encodeAddress (Proxy @t) (getApiT $ fst $ addr ^. #id) + let amt = 1234 + + txBlob <- prepExternalTxViaJcli (ctx ^. typed @(Port "node")) addrStr amt + let payload = (NonJson . BL.fromStrict . toRawBytes Base16) txBlob + let headers = Headers + [ ("Content-Type", "application/octet-stream") + , ("Accept", "application/json")] + + r <- request @ApiTxId ctx postExternalTxEp headers payload + let txId = toText $ getApiT$ getFromResponse #id r + + -- try to forget external tx using wallet or byron-wallet + w <- eWallet ctx + let ep = "v2/" <> T.pack res <> "/" <> w ^. walletId + <> "/transactions/" <> txId + ra <- request @ApiTxId @IO ctx ("DELETE", ep) Default Empty + expectResponseCode @IO HTTP.status404 ra + expectErrorMessage (errMsg404CannotFindTx txId) ra + + -- tx eventually gets into ledger (funds are on the target wallet) + expectEventually' ctx getWalletEp balanceAvailable amt wal + expectEventually' ctx getWalletEp balanceTotal amt wal + + txDeleteTest05 "wallets" emptyWallet + txDeleteTest05 "byron-wallets" emptyByronWallet it "TRANS_EXTERNAL_CREATE_01 - proper single output transaction and \ \proper binary format" $ \ctx -> do @@ -342,7 +349,6 @@ spec = do verify r expectations where - externalTxHeaders :: (Show a) => [( String From 1620655ec71bdf5e58cbccfab6036d6e7c7291a7 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Mon, 28 Oct 2019 08:12:45 +0100 Subject: [PATCH 4/5] Make tested capabilities more clear in the test suite --- .../Integration/Scenario/API/Transactions.hs | 105 +++++++++--------- 1 file changed, 52 insertions(+), 53 deletions(-) diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs index 37891a8a76c..6d50635c2d5 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs @@ -1495,43 +1495,43 @@ spec = do txs2 <- listTransactions ctx w (Just te) (Just te) Nothing length <$> [txs1, txs2] `shouldSatisfy` all (== 0) - transactionDeleteTest01 - "wallets" it fixtureWallet postTxEp listTxEp deleteTxEp getWalletEp - - -- xit -> it when submitting byron tx is supported by Jormungadr - -- Then we need also to add impl of fixtureByronWallet in DSL - transactionDeleteTest01 - "byron-wallets" xit fixtureByronWallet postByronTxEp listByronTxEp - deleteByronTxEp getByronWalletEp - - transactionDeleteTest02 - "wallets" it fixtureWallet emptyWallet postTxEp listTxEp deleteTxEp - - -- xit -> it when submitting byron tx is supported by Jormungadr - -- Then we need also to add impl of fixtureByronWallet in DSL - transactionDeleteTest02 - "byron-wallets" xit fixtureByronWallet emptyWallet postByronTxEp - listByronTxEp deleteByronTxEp - - transactionDeleteTest03 emptyWallet "wallets" - - transactionDeleteTest03 emptyByronWallet "byron-wallets" - - transactionDeleteTest04 "wallets" - - transactionDeleteTest04 "byron-wallets" - - transactionDeleteTest07 emptyWallet "wallets" - - transactionDeleteTest07 emptyByronWallet "byron-wallets" - - transactionDeleteTest08 emptyWallet "wallets" - - transactionDeleteTest08 emptyByronWallet "byron-wallets" - - transactionDeleteTest09 "wallets" - - transactionDeleteTest09 "byron-wallets" + describe "TRANS_DELETE_01 - Single Output Transaction for " $ do + txDeleteForgetSingleOutputTxTest + "wallets" it fixtureWallet postTxEp listTxEp deleteTxEp getWalletEp + -- xit -> it when submitting byron tx is supported by Jormungadr + -- Then we need also to add impl of fixtureByronWallet in DSL + txDeleteForgetSingleOutputTxTest + "byron-wallets" xit fixtureByronWallet postByronTxEp listByronTxEp + deleteByronTxEp getByronWalletEp + + describe "TRANS_DELETE_02 - checking not pending anymore error for " $ do + txDeleteNoLongerPendingTest + "wallets" it fixtureWallet emptyWallet postTxEp listTxEp deleteTxEp + -- xit -> it when submitting byron tx is supported by Jormungadr + -- Then we need also to add impl of fixtureByronWallet in DSL + txDeleteNoLongerPendingTest + "byron-wallets" xit fixtureByronWallet emptyWallet postByronTxEp + listByronTxEp deleteByronTxEp + + describe "TRANS_DELETE_03 - checking no transaction id error for " $ do + txDeleteNotExistsingTxIdTest emptyWallet "wallets" + txDeleteNotExistsingTxIdTest emptyByronWallet "byron-wallets" + + describe "TRANS_DELETE_04 - False wallet ids for " $ do + txDeleteFalseWalletIdsTest "wallets" + txDeleteFalseWalletIdsTest "byron-wallets" + + describe "TRANS_DELETE_07 - invalid tx id " $ do + txDeleteInvalidTxIdsTest emptyWallet "wallets" + txDeleteInvalidTxIdsTest emptyByronWallet "byron-wallets" + + describe "TRANS_DELETE_08 - HTTP headers " $ do + txDeleteHTTPHeadersTest emptyWallet "wallets" + txDeleteHTTPHeadersTest emptyByronWallet "byron-wallets" + + describe "TRANS_DELETE_09 - HTTP methods not allowed " $ do + txDeleteHTTPMethodsTest "wallets" + txDeleteHTTPMethodsTest "byron-wallets" it "TRANS_DELETE_06 -\ \ Cannot forget tx that is performed from different wallet -> 404" @@ -1601,7 +1601,7 @@ spec = do expectResponseCode @IO HTTP.status404 r expectErrorMessage (errMsg404NoWallet wid) r where - transactionDeleteTest01 + txDeleteForgetSingleOutputTxTest :: forall wal . ( Eq wal , FromJSON wal @@ -1616,10 +1616,10 @@ spec = do -> (wal -> ApiTxId -> (Method, Text)) -> (wal -> (Method, Text)) -> SpecWith (Context t) - transactionDeleteTest01 + txDeleteForgetSingleOutputTxTest str action fWallet postTxEndp listTxEndpSrc deleteTxEndp getWalletEndp = - action ("TRANS_DELETE_01 - Single Output Transaction for " <> str) $ \ctx -> do + action str $ \ctx -> do (wSrc, wDest) <- (,) <$> fWallet ctx <*> emptyWallet ctx -- post tx let amt = (1 :: Natural) @@ -1665,9 +1665,9 @@ spec = do , expectListItemFieldEqual 0 status InLedger ] - transactionDeleteTest02 + txDeleteNoLongerPendingTest str action fWallet eWallet postTxEndp listTxEndp deleteTxEndp = - action ("TRANS_DELETE_02 - checking not pending anymore error for " <> str) $ \ctx -> do + action str $ \ctx -> do (wSrc, wDest) <- (,) <$> fWallet ctx <*> eWallet ctx -- post transaction @@ -1689,8 +1689,8 @@ spec = do let err = errMsg403NoPendingAnymore (toUrlPiece (ApiTxId txId)) expectErrorMessage err rDel - transactionDeleteTest03 eWallet resource = - it ("TRANS_DELETE_03 - checking no transaction id error for " <> resource) $ \ctx -> do + txDeleteNotExistsingTxIdTest eWallet resource = + it resource $ \ctx -> do w <- eWallet ctx let walId = w ^. walletId let txId = "3e6ec12da4414aa0781ff8afa9717ae53ee8cb4aa55d622f65bc62619a4f7b12" @@ -1699,8 +1699,8 @@ spec = do expectResponseCode @IO HTTP.status404 ra expectErrorMessage (errMsg404CannotFindTx txId) ra - transactionDeleteTest04 resource = - describe ("TRANS_DELETE_04 - False wallet ids for " <> resource) $ do + txDeleteFalseWalletIdsTest resource = + describe resource $ do forM_ falseWalletIds $ \(title, walId) -> it title $ \ctx -> do let txId = "3e6ec12da4414aa0781ff8afa9717ae53ee8cb4aa55d622f65bc62619a4f7b12" let endpoint = "v2/" <> resource <> "/" <> walId <> "/transactions/" <> txId @@ -1711,8 +1711,8 @@ spec = do else expectErrorMessage errMsg404NoEndpoint r - transactionDeleteTest07 eWallet resource = - describe ("TRANS_DELETE_07 - invalid tx id " <> resource) $ do + txDeleteInvalidTxIdsTest eWallet resource = + describe resource $ do let txIds = [ replicate 63 '1' , replicate 65 '1' @@ -1727,8 +1727,8 @@ spec = do expectResponseCode @IO HTTP.status404 r expectErrorMessage errMsg404NoEndpoint r - transactionDeleteTest08 eWallet resource = - describe ("TRANS_DELETE_08 - HTTP headers " <> resource) $ do + txDeleteHTTPHeadersTest eWallet resource = + describe resource $ do forM_ (getHeaderCases HTTP.status404) $ \(title, headers, expectations) -> it title $ \ctx -> do w <- eWallet ctx @@ -1739,9 +1739,8 @@ spec = do r <- request @ApiTxId @IO ctx ("DELETE", ep) headers Empty verify r expectations - transactionDeleteTest09 res = - describe ("TRANS_DELETE_09 -\ - \ v2/" <> res <> "/{id}/transactions/id - Methods Not Allowed") $ do + txDeleteHTTPMethodsTest res = + describe ("v2/" <> res <> "/{wid}/transactions/{tid}") $ do let matrix = ["POST", "CONNECT", "TRACE", "OPTIONS", "PUT", "GET"] forM_ matrix $ \m -> it (show m) $ \ctx -> do From be6f978c39f2fdc61fa64b683660e9080f052c8e Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Mon, 28 Oct 2019 10:58:19 +0100 Subject: [PATCH 5/5] reuse TRANS_DELETE_06 for byron-wallets --- .../Integration/Scenario/API/Transactions.hs | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs index 6d50635c2d5..daa71fc268a 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Transactions.hs @@ -1533,20 +1533,10 @@ spec = do txDeleteHTTPMethodsTest "wallets" txDeleteHTTPMethodsTest "byron-wallets" - it "TRANS_DELETE_06 -\ - \ Cannot forget tx that is performed from different wallet -> 404" - $ \ctx -> do - wDifferent <- emptyWallet ctx - (wSrc, wDest) <- (,) <$> fixtureWallet ctx <*> emptyWallet ctx - rMkTx <- postTx ctx (wSrc, postTxEp) wDest (1 :: Natural) - let txId = toText $ getApiT $ getFromResponse #id rMkTx - let endpoint = "v2/wallets/" - <> wDifferent ^. walletId - <> "/transactions/" - <> txId - ra <- request @ApiTxId @IO ctx ("DELETE", endpoint) Default Empty - expectResponseCode @IO HTTP.status404 ra - expectErrorMessage (errMsg404CannotFindTx txId) ra + describe "TRANS_DELETE_06 -\ + \ Cannot forget tx that is performed from different wallet" $ do + txDeleteFromDifferentWalletTest emptyWallet "wallets" + txDeleteFromDifferentWalletTest emptyByronWallet "byron-wallets" it "BYRON_TRANS_DELETE -\ \ Cannot delete tx on Byron wallet using shelley ep" $ \ctx -> do @@ -1727,6 +1717,23 @@ spec = do expectResponseCode @IO HTTP.status404 r expectErrorMessage errMsg404NoEndpoint r + txDeleteFromDifferentWalletTest eWallet resource= + it resource $ \ctx -> do + -- post tx + (wSrc, wDest) <- (,) <$> fixtureWallet ctx <*> emptyWallet ctx + rMkTx <- postTx ctx (wSrc, postTxEp) wDest (1 :: Natural) + + -- try to forget from different wallet + wDifferent <- eWallet ctx + let txId = toText $ getApiT $ getFromResponse #id rMkTx + let endpoint = "v2/" <> T.pack resource <> "/" + <> wDifferent ^. walletId + <> "/transactions/" + <> txId + ra <- request @ApiTxId @IO ctx ("DELETE", endpoint) Default Empty + expectResponseCode @IO HTTP.status404 ra + expectErrorMessage (errMsg404CannotFindTx txId) ra + txDeleteHTTPHeadersTest eWallet resource = describe resource $ do forM_ (getHeaderCases HTTP.status404)