From 224ade30e1c856d46bc1951b39f798caa74ae7e0 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Tue, 12 Feb 2019 09:25:35 +0100 Subject: [PATCH 01/10] EOWWALLETS_CREATE tests --- .../Test/Integration/Scenario/EosWallets.hs | 82 ++++++++++++++++++- 1 file changed, 78 insertions(+), 4 deletions(-) diff --git a/test/integration/Test/Integration/Scenario/EosWallets.hs b/test/integration/Test/Integration/Scenario/EosWallets.hs index fcb33346b..034348cdb 100644 --- a/test/integration/Test/Integration/Scenario/EosWallets.hs +++ b/test/integration/Test/Integration/Scenario/EosWallets.hs @@ -10,6 +10,7 @@ import qualified Data.List.NonEmpty as NE import Cardano.Wallet.Client.Http (ClientError, Wallet) import qualified Cardano.Wallet.Client.Http as Client +import Test.Hspec (describe) import Test.Integration.Framework.DSL @@ -22,7 +23,6 @@ spec = do noAddressPoolGap defaultAssuranceLevel defaultWalletName - response <- request $ Client.getEosWallet $- eowallet ^. walletId verify response @@ -50,14 +50,88 @@ spec = do , expectFieldEqual addressPoolGap (fixture ^. addressPoolGap) ] + describe "EOSWALLETS_CREATE_02 - addressPoolGap cannot be outside [10..100]" $ do + forM_ ([-1, 0, 9, 101]) $ \poolGap -> scenario ("addressPoolGap = " ++ show (poolGap :: Int)) $ do + let endpoint = "api/v1/wallets/externally-owned" + response <- unsafeRequest ("POST", endpoint) $ Just $ [json|{ + "accounts": [ + { + "publicKey": "1OQQ6jrO8xzPyybgLEk5vuUcoCCH4fds3k5rqnxErglRb7EiGQKa74TP9jx0ATHCqUiD8uLO6pP8z31+c393lw==", + "index": 2710723942 + } + ], + "addressPoolGap": #{poolGap}, + "assuranceLevel": "normal", + "name": "My EOS Wallet" + }|] + verify (response :: Either ClientError EosWallet) + [ expectJSONError $ case poolGap of + -1 -> "Error in $.addressPoolGap: Word8 is either floating or will cause over or underflow: -1.0" + _ -> "Error in $.addressPoolGap: Address pool gap should be in range [10..100]" + ] + scenario "EOSWALLETS_CREATE_03 - one can't provide an empty list of accounts" $ do let endpoint = "api/v1/wallets/externally-owned" response <- unsafeRequest ("POST", endpoint) $ Just $ [json|{ "accounts": [], - "addressPoolGap": "#{noAddressPoolGap}", - "assuranceLevel": "#{defaultAssuranceLevel}", - "name": "#{defaultWalletName}" + "addressPoolGap": 10, + "assuranceLevel": "normal", + "name": "My EOS Wallet" }|] verify (response :: Either ClientError EosWallet) [ expectError ] + + describe "EOSWALLETS_CREATE_04 - one has to provide assuranceLevel to be either 'normal' or 'strict'" $ do + let matrix = + [ ( "normal" + , [json| "normal" |] + , [ expectSuccess ] + ) + , ( "strict" + , [json| "strict" |] + , [ expectSuccess ] + ) + , ( "empty string" + , [json| "" |] + , [ expectJSONError "Error in $.assuranceLevel: When parsing Cardano.Wallet.API.V1.Types.AssuranceLevel expected a String with the tag of a constructor but got ." ] + ) + , ( "555" + , [json| 555 |] + , [ expectJSONError "Error in $.assuranceLevel: When parsing Cardano.Wallet.API.V1.Types.AssuranceLevel expected String but got Number." ] + ) + , ( "亜哀愛źiemniak悪握圧扱安" + , [json| "亜哀愛źiemniak悪握圧扱安" |] + , [ expectJSONError "Error in $.assuranceLevel: When parsing Cardano.Wallet.API.V1.Types.AssuranceLevel expected a String with the tag of a constructor but got 亜哀愛źiemniak悪握圧扱安" ] + ) + ] + + forM_ matrix $ \(title, assurLevel, expectations) -> scenario ("assuranceLevel = " ++ title) $ do + let endpoint = "api/v1/wallets/externally-owned" + response <- unsafeRequest ("POST", endpoint) $ Just $ [json|{ + "accounts": [ + { + "publicKey": "1OQQ6jrO8xzPyybgLEk5vuUcoCCH4fds3k5rqnxErglRb7EiGQKa74TP9jx0ATHCqUiD8uLO6pP8z31+c393lw==", + "index": 2710723942 + } + ], + "assuranceLevel": #{assurLevel}, + "addressPoolGap": 10, + "name": "My EOS Wallet" + }|] + verify (response :: Either ClientError EosWallet) expectations + + scenario "EOSWALLETS_CREATE_05 - one has to provide wallet's name" $ do + response <- unsafeRequest ("POST", "api/v1/wallets/externally-owned") $ Just $ [json|{ + "accounts": [ + { + "publicKey": "1OQQ6jrO8xzPyybgLEk5vuUcoCCH4fds3k5rqnxErglRb7EiGQKa74TP9jx0ATHCqUiD8uLO6pP8z31+c393lw==", + "index": 2710723942 + } + ], + "addressPoolGap": 70, + "assuranceLevel": "strict" + }|] + verify (response :: Either ClientError EosWallet) + [ expectJSONError "Error in $: When parsing the record newEosWallet of type Cardano.Wallet.API.V1.Types.NewEosWallet the key name was not present." + ] From af1c5bdf1d463bb9f9a7153ac5343c8babdd15b0 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Tue, 12 Feb 2019 15:32:30 +0100 Subject: [PATCH 02/10] EOS wallets list, update, delete --- .../Test/Integration/Scenario/EosWallets.hs | 181 +++++++++++++++++- 1 file changed, 177 insertions(+), 4 deletions(-) diff --git a/test/integration/Test/Integration/Scenario/EosWallets.hs b/test/integration/Test/Integration/Scenario/EosWallets.hs index 034348cdb..694df32b6 100644 --- a/test/integration/Test/Integration/Scenario/EosWallets.hs +++ b/test/integration/Test/Integration/Scenario/EosWallets.hs @@ -12,7 +12,7 @@ import Cardano.Wallet.Client.Http (ClientError, Wallet) import qualified Cardano.Wallet.Client.Http as Client import Test.Hspec (describe) import Test.Integration.Framework.DSL - +import Cardano.Wallet.API.V1.Types spec :: Scenarios Context spec = do @@ -23,8 +23,8 @@ spec = do noAddressPoolGap defaultAssuranceLevel defaultWalletName - response <- request $ Client.getEosWallet $- eowallet ^. walletId + response <- request $ Client.getEosWallet $- eowallet ^. walletId verify response [ expectFieldEqual walletId (eowallet ^. walletId) , expectFieldEqual assuranceLevel defaultAssuranceLevel @@ -86,11 +86,15 @@ spec = do let matrix = [ ( "normal" , [json| "normal" |] - , [ expectSuccess ] + , [ expectSuccess + , expectFieldEqual assuranceLevel NormalAssurance + ] ) , ( "strict" , [json| "strict" |] - , [ expectSuccess ] + , [ expectSuccess + , expectFieldEqual assuranceLevel StrictAssurance + ] ) , ( "empty string" , [json| "" |] @@ -135,3 +139,172 @@ spec = do verify (response :: Either ClientError EosWallet) [ expectJSONError "Error in $: When parsing the record newEosWallet of type Cardano.Wallet.API.V1.Types.NewEosWallet the key name was not present." ] + + + scenario "EOSWALLETS_CREATE_06 - create wallet reponse returns wallet details" $ do + fixture <- setup defaultSetup + eowallet <- request $ Client.postEosWallet $- NewEosWallet + (NE.fromList $ take 3 $ fixture ^. externallyOwnedAccounts) + noAddressPoolGap + defaultAssuranceLevel + defaultWalletName + verify eowallet + [ expectFieldEqual assuranceLevel defaultAssuranceLevel + , expectFieldEqual walletName defaultWalletName + , expectFieldEqual addressPoolGap defaultAddressPoolGap + , expectFieldEqual amount 0 + ] + + + scenario "EOSWALLETS_DELETE_01 - deleted wallet is not available" $ do + fixture <- setup defaultSetup + eowallet <- successfulRequest $ Client.postEosWallet $- NewEosWallet + (NE.fromList $ take 3 $ fixture ^. externallyOwnedAccounts) + noAddressPoolGap + defaultAssuranceLevel + defaultWalletName + + successfulRequest $ Client.deleteEosWallet $- eowallet ^. walletId + + response <- request $ Client.getEosWallet $- eowallet ^. walletId + verify response + [ expectWalletError (WalletNotFound) + ] + + scenario "EOSWALLETS_DELETE_02 - cannot delete FO wallet with EOS endpoint" $ do + fixture <- setup defaultSetup + + delResp <- request $ Client.deleteEosWallet $- fixture ^. wallet . walletId + verify delResp + [ expectWalletError (WalletNotFound) + ] + + getFo <- request $ Client.getWallet $- fixture ^. wallet . walletId + verify getFo + [ expectSuccess + ] + + scenario "EOSWALLETS_DELETE_02 - cannot delete EOS wallet with FO endpoint" $ do + fixture <- setup defaultSetup + eowallet <- successfulRequest $ Client.postEosWallet $- NewEosWallet + (NE.fromList $ take 3 $ fixture ^. externallyOwnedAccounts) + noAddressPoolGap + defaultAssuranceLevel + defaultWalletName + + delResp <- request $ Client.deleteWallet $- eowallet ^. walletId + verify delResp + [ expectWalletError (WalletNotFound) + ] + + getEos <- request $ Client.getEosWallet $- eowallet ^. walletId + verify getEos + [ expectSuccess + ] + + + scenario "EOSWALLETS_DETAILS_01 - cannot get FO wallet with EOS endpoint" $ do + fixture <- setup defaultSetup + + getFoWithEos <- request $ Client.getEosWallet $- fixture ^. wallet . walletId + verify getFoWithEos + [ expectWalletError (WalletNotFound) + -- expectWalletError (UnknownError "ErrorCall") + ] + + scenario "EOSWALLETS_DETAILS_01 - cannot get EOS wallet with FO endpoint" $ do + fixture <- setup defaultSetup + eowallet <- successfulRequest $ Client.postEosWallet $- NewEosWallet + (NE.fromList $ take 3 $ fixture ^. externallyOwnedAccounts) + noAddressPoolGap + defaultAssuranceLevel + defaultWalletName + + getEosWithFo <- request $ Client.getWallet $- eowallet ^. walletId + verify getEosWithFo + [ expectWalletError (WalletNotFound) + ] + + scenario "EOSWALLETS_LIST_01 - cannot get EOS wallets with FO endpoint" $ do + fixture <- setup defaultSetup + _ <- successfulRequest $ Client.postEosWallet $- NewEosWallet + (NE.fromList $ take 3 $ fixture ^. externallyOwnedAccounts) + noAddressPoolGap + defaultAssuranceLevel + defaultWalletName + + getFO <- request $ Client.getWallets + verify getFO + [ expectSuccess + , expectListSizeEqual 1 + , expectListItemFieldEqual 0 walletId (fixture ^. wallet . walletId) + ] + + scenario "EOSWALLETS_LIST_01 - cannot get FO wallets with EOS endpoint" $ do + fixture <- setup defaultSetup + eowallet <- successfulRequest $ Client.postEosWallet $- NewEosWallet + (NE.fromList $ take 3 $ fixture ^. externallyOwnedAccounts) + noAddressPoolGap + defaultAssuranceLevel + defaultWalletName + + getFO <- request $ Client.getEosWalletIndexFilterSorts + $- Nothing + $- Nothing + $- NoFilters + $- NoSorts + verify getFO + [ expectSuccess + , expectListSizeEqual 1 + , expectListItemFieldEqual 0 walletId (eowallet ^. walletId) + ] + + scenario "EOSWALLETS_UPDATE_01 - cannot update FO wallets with EOS endpoint" $ do + fixture <- setup $ defaultSetup + & walletName .~ "Before update FO" + & assuranceLevel .~ NormalAssurance + + let endpoint = "api/v1/wallets/externally-owned/" <> fromWalletId (fixture ^. wallet . walletId) + updResp <- unsafeRequest ("PUT", endpoint) $ Just $ [json|{ + "assuranceLevel": "strict", + "addressPoolGap": 12, + "name": "My EosWallet2" + }|] + verify (updResp :: Either ClientError EosWallet) + [ expectWalletError (UnknownError "UpdateEosWalletError") + ] + + response <- request $ Client.getWallet $- fixture ^. wallet . walletId + verify response + [ expectFieldEqual walletId (fixture ^. wallet . walletId) + , expectFieldEqual assuranceLevel NormalAssurance + , expectFieldEqual walletName "Before update" + ] + + scenario "EOSWALLETS_UPDATE_01 - cannot update EOS wallets with FO endpoint" $ do + fixture <- setup defaultSetup + eowallet <- successfulRequest $ Client.postEosWallet $- NewEosWallet + (NE.fromList $ take 3 $ fixture ^. externallyOwnedAccounts) + noAddressPoolGap + NormalAssurance + "Before update EOS" + + let endpoint = "api/v1/wallets/" <> fromWalletId (eowallet ^. walletId) + updResp <- unsafeRequest ("PUT", endpoint) $ Just $ [json|{ + "assuranceLevel": "strict", + "name": "My EosWallet" + }|] + verify (updResp :: Either ClientError EosWallet) + [ expectError + ] + + response <- request $ Client.getEosWallet $- eowallet ^. walletId + verify response + [ expectFieldEqual walletId (eowallet ^. walletId) + , expectFieldEqual assuranceLevel NormalAssurance + , expectFieldEqual walletName "Before update EOS" + , expectFieldEqual addressPoolGap defaultAddressPoolGap + ] + where + fromWalletId :: Client.WalletId -> Text + fromWalletId (Client.WalletId a) = a From 9570c9ce68616c69807020e673b129e24bcbc0a2 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Wed, 13 Feb 2019 09:45:34 +0100 Subject: [PATCH 03/10] EOSWALLETS_UPDATE_01 fix --- test/integration/Test/Integration/Scenario/EosWallets.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/Test/Integration/Scenario/EosWallets.hs b/test/integration/Test/Integration/Scenario/EosWallets.hs index 694df32b6..a5dfd3661 100644 --- a/test/integration/Test/Integration/Scenario/EosWallets.hs +++ b/test/integration/Test/Integration/Scenario/EosWallets.hs @@ -278,7 +278,7 @@ spec = do verify response [ expectFieldEqual walletId (fixture ^. wallet . walletId) , expectFieldEqual assuranceLevel NormalAssurance - , expectFieldEqual walletName "Before update" + , expectFieldEqual walletName "Before update FO" ] scenario "EOSWALLETS_UPDATE_01 - cannot update EOS wallets with FO endpoint" $ do From 716f0086cff866e9693b881f32ef093a8bfb5ba5 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Wed, 13 Feb 2019 18:13:48 +0100 Subject: [PATCH 04/10] CREATE, DELETE, UPDATE, DETAILS tests --- .../Test/Integration/Framework/DSL.hs | 4 + .../Test/Integration/Scenario/EosWallets.hs | 142 +++++++++++++++++- 2 files changed, 143 insertions(+), 3 deletions(-) diff --git a/test/integration/Test/Integration/Framework/DSL.hs b/test/integration/Test/Integration/Framework/DSL.hs index 7496aea21..62644b1ed 100644 --- a/test/integration/Test/Integration/Framework/DSL.hs +++ b/test/integration/Test/Integration/Framework/DSL.hs @@ -85,6 +85,7 @@ module Test.Integration.Framework.DSL , amount , assuranceLevel , backupPhrase + , createdAt , externallyOwnedAccounts , failures , fromWalletId @@ -390,6 +391,9 @@ assuranceLevel = typed backupPhrase :: HasType BackupPhrase s => Lens' s BackupPhrase backupPhrase = typed +createdAt :: HasType WalletTimestamp s => Lens' s WalletTimestamp +createdAt = typed + externallyOwnedAccounts :: HasType [AccountPublicKeyWithIx] s => Lens' s [AccountPublicKeyWithIx] externallyOwnedAccounts = typed diff --git a/test/integration/Test/Integration/Scenario/EosWallets.hs b/test/integration/Test/Integration/Scenario/EosWallets.hs index a5dfd3661..f35c56221 100644 --- a/test/integration/Test/Integration/Scenario/EosWallets.hs +++ b/test/integration/Test/Integration/Scenario/EosWallets.hs @@ -16,7 +16,7 @@ import Cardano.Wallet.API.V1.Types spec :: Scenarios Context spec = do - scenario "EOSWALLETS_CREATE_01 - one can use default address pool gap" $ do + scenario "EOSWALLETS_CREATE_01, EOSWALLETS_DETAILS_02 - one can use default address pool gap" $ do fixture <- setup defaultSetup eowallet <- successfulRequest $ Client.postEosWallet $- NewEosWallet (NE.fromList $ take 3 $ fixture ^. externallyOwnedAccounts) @@ -30,9 +30,10 @@ spec = do , expectFieldEqual assuranceLevel defaultAssuranceLevel , expectFieldEqual walletName defaultWalletName , expectFieldEqual addressPoolGap defaultAddressPoolGap + , expectFieldEqual amount 0 ] - scenario "EOSWALLETS_CREATE_02 - one can configure the address pool gap" $ do + scenario "EOSWALLETS_CREATE_02, EOSWALLETS_DETAILS_02 - one can configure the address pool gap" $ do fixture <- setup $ defaultSetup & rawAddressPoolGap .~ 14 eowallet <- successfulRequest $ Client.postEosWallet $- NewEosWallet @@ -48,6 +49,7 @@ spec = do , expectFieldEqual assuranceLevel defaultAssuranceLevel , expectFieldEqual walletName defaultWalletName , expectFieldEqual addressPoolGap (fixture ^. addressPoolGap) + , expectFieldEqual amount 0 ] describe "EOSWALLETS_CREATE_02 - addressPoolGap cannot be outside [10..100]" $ do @@ -82,6 +84,79 @@ spec = do [ expectError ] + scenario "EOSWALLETS_CREATE_03 - publicKey must be present" $ do + response <- unsafeRequest ("POST", "api/v1/wallets/externally-owned") $ Just $ [json|{ + "accounts": [ + { + "index": 2710723942 + } + ], + "addressPoolGap": 10, + "assuranceLevel": "strict", + "name": "My EOS Wallet" + }|] + verify (response :: Either ClientError EosWallet) + [ expectJSONError "Error in $.accounts[0]: When parsing the record accountPublicKeyWithIx of type Cardano.Wallet.API.V1.Types.AccountPublicKeyWithIx the key publicKey was not present." + ] + + scenario "EOSWALLETS_CREATE_03 - index must be present" $ do + response <- unsafeRequest ("POST", "api/v1/wallets/externally-owned") $ Just $ [json|{ + "accounts": [ + { + "publicKey": "1OQQ6jrO8xzPyybgLEk5vuUcoCCH4fds3k5rqnxErglRb7EiGQKa74TP9jx0ATHCqUiD8uLO6pP8z31+c393lw==" + + } + ], + "addressPoolGap": 10, + "assuranceLevel": "strict", + "name": "My EOS Wallet" + }|] + verify (response :: Either ClientError EosWallet) + [ expectJSONError "Error in $.accounts[0]: When parsing the record accountPublicKeyWithIx of type Cardano.Wallet.API.V1.Types.AccountPublicKeyWithIx the key index was not present." + ] + + describe "EOSWALLETS_CREATE_03 - index must be [2147483648..4294967295]" $ do + forM_ ([-1, 0, 1, 2147483647, 2147483648, 4294967295, 4294967296]) $ \(index) -> scenario ("index = " ++ show (index :: Int)) $ do + response <- unsafeRequest ("POST", "api/v1/wallets/externally-owned") $ Just $ [json|{ + "accounts": [ + { + "publicKey": "1OQQ6jrO8xzPyybgLEk5vuUcoCCH4fds3k5rqnxErglRb7EiGQKa74TP9jx0ATHCqUiD8uLO6pP8z31+c393lw==", + "index": #{index} + } + ], + "addressPoolGap": 10, + "assuranceLevel": "strict", + "name": "My EOS Wallet" + }|] + verify (response :: Either ClientError EosWallet) + [ case index of + 2147483648 -> expectSuccess + 4294967295 -> expectSuccess + -1 -> expectJSONError "Error in $.accounts[0].index: Word32 is either floating or will cause over or underflow" + 4294967296 -> expectJSONError "Error in $.accounts[0].index: Word32 is either floating or will cause over or underflow" + _ -> expectJSONError "Error in $.accounts[0].index: Account index should be in range [2147483648..4294967295]" + ] + + describe "EOSWALLETS_CREATE_03 - publicKey must be valid" $ do + forM_ (["", "123", "ziemniak", "1OQQ6jrO8xzPyybgLEk5vuUcoCCH4fds3k5rqnxErglRb7EiGQKa74TP9jx0ATHCqUiD8uLO6pP8z31"]) $ \(key) -> scenario ("key = \"" ++ key ++ "\"") $ do + response <- unsafeRequest ("POST", "api/v1/wallets/externally-owned") $ Just $ [json|{ + "accounts": [ + { + "publicKey": #{key}, + "index": 2710723942 + } + ], + "addressPoolGap": 10, + "assuranceLevel": "strict", + "name": "My EOS Wallet" + }|] + verify (response :: Either ClientError EosWallet) + [ case key of + "" -> expectJSONError "Error in $.accounts[0].publicKey: Unable to parse json PublicKey reason: error: xprv needs to be 64 bytes: got 0 bytes" + "ziemniak" -> expectJSONError "Error in $.accounts[0].publicKey: Unable to parse json PublicKey reason: error: xprv needs to be 64 bytes: got 6 bytes" + _ -> expectJSONError "Error in $.accounts[0].publicKey: Unable to parse json PublicKey reason: invalid padding" + ] + describe "EOSWALLETS_CREATE_04 - one has to provide assuranceLevel to be either 'normal' or 'strict'" $ do let matrix = [ ( "normal" @@ -202,6 +277,33 @@ spec = do [ expectSuccess ] + scenario "EOSWALLETS_DELETE_03, EOSWALLETS_DETAILS_03 - Providing non-existing wallet id returns 404 error and appropriate error message." $ do + fixture <- setup defaultSetup + eowallet <- successfulRequest $ Client.postEosWallet $- NewEosWallet + (NE.fromList $ take 3 $ fixture ^. externallyOwnedAccounts) + noAddressPoolGap + defaultAssuranceLevel + defaultWalletName + + _ <- successfulRequest $ Client.deleteEosWallet $- eowallet ^. walletId + delResp <- request $ Client.deleteEosWallet $- eowallet ^. walletId + verify delResp + [ expectWalletError (WalletNotFound) + ] + + getEos <- request $ Client.getEosWallet $- eowallet ^. walletId + verify getEos + [ expectWalletError (WalletNotFound) + ] + + describe "EOSWALLETS_DELETE_03 - Providing not valid wallet id returns 404 error and appropriate error message." $ do + forM_ (["", "123", "ziemniak"]) $ \(notValidId) -> scenario ("walId = \"" ++ notValidId ++ "\"") $ do + let endpoint = "api/v1/wallets/externally-owned/" ++ notValidId + response <- unsafeRequest ("DELETE", fromString endpoint) $ Nothing + verify (response :: Either ClientError EosWallet) + [ expectError + -- TODO: add more expectations after #221 is resolved + ] scenario "EOSWALLETS_DETAILS_01 - cannot get FO wallet with EOS endpoint" $ do fixture <- setup defaultSetup @@ -209,7 +311,6 @@ spec = do getFoWithEos <- request $ Client.getEosWallet $- fixture ^. wallet . walletId verify getFoWithEos [ expectWalletError (WalletNotFound) - -- expectWalletError (UnknownError "ErrorCall") ] scenario "EOSWALLETS_DETAILS_01 - cannot get EOS wallet with FO endpoint" $ do @@ -225,6 +326,15 @@ spec = do [ expectWalletError (WalletNotFound) ] + describe "EOSWALLETS_DETAILS_03 - Providing not valid wallet id returns 404 error and appropriate error message." $ do + forM_ (["", "123", "ziemniak"]) $ \(notValidId) -> scenario ("walId = \"" ++ notValidId ++ "\"") $ do + let endpoint = "api/v1/wallets/externally-owned/" ++ notValidId + response <- unsafeRequest ("GET", fromString endpoint) $ Nothing + verify (response :: Either ClientError EosWallet) + [ expectError + -- TODO: add more expectations after #221 is resolved + ] + scenario "EOSWALLETS_LIST_01 - cannot get EOS wallets with FO endpoint" $ do fixture <- setup defaultSetup _ <- successfulRequest $ Client.postEosWallet $- NewEosWallet @@ -305,6 +415,32 @@ spec = do , expectFieldEqual walletName "Before update EOS" , expectFieldEqual addressPoolGap defaultAddressPoolGap ] + + scenario "EOSWALLETS_UPDATE_02, EOSWALLETS_DETAILS_04 - Updating wallet, updates name, assuranceLevel and addressPoolGap only" $ do + fixture <- setup $ defaultSetup + & rawAddressPoolGap .~ 12 + eowallet <- successfulRequest $ Client.postEosWallet $- NewEosWallet + (NE.fromList $ take 3 $ fixture ^. externallyOwnedAccounts) + noAddressPoolGap + NormalAssurance + "Before update EOS" + + let expectations = [ -- updated + expectFieldEqual assuranceLevel StrictAssurance + , expectFieldEqual walletName "After update EOS" + , expectFieldEqual addressPoolGap (fixture ^. addressPoolGap) + -- not updated + , expectFieldEqual createdAt (eowallet ^. createdAt) + , expectFieldEqual amount 0 + ] + + updResp <- request $ Client.updateEosWallet + $- (eowallet ^. walletId) + $- UpdateEosWallet StrictAssurance "After update EOS" (fixture ^. addressPoolGap) + verify updResp expectations + + response <- request $ Client.getEosWallet $- eowallet ^. walletId + verify response expectations where fromWalletId :: Client.WalletId -> Text fromWalletId (Client.WalletId a) = a From 27267a729c41cd8ec5d656e7ec39ca7f26f018d0 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Thu, 14 Feb 2019 14:56:17 +0100 Subject: [PATCH 05/10] more tests for CRUD operations --- .../Test/Integration/Scenario/EosWallets.hs | 153 ++++++++++++++++-- 1 file changed, 138 insertions(+), 15 deletions(-) diff --git a/test/integration/Test/Integration/Scenario/EosWallets.hs b/test/integration/Test/Integration/Scenario/EosWallets.hs index f35c56221..314bdf3f1 100644 --- a/test/integration/Test/Integration/Scenario/EosWallets.hs +++ b/test/integration/Test/Integration/Scenario/EosWallets.hs @@ -200,20 +200,46 @@ spec = do }|] verify (response :: Either ClientError EosWallet) expectations - scenario "EOSWALLETS_CREATE_05 - one has to provide wallet's name" $ do - response <- unsafeRequest ("POST", "api/v1/wallets/externally-owned") $ Just $ [json|{ - "accounts": [ - { - "publicKey": "1OQQ6jrO8xzPyybgLEk5vuUcoCCH4fds3k5rqnxErglRb7EiGQKa74TP9jx0ATHCqUiD8uLO6pP8z31+c393lw==", - "index": 2710723942 - } - ], - "addressPoolGap": 70, - "assuranceLevel": "strict" - }|] - verify (response :: Either ClientError EosWallet) - [ expectJSONError "Error in $: When parsing the record newEosWallet of type Cardano.Wallet.API.V1.Types.NewEosWallet the key name was not present." - ] + describe "EOSWALLETS_CREATE_05 - one has to provide all required parameters" $ do + let matrix = + [ ( "no accounts" + , [json| { + "addressPoolGap": 70, + "assuranceLevel": "strict", + "name": "Wallet EOS" + } |] + , [ expectJSONError "Error in $: When parsing the record newEosWallet of type Cardano.Wallet.API.V1.Types.NewEosWallet the key accounts was not present." ] + ) + , ( "no assuranceLevel" + , [json| { + "accounts": [ + { + "publicKey": "1OQQ6jrO8xzPyybgLEk5vuUcoCCH4fds3k5rqnxErglRb7EiGQKa74TP9jx0ATHCqUiD8uLO6pP8z31+c393lw==", + "index": 2710723942 + } + ], + "addressPoolGap": 70, + "name": "Wallet EOS" + } |] + , [ expectJSONError "Error in $: When parsing the record newEosWallet of type Cardano.Wallet.API.V1.Types.NewEosWallet the key assuranceLevel was not present." ] + ) + , ( "no name" + , [json| { + "accounts": [ + { + "publicKey": "1OQQ6jrO8xzPyybgLEk5vuUcoCCH4fds3k5rqnxErglRb7EiGQKa74TP9jx0ATHCqUiD8uLO6pP8z31+c393lw==", + "index": 2710723942 + } + ], + "addressPoolGap": 70, + "assuranceLevel": "strict" + } |] + , [ expectJSONError "Error in $: When parsing the record newEosWallet of type Cardano.Wallet.API.V1.Types.NewEosWallet the key name was not present." ] + ) + ] + forM_ matrix $ \(title, payload, expectations) -> scenario title $ do + response <- unsafeRequest ("POST", "api/v1/wallets/externally-owned") $ Just $ [json|#{payload}|] + verify (response :: Either ClientError EosWallet) expectations scenario "EOSWALLETS_CREATE_06 - create wallet reponse returns wallet details" $ do @@ -350,7 +376,7 @@ spec = do , expectListItemFieldEqual 0 walletId (fixture ^. wallet . walletId) ] - scenario "EOSWALLETS_LIST_01 - cannot get FO wallets with EOS endpoint" $ do + scenario "EOSWALLETS_LIST_01, EOSWALLETS_LIST_02 - cannot get FO wallets with EOS endpoint" $ do fixture <- setup defaultSetup eowallet <- successfulRequest $ Client.postEosWallet $- NewEosWallet (NE.fromList $ take 3 $ fixture ^. externallyOwnedAccounts) @@ -441,6 +467,103 @@ spec = do response <- request $ Client.getEosWallet $- eowallet ^. walletId verify response expectations + + describe "EOSWALLETS_UPDATE_03 - addressPoolGap cannot be outside [10..100]" $ do + forM_ ([-1, 0, 9, 101]) $ \poolGap -> scenario ("addressPoolGap = " ++ show (poolGap :: Int)) $ do + fixture <- setup $ defaultSetup + & rawAddressPoolGap .~ 12 + eowallet <- successfulRequest $ Client.postEosWallet $- NewEosWallet + (NE.fromList $ take 3 $ fixture ^. externallyOwnedAccounts) + noAddressPoolGap + defaultAssuranceLevel + defaultWalletName + + let endpoint = "api/v1/wallets/externally-owned/" <> fromWalletId (eowallet ^. walletId) + response <- unsafeRequest ("PUT", endpoint) $ Just $ [json|{ + "assuranceLevel": "normal", + "addressPoolGap": #{poolGap}, + "name": "My EosWallet" + }|] + verify (response :: Either ClientError EosWallet) + [ expectJSONError $ case poolGap of + -1 -> "Error in $.addressPoolGap: Word8 is either floating or will cause over or underflow: -1.0" + _ -> "Error in $.addressPoolGap: Address pool gap should be in range [10..100]" + ] + + + describe "EOSWALLETS_UPDATE_04 - one has to provide assuranceLevel to be either 'normal' or 'strict'" $ do + let matrix = + [ ( "normal" + , [json| "normal" |] + , [ expectSuccess + , expectFieldEqual assuranceLevel NormalAssurance + ] + ) + , ( "strict" + , [json| "strict" |] + , [ expectSuccess + , expectFieldEqual assuranceLevel StrictAssurance + ] + ) + , ( "empty string" + , [json| "" |] + , [ expectJSONError "Error in $.assuranceLevel: When parsing Cardano.Wallet.API.V1.Types.AssuranceLevel expected a String with the tag of a constructor but got ." ] + ) + , ( "555" + , [json| 555 |] + , [ expectJSONError "Error in $.assuranceLevel: When parsing Cardano.Wallet.API.V1.Types.AssuranceLevel expected String but got Number." ] + ) + , ( "亜哀愛źiemniak悪握圧扱安" + , [json| "亜哀愛źiemniak悪握圧扱安" |] + , [ expectJSONError "Error in $.assuranceLevel: When parsing Cardano.Wallet.API.V1.Types.AssuranceLevel expected a String with the tag of a constructor but got 亜哀愛źiemniak悪握圧扱安" ] + ) + ] + + forM_ matrix $ \(title, assurLevel, expectations) -> scenario ("assuranceLevel = " ++ title) $ do + fixture <- setup $ defaultSetup + & rawAddressPoolGap .~ 12 + eowallet <- successfulRequest $ Client.postEosWallet $- NewEosWallet + (NE.fromList $ take 3 $ fixture ^. externallyOwnedAccounts) + noAddressPoolGap + defaultAssuranceLevel + defaultWalletName + + let endpoint = "api/v1/wallets/externally-owned/" <> fromWalletId (eowallet ^. walletId) + response <- unsafeRequest ("PUT", endpoint) $ Just $ [json|{ + "assuranceLevel": #{assurLevel}, + "addressPoolGap": 10, + "name": "My EosWallet" + }|] + verify (response :: Either ClientError EosWallet) expectations + + describe "EOSWALLETS_UPDATE_05 - one has to provide all required parameters" $ do + + let matrix = + [ ( "no addressPoolGap" + , [json| { "assuranceLevel": "normal", "name": "My EosWallet" } |] + , [ expectJSONError "Error in $: When parsing the record updateEosWallet of type Cardano.Wallet.API.V1.Types.UpdateEosWallet the key addressPoolGap was not present." ] + ) + , ( "no assuranceLevel" + , [json| { "addressPoolGap": 10, "name": "My EosWallet" } |] + , [ expectJSONError "Error in $: When parsing the record updateEosWallet of type Cardano.Wallet.API.V1.Types.UpdateEosWallet the key assuranceLevel was not present." ] + ) + , ( "no name" + , [json| { "addressPoolGap": 10, "assuranceLevel": "normal" } |] + , [ expectJSONError "Error in $: When parsing the record updateEosWallet of type Cardano.Wallet.API.V1.Types.UpdateEosWallet the key name was not present." ] + ) + ] + forM_ matrix $ \(title, payload, expectations) -> scenario title $ do + fixture <- setup $ defaultSetup + & rawAddressPoolGap .~ 12 + eowallet <- successfulRequest $ Client.postEosWallet $- NewEosWallet + (NE.fromList $ take 3 $ fixture ^. externallyOwnedAccounts) + noAddressPoolGap + defaultAssuranceLevel + defaultWalletName + + let endpoint = "api/v1/wallets/externally-owned/" <> fromWalletId (eowallet ^. walletId) + response <- unsafeRequest ("PUT", endpoint) $ Just $ [json| #{payload} |] + verify (response :: Either ClientError EosWallet) expectations where fromWalletId :: Client.WalletId -> Text fromWalletId (Client.WalletId a) = a From 700ec8eaf26a1328762589f5e7049031aaff1086 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 15 Feb 2019 08:59:15 +0100 Subject: [PATCH 06/10] remove redundant fromWalletId method from EosWallets.hs --- test/integration/Test/Integration/Scenario/EosWallets.hs | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/integration/Test/Integration/Scenario/EosWallets.hs b/test/integration/Test/Integration/Scenario/EosWallets.hs index 314bdf3f1..dee7232bb 100644 --- a/test/integration/Test/Integration/Scenario/EosWallets.hs +++ b/test/integration/Test/Integration/Scenario/EosWallets.hs @@ -564,6 +564,3 @@ spec = do let endpoint = "api/v1/wallets/externally-owned/" <> fromWalletId (eowallet ^. walletId) response <- unsafeRequest ("PUT", endpoint) $ Just $ [json| #{payload} |] verify (response :: Either ClientError EosWallet) expectations - where - fromWalletId :: Client.WalletId -> Text - fromWalletId (Client.WalletId a) = a From f5a022b5ba1e3c2d23e6f481063776a94fe8e34b Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 15 Feb 2019 09:23:17 +0100 Subject: [PATCH 07/10] shorten expectJSON error messages not to include module names --- .../Test/Integration/Scenario/EosWallets.hs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/integration/Test/Integration/Scenario/EosWallets.hs b/test/integration/Test/Integration/Scenario/EosWallets.hs index dee7232bb..ba277279b 100644 --- a/test/integration/Test/Integration/Scenario/EosWallets.hs +++ b/test/integration/Test/Integration/Scenario/EosWallets.hs @@ -96,7 +96,7 @@ spec = do "name": "My EOS Wallet" }|] verify (response :: Either ClientError EosWallet) - [ expectJSONError "Error in $.accounts[0]: When parsing the record accountPublicKeyWithIx of type Cardano.Wallet.API.V1.Types.AccountPublicKeyWithIx the key publicKey was not present." + [ expectJSONError "the key publicKey was not present." ] scenario "EOSWALLETS_CREATE_03 - index must be present" $ do @@ -112,7 +112,7 @@ spec = do "name": "My EOS Wallet" }|] verify (response :: Either ClientError EosWallet) - [ expectJSONError "Error in $.accounts[0]: When parsing the record accountPublicKeyWithIx of type Cardano.Wallet.API.V1.Types.AccountPublicKeyWithIx the key index was not present." + [ expectJSONError "the key index was not present." ] describe "EOSWALLETS_CREATE_03 - index must be [2147483648..4294967295]" $ do @@ -173,15 +173,15 @@ spec = do ) , ( "empty string" , [json| "" |] - , [ expectJSONError "Error in $.assuranceLevel: When parsing Cardano.Wallet.API.V1.Types.AssuranceLevel expected a String with the tag of a constructor but got ." ] + , [ expectJSONError "expected a String with the tag of a constructor but got ." ] ) , ( "555" , [json| 555 |] - , [ expectJSONError "Error in $.assuranceLevel: When parsing Cardano.Wallet.API.V1.Types.AssuranceLevel expected String but got Number." ] + , [ expectJSONError "expected String but got Number." ] ) , ( "亜哀愛źiemniak悪握圧扱安" , [json| "亜哀愛źiemniak悪握圧扱安" |] - , [ expectJSONError "Error in $.assuranceLevel: When parsing Cardano.Wallet.API.V1.Types.AssuranceLevel expected a String with the tag of a constructor but got 亜哀愛źiemniak悪握圧扱安" ] + , [ expectJSONError "expected a String with the tag of a constructor but got 亜哀愛źiemniak悪握圧扱安" ] ) ] @@ -208,7 +208,7 @@ spec = do "assuranceLevel": "strict", "name": "Wallet EOS" } |] - , [ expectJSONError "Error in $: When parsing the record newEosWallet of type Cardano.Wallet.API.V1.Types.NewEosWallet the key accounts was not present." ] + , [ expectJSONError "the key accounts was not present." ] ) , ( "no assuranceLevel" , [json| { @@ -221,7 +221,7 @@ spec = do "addressPoolGap": 70, "name": "Wallet EOS" } |] - , [ expectJSONError "Error in $: When parsing the record newEosWallet of type Cardano.Wallet.API.V1.Types.NewEosWallet the key assuranceLevel was not present." ] + , [ expectJSONError "the key assuranceLevel was not present." ] ) , ( "no name" , [json| { @@ -234,7 +234,7 @@ spec = do "addressPoolGap": 70, "assuranceLevel": "strict" } |] - , [ expectJSONError "Error in $: When parsing the record newEosWallet of type Cardano.Wallet.API.V1.Types.NewEosWallet the key name was not present." ] + , [ expectJSONError "the key name was not present." ] ) ] forM_ matrix $ \(title, payload, expectations) -> scenario title $ do @@ -507,15 +507,15 @@ spec = do ) , ( "empty string" , [json| "" |] - , [ expectJSONError "Error in $.assuranceLevel: When parsing Cardano.Wallet.API.V1.Types.AssuranceLevel expected a String with the tag of a constructor but got ." ] + , [ expectJSONError "expected a String with the tag of a constructor but got ." ] ) , ( "555" , [json| 555 |] - , [ expectJSONError "Error in $.assuranceLevel: When parsing Cardano.Wallet.API.V1.Types.AssuranceLevel expected String but got Number." ] + , [ expectJSONError "expected String but got Number." ] ) , ( "亜哀愛źiemniak悪握圧扱安" , [json| "亜哀愛źiemniak悪握圧扱安" |] - , [ expectJSONError "Error in $.assuranceLevel: When parsing Cardano.Wallet.API.V1.Types.AssuranceLevel expected a String with the tag of a constructor but got 亜哀愛źiemniak悪握圧扱安" ] + , [ expectJSONError "expected a String with the tag of a constructor but got 亜哀愛źiemniak悪握圧扱安" ] ) ] @@ -541,15 +541,15 @@ spec = do let matrix = [ ( "no addressPoolGap" , [json| { "assuranceLevel": "normal", "name": "My EosWallet" } |] - , [ expectJSONError "Error in $: When parsing the record updateEosWallet of type Cardano.Wallet.API.V1.Types.UpdateEosWallet the key addressPoolGap was not present." ] + , [ expectJSONError "the key addressPoolGap was not present." ] ) , ( "no assuranceLevel" , [json| { "addressPoolGap": 10, "name": "My EosWallet" } |] - , [ expectJSONError "Error in $: When parsing the record updateEosWallet of type Cardano.Wallet.API.V1.Types.UpdateEosWallet the key assuranceLevel was not present." ] + , [ expectJSONError "the key assuranceLevel was not present." ] ) , ( "no name" , [json| { "addressPoolGap": 10, "assuranceLevel": "normal" } |] - , [ expectJSONError "Error in $: When parsing the record updateEosWallet of type Cardano.Wallet.API.V1.Types.UpdateEosWallet the key name was not present." ] + , [ expectJSONError "the key name was not present." ] ) ] forM_ matrix $ \(title, payload, expectations) -> scenario title $ do From 992dfcb1cb93dedbc85d4c4d4178465e5c2ae46a Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 15 Feb 2019 10:33:09 +0100 Subject: [PATCH 08/10] set pendingWith on test 'EOSWALLETS_LIST_01, EOSWALLETS_LIST_02 - cannot get FO wallets with EOS endpoint' --- test/integration/Test/Integration/Scenario/EosWallets.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/integration/Test/Integration/Scenario/EosWallets.hs b/test/integration/Test/Integration/Scenario/EosWallets.hs index ba277279b..9ed91f501 100644 --- a/test/integration/Test/Integration/Scenario/EosWallets.hs +++ b/test/integration/Test/Integration/Scenario/EosWallets.hs @@ -377,6 +377,7 @@ spec = do ] scenario "EOSWALLETS_LIST_01, EOSWALLETS_LIST_02 - cannot get FO wallets with EOS endpoint" $ do + pendingWith "This test is failing due to broken Client.getEosWalletIndexFilterSorts endpoint (#336)" fixture <- setup defaultSetup eowallet <- successfulRequest $ Client.postEosWallet $- NewEosWallet (NE.fromList $ take 3 $ fixture ^. externallyOwnedAccounts) From 311f6ebfccb255f922388fd0f24b33b43f43510d Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Fri, 15 Feb 2019 19:00:11 +0100 Subject: [PATCH 09/10] hlint --- test/integration/Test/Integration/Scenario/EosWallets.hs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/integration/Test/Integration/Scenario/EosWallets.hs b/test/integration/Test/Integration/Scenario/EosWallets.hs index 9ed91f501..b904ce70f 100644 --- a/test/integration/Test/Integration/Scenario/EosWallets.hs +++ b/test/integration/Test/Integration/Scenario/EosWallets.hs @@ -472,7 +472,6 @@ spec = do describe "EOSWALLETS_UPDATE_03 - addressPoolGap cannot be outside [10..100]" $ do forM_ ([-1, 0, 9, 101]) $ \poolGap -> scenario ("addressPoolGap = " ++ show (poolGap :: Int)) $ do fixture <- setup $ defaultSetup - & rawAddressPoolGap .~ 12 eowallet <- successfulRequest $ Client.postEosWallet $- NewEosWallet (NE.fromList $ take 3 $ fixture ^. externallyOwnedAccounts) noAddressPoolGap @@ -522,9 +521,8 @@ spec = do forM_ matrix $ \(title, assurLevel, expectations) -> scenario ("assuranceLevel = " ++ title) $ do fixture <- setup $ defaultSetup - & rawAddressPoolGap .~ 12 eowallet <- successfulRequest $ Client.postEosWallet $- NewEosWallet - (NE.fromList $ take 3 $ fixture ^. externallyOwnedAccounts) + (NE.fromList $ take 5 $ fixture ^. externallyOwnedAccounts) noAddressPoolGap defaultAssuranceLevel defaultWalletName From ba1c705c737f7fc6eed36d252806015239081774 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Mon, 18 Feb 2019 10:01:39 +0100 Subject: [PATCH 10/10] stylish haskell --- test/integration/Test/Integration/Scenario/EosWallets.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/integration/Test/Integration/Scenario/EosWallets.hs b/test/integration/Test/Integration/Scenario/EosWallets.hs index b904ce70f..8879bca3a 100644 --- a/test/integration/Test/Integration/Scenario/EosWallets.hs +++ b/test/integration/Test/Integration/Scenario/EosWallets.hs @@ -8,11 +8,12 @@ import Universum import qualified Data.List.NonEmpty as NE +import Cardano.Wallet.API.V1.Types import Cardano.Wallet.Client.Http (ClientError, Wallet) import qualified Cardano.Wallet.Client.Http as Client import Test.Hspec (describe) import Test.Integration.Framework.DSL -import Cardano.Wallet.API.V1.Types + spec :: Scenarios Context spec = do