From 3ed89c66064526e366db46f25608089ebcd69e1e Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Mon, 3 Jun 2019 11:17:21 +0200 Subject: [PATCH 1/4] map existing tests to requirements --- .../Integration/Scenario/CLI/Addresses.hs | 3 +- .../Integration/Scenario/CLI/Mnemonics.hs | 16 +++++----- .../Integration/Scenario/CLI/Transactions.hs | 3 +- .../Test/Integration/Scenario/CLI/Wallets.hs | 30 +++++++++---------- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Addresses.hs b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Addresses.hs index d426f9c3521..678f9afee48 100644 --- a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Addresses.hs +++ b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Addresses.hs @@ -37,7 +37,8 @@ import qualified Data.Text as T spec :: forall t. (DecodeAddress t) => SpecWith (Context t) spec = do - it "CLI - Can list addresses" $ \ctx -> do + + it "ADDRESS_LIST_01 - Can list addresses" $ \ctx -> do walId <- emptyWallet' ctx (Exit c, Stdout out, Stderr err) <- listAddressesViaCLI walId err `shouldBe` "Ok.\n" diff --git a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Mnemonics.hs b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Mnemonics.hs index 2d89c86abc0..f789342d115 100644 --- a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Mnemonics.hs +++ b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Mnemonics.hs @@ -31,42 +31,42 @@ version = "2019.5.24" spec :: SpecWith () spec = do - it "CLI - Shows version" $ do + it "CLI_VERSION - Shows version" $ do (Exit c, Stdout out) <- cardanoWalletCLI ["--version"] let v = T.dropWhileEnd (== '\n') (T.pack out) v `shouldBe` version c `shouldBe` ExitSuccess - it "CLI - cardano-wallet-launcher shows help on bad argument" $ do + it "CLI_HELP - cardano-wallet-launcher shows help on bad argument" $ do (Exit c, Stdout out) <- cardanoWalletLauncherCLI ["--bad arg"] out `shouldContain` "cardano-wallet-launcher" c `shouldBe` ExitFailure 1 - describe "CLI - cardano-wallet-launcher shows help with" $ do + describe "CLI_HELP - cardano-wallet-launcher shows help with" $ do let test option = it option $ do (Exit c, Stdout out) <- cardanoWalletLauncherCLI [option] out `shouldContain` "cardano-wallet-launcher" c `shouldBe` ExitSuccess forM_ ["-h", "--help"] test - it "CLI - cardano-wallet shows help on bad argument" $ do + it "CLI_HELP - cardano-wallet shows help on bad argument" $ do (Exit c, Stdout out) <- cardanoWalletCLI ["--bad arg"] out `shouldContain` "Cardano Wallet CLI" c `shouldBe` ExitFailure 1 - describe "CLI - cardano-wallet shows help with" $ do + describe "CLI_HELP - cardano-wallet shows help with" $ do let test option = it option $ do (Exit c, Stdout out) <- cardanoWalletCLI [option] out `shouldContain` "Cardano Wallet CLI" c `shouldBe` ExitSuccess forM_ ["-h", "--help"] test - it "MNEMONICS - Can generate mnemonics with default size" $ do + it "CLI_MNEMONICS_01 - Can generate mnemonics with default size" $ do (Exit c, Stdout out) <- generateMnemonicsViaCLI [] length (words out) `shouldBe` 15 c `shouldBe` ExitSuccess - describe "MNEMONICS - Can generate mnemonics with different sizes" $ do + describe "CLI_MNEMONICS_01 - Can generate mnemonics with different sizes" $ do let test size = it ("--size=" <> show size) $ do (Exit c, Stdout out) <- generateMnemonicsViaCLI ["--size", show size] @@ -74,7 +74,7 @@ spec = do c `shouldBe` ExitSuccess forM_ [9, 12, 15, 18, 21, 24] test - describe "MNEMONICS - It can't generate mnemonics with an invalid size" $ do + describe "CLI_MNEMONICS_02 - It can't generate mnemonics with an invalid size" $ do let sizes = ["15.5", "3", "6", "14", "abc", "👌", "0", "~!@#%" , "-1000", "1000"] forM_ sizes $ \(size) -> it ("--size=" <> size) $ do diff --git a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Transactions.hs b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Transactions.hs index c23c085d8e7..ca9755221aa 100644 --- a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Transactions.hs +++ b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Transactions.hs @@ -39,7 +39,8 @@ import qualified Data.Text as T spec :: forall t. (EncodeAddress t, DecodeAddress t) => SpecWith (Context t) spec = do - it "CLI - Can create transaction" $ \ctx -> do + + it "TRANS_CREATE_01 - Can create transaction" $ \ctx -> do wSrc <- fixtureWallet ctx wDest <- emptyWallet ctx (_, addr:_) <- unsafeRequest @[ApiAddress t] ctx (getAddresses wDest) Empty diff --git a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Wallets.hs b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Wallets.hs index e0b4a4dce4a..33a9fef72c9 100644 --- a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Wallets.hs +++ b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Wallets.hs @@ -45,7 +45,7 @@ import qualified Data.Text as T spec :: SpecWith (Context t) spec = do - describe "CLI1 - Can create wallet with different mnemonic sizes" $ do + describe "WALLETS_CREATE_05 - Can create wallet with different mnemonic sizes" $ do forM_ ["15", "18", "21", "24"] $ \(size) -> it size $ \_ -> do let walletName = "Wallet created via CLI" Stdout mnemonics <- generateMnemonicsViaCLI ["--size", size] @@ -57,33 +57,33 @@ spec = do Stdout outList <- listWalletsViaCLI outList `shouldContain` walletName - describe "CLI1 - Can create wallet with different mnemonic snd factor sizes" $ do + describe "WALLETS_CREATE_05 - Can't create wallet with wrong size of mnemonic" $ do forM_ ["9", "12"] $ \(size) -> it size $ \_ -> do let walletName = "Wallet created via CLI" - Stdout mnemonics <- generateMnemonicsViaCLI [] + Stdout mnemonics <- generateMnemonicsViaCLI ["--size", size] Stdout mnemonics2 <- generateMnemonicsViaCLI ["--size", size] let passphrase = "Secure passphrase" c <- createWalletViaCLI [walletName] mnemonics mnemonics2 passphrase - c `shouldBe` ExitSuccess + c `shouldBe` (ExitFailure 1) Stdout outList <- listWalletsViaCLI - outList `shouldContain` walletName + outList `shouldNotContain` walletName - describe "CLI1 - Can't create wallet with wrong size of mnemonic" $ do + describe "WALLETS_CREATE_06 - Can create wallet with different mnemonic snd factor sizes" $ do forM_ ["9", "12"] $ \(size) -> it size $ \_ -> do let walletName = "Wallet created via CLI" - Stdout mnemonics <- generateMnemonicsViaCLI ["--size", size] + Stdout mnemonics <- generateMnemonicsViaCLI [] Stdout mnemonics2 <- generateMnemonicsViaCLI ["--size", size] let passphrase = "Secure passphrase" c <- createWalletViaCLI [walletName] mnemonics mnemonics2 passphrase - c `shouldBe` (ExitFailure 1) + c `shouldBe` ExitSuccess Stdout outList <- listWalletsViaCLI - outList `shouldNotContain` walletName + outList `shouldContain` walletName - describe "CLI1 - Can't create wallet with wrong size of mnemonic snd factor" $ do + describe "WALLETS_CREATE_06 - Can't create wallet with wrong size of mnemonic snd factor" $ do forM_ ["15", "18", "21", "24"] $ \(size) -> it size $ \_ -> do let walletName = "Wallet created via CLI" Stdout mnemonics <- generateMnemonicsViaCLI ["--size", size] @@ -96,7 +96,7 @@ spec = do Stdout outList <- listWalletsViaCLI outList `shouldNotContain` walletName - it "CLI - Can get a wallet" $ \ctx -> do + it "WALLETS_GET_01 - Can get a wallet" $ \ctx -> do walId <- emptyWallet' ctx (Exit c, Stdout out, Stderr err) <- getWalletViaCLI walId err `shouldBe` "Ok.\n" @@ -104,7 +104,7 @@ spec = do out `shouldContain` "Empty Wallet" c `shouldBe` ExitSuccess - describe "CLI - Cannot get wallets with false ids" $ do + describe "WALLETS_GET_03,04 - Cannot get wallets with false ids" $ do forM_ falseWalletIds $ \(title, walId) -> it title $ \_ -> do (Exit c, Stdout out, Stderr err) <- getWalletViaCLI walId out `shouldBe` "" @@ -120,7 +120,7 @@ spec = do else c `shouldBe` ExitFailure 1 - it "CLI - Can list wallets" $ \ctx -> do + it "WALLETS_LIST_01 - Can list wallets" $ \ctx -> do emptyWallet' ctx $> () <* emptyWallet' ctx (Exit c, Stdout out, Stderr err) <- listWalletsViaCLI err `shouldBe` "Ok.\n" @@ -128,7 +128,7 @@ spec = do out `shouldContain` "Empty Wallet" c `shouldBe` ExitSuccess - it "CLI - Can update wallet name" $ \ctx -> do + it "WALLETS_UPDATE_01 - Can update wallet name" $ \ctx -> do walId <- emptyWallet' ctx let args = [walId, "--name", "new name"] (Exit c, Stdout out, Stderr err) <- updateWalletViaCLI args @@ -137,7 +137,7 @@ spec = do out `shouldContain` "new name" c `shouldBe` ExitSuccess - it "CLI - Can delete wallet" $ \ctx -> do + it "WALLETS_DELETE_01 - Can delete wallet" $ \ctx -> do walId <- emptyWallet' ctx (Exit c, Stdout out, Stderr err) <- deleteWalletViaCLI walId err `shouldBe` "Ok.\n" From 0bbab9dbdf225fe9b455d7228da9fbd07af74fd6 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Mon, 3 Jun 2019 12:04:22 +0200 Subject: [PATCH 2/4] Make cardano-wallet-launcher to show version as cardano-wallet for consistency --- cardano-wallet.cabal | 2 -- exe/launcher/Main.hs | 4 ++- exe/wallet/Main.hs | 19 ++------------ lib/cli/cardano-wallet-cli.cabal | 3 +++ lib/cli/src/Cardano/CLI.hs | 25 +++++++++++++++++++ .../Integration/Scenario/CLI/Mnemonics.hs | 8 +++++- 6 files changed, 40 insertions(+), 21 deletions(-) diff --git a/cardano-wallet.cabal b/cardano-wallet.cabal index 068b9ae12e9..16a4cd2e886 100644 --- a/cardano-wallet.cabal +++ b/cardano-wallet.cabal @@ -38,9 +38,7 @@ executable cardano-wallet , cardano-wallet-core , cardano-wallet-http-bridge , docopt - , file-embed , http-client - , regex-applicative , servant-client , servant-client-core , servant-server diff --git a/exe/launcher/Main.hs b/exe/launcher/Main.hs index 3b76595ab95..33e0a2e147a 100644 --- a/exe/launcher/Main.hs +++ b/exe/launcher/Main.hs @@ -6,7 +6,7 @@ module Main where import Prelude import Cardano.CLI - ( Port, help, parseArgWith ) + ( Port, help, parseArgWith, showVersion ) import Cardano.Launcher ( Command (Command) , ProcessHasExited (ProcessHasExited) @@ -59,6 +59,7 @@ in the directory. Usage: cardano-wallet-launcher [options] cardano-wallet-launcher -h | --help + cardano-wallet-launcher --version Options: --network testnet, staging, or mainnet [default: testnet] @@ -71,6 +72,7 @@ main = do args <- parseArgsOrExit cli =<< getArgs when (args `isPresent` (longOption "help")) $ help cli when (args `isPresent` (shortOption 'h')) $ help cli + when (args `isPresent` (longOption "version")) showVersion network <- args `parseArg` longOption "network" bridgePort <- args `parseArg` longOption "http-bridge-port" diff --git a/exe/wallet/Main.hs b/exe/wallet/Main.hs index 5e5245effff..095adc4dba4 100644 --- a/exe/wallet/Main.hs +++ b/exe/wallet/Main.hs @@ -6,7 +6,6 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeOperators #-} @@ -35,6 +34,7 @@ import Cardano.CLI , parseArgWith , putErrLn , setUtf8Encoding + , showVersion ) import Cardano.Wallet ( newWalletLayer ) @@ -67,8 +67,6 @@ import Control.Monad ( when ) import Data.Aeson ( (.:) ) -import Data.FileEmbed - ( embedFile ) import Data.Function ( (&) ) import Data.Functor @@ -109,8 +107,6 @@ import System.Exit ( exitFailure ) import System.IO ( BufferMode (NoBuffering), hSetBuffering, stderr, stdout ) -import Text.Regex.Applicative - ( anySym, few, match, string, sym ) import qualified Cardano.Wallet.Api.Server as Server import qualified Cardano.Wallet.DB.MVar as MVar @@ -119,7 +115,6 @@ import qualified Cardano.Wallet.HttpBridge.Transaction as HttpBridge import qualified Data.Aeson as Aeson import qualified Data.Aeson.Encode.Pretty as Aeson import qualified Data.Aeson.Types as Aeson -import qualified Data.ByteString.Char8 as B8 import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Lazy.Char8 as BL8 import qualified Data.Text as T @@ -267,17 +262,7 @@ exec execServer manager args wId <- args `parseArg` argument "wallet-id" runClient Aeson.encodePretty $ listAddresses (ApiT wId) Nothing - | args `isPresent` longOption "version" = do - let cabal = B8.unpack $(embedFile "cardano-wallet.cabal") - let re = few anySym - *> string "version:" *> many (sym ' ') *> few anySym - <* sym '\n' <* many anySym - case match re cabal of - Nothing -> do - putErrLn "Couldn't find program version!" - exitFailure - Just version -> do - TIO.putStrLn $ T.pack version + | args `isPresent` longOption "version" = showVersion | otherwise = exitWithUsage cli diff --git a/lib/cli/cardano-wallet-cli.cabal b/lib/cli/cardano-wallet-cli.cabal index 0c50c306534..62668156dd7 100644 --- a/lib/cli/cardano-wallet-cli.cabal +++ b/lib/cli/cardano-wallet-cli.cabal @@ -31,9 +31,12 @@ library -Werror build-depends: base + , bytestring , ansi-terminal , docopt + , file-embed , fmt + , regex-applicative , text , text-class hs-source-dirs: diff --git a/lib/cli/src/Cardano/CLI.hs b/lib/cli/src/Cardano/CLI.hs index 18d6e53a237..c4e978d9683 100644 --- a/lib/cli/src/Cardano/CLI.hs +++ b/lib/cli/src/Cardano/CLI.hs @@ -4,6 +4,7 @@ {-# LANGUAGE KindSignatures #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE TemplateHaskell #-} -- | -- Copyright: © 2018-2019 IOHK @@ -33,13 +34,20 @@ module Cardano.CLI , hGetLine , getSensitiveLine , hGetSensitiveLine + + -- * Show version + , showVersion ) where import Prelude hiding ( getLine ) +import Control.Applicative + ( many ) import Control.Exception ( bracket ) +import Data.FileEmbed + ( embedFile ) import Data.Functor ( (<$) ) import qualified Data.List.NonEmpty as NE @@ -88,7 +96,10 @@ import System.IO , stdout , utf8 ) +import Text.Regex.Applicative + ( anySym, few, match, string, sym ) +import qualified Data.ByteString.Char8 as B8 import qualified Data.Text as T import qualified Data.Text.IO as TIO @@ -259,6 +270,20 @@ getSensitiveLine = hGetSensitiveLine (stdin, stderr) Internals -------------------------------------------------------------------------------} +showVersion :: IO () +showVersion = do + let cabal = B8.unpack $(embedFile "../../cardano-wallet.cabal") + let re = few anySym + *> string "version:" *> many (sym ' ') *> few anySym + <* sym '\n' <* many anySym + case match re cabal of + Nothing -> do + putErrLn "Couldn't find program version!" + exitFailure + Just version -> do + TIO.putStrLn $ T.pack version + exitSuccess + withBuffering :: Handle -> BufferMode -> IO a -> IO a withBuffering h buffering action = bracket aFirst aLast aBetween where diff --git a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Mnemonics.hs b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Mnemonics.hs index f789342d115..15b89fd27c4 100644 --- a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Mnemonics.hs +++ b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Mnemonics.hs @@ -31,12 +31,18 @@ version = "2019.5.24" spec :: SpecWith () spec = do - it "CLI_VERSION - Shows version" $ do + it "CLI_VERSION - cardano-wallet shows version" $ do (Exit c, Stdout out) <- cardanoWalletCLI ["--version"] let v = T.dropWhileEnd (== '\n') (T.pack out) v `shouldBe` version c `shouldBe` ExitSuccess + it "CLI_VERSION - cardano-wallet-launcher shows version" $ do + (Exit c, Stdout out) <- cardanoWalletLauncherCLI ["--version"] + let v = T.dropWhileEnd (== '\n') (T.pack out) + v `shouldBe` version + c `shouldBe` ExitSuccess + it "CLI_HELP - cardano-wallet-launcher shows help on bad argument" $ do (Exit c, Stdout out) <- cardanoWalletLauncherCLI ["--bad arg"] out `shouldContain` "cardano-wallet-launcher" From 900765aaa94dce5b1f3eb8cf0facda4515f1e682 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Tue, 4 Jun 2019 18:10:28 +0200 Subject: [PATCH 3/4] Transaction tests via CLI --- .../Test/Integration/Framework/DSL.hs | 66 ++- .../Test/Integration/Framework/TestData.hs | 27 ++ .../Integration/Scenario/API/Transactions.hs | 28 +- .../Integration/Scenario/CLI/Transactions.hs | 410 +++++++++++++++++- .../Test/Integration/Scenario/CLI/Wallets.hs | 6 +- 5 files changed, 497 insertions(+), 40 deletions(-) diff --git a/lib/http-bridge/test/integration/Test/Integration/Framework/DSL.hs b/lib/http-bridge/test/integration/Test/Integration/Framework/DSL.hs index bb603a80451..e55cc09a124 100644 --- a/lib/http-bridge/test/integration/Test/Integration/Framework/DSL.hs +++ b/lib/http-bridge/test/integration/Test/Integration/Framework/DSL.hs @@ -29,7 +29,10 @@ module Test.Integration.Framework.DSL , expectListSizeEqual , expectResponseCode , expectEventually + , expectEventually' , expectValidJSON + , expectCliFieldBetween + , expectCliFieldEqual , verify , Headers(..) , Payload(..) @@ -184,6 +187,9 @@ import qualified Data.Text as T import qualified Data.Text.IO as TIO import qualified Network.HTTP.Types.Status as HTTP +-- +-- API response expectations +-- -- | Expect an errored response, without any further assumptions expectError @@ -306,7 +312,6 @@ expectEventually expectEventually ctx getter target (_, res) = case res of Left e -> wantedSuccessButError e Right s -> loopUntilRestore (s ^. walletId) - where loopUntilRestore :: (MonadIO m, MonadCatch m) => Text -> m () loopUntilRestore wid = do @@ -314,17 +319,70 @@ expectEventually ctx getter target (_, res) = case res of let target' = getFromResponse getter r unless (target' >= target) $ loopUntilRestore wid +expectEventually' + :: (MonadIO m, MonadCatch m, MonadFail m, Ord a) + => Context + -> Lens' ApiWallet a + -> a + -> ApiWallet + -> m () +expectEventually' ctx target value wallet = do + rb <- request @ApiWallet ctx (getWallet wallet) Default Empty + expectEventually ctx target value rb +-- +-- CLI output expectations +-- + -- | Expects a given string to be a valid JSON output corresponding to some --- given data-type 'a' +-- given data-type 'a'. Returns this type if successful. expectValidJSON :: forall m a. (MonadFail m, FromJSON a) => Proxy a -> String - -> m () + -> m a expectValidJSON _ str = case Aeson.eitherDecode @a (BL8.pack str) of Left e -> fail $ "expected valid JSON but failed decoding: " <> show e - Right _ -> return () + Right a -> return a + +-- | Expects wallet from the request to eventually reach the given state or +-- beyond +-- expectCliEventually +-- :: (MonadIO m, MonadCatch m, MonadFail m, Ord a) +-- => Lens' ApiWallet a +-- -> a +-- -> ApiWallet +-- -> m () +-- expectCliEventually getter target w = loopUntilRestore (w ^. walletId) +-- where +-- loopUntilRestore :: (MonadIO m, MonadCatch m) => Text -> IO () +-- loopUntilRestore wid = do +-- Stdout out <- getWalletViaCLI (T.unpack wid) +-- outJson <- expectValidJSON (Proxy @ApiWallet) out +-- let target' = view getter outJson +-- unless (target' >= target) $ loopUntilRestore wid + +expectCliFieldBetween + :: (MonadIO m, MonadFail m, Show a, Ord a) + => Lens' s a + -> (a, a) + -> s + -> m () +expectCliFieldBetween getter (aMin, aMax) s = case view getter s of + a | a < aMin -> fail $ + "expected " <> show a <> " >= " <> show aMin + a | a > aMax -> fail $ + "expected " <> show a <> " <= " <> show aMax + _ -> + return () + +expectCliFieldEqual + :: (MonadIO m, MonadFail m, Show a, Eq a) + => Lens' s a + -> a + -> s + -> m () +expectCliFieldEqual getter a out = (view getter out) `shouldBe` a -- | Apply 'a' to all actions in sequence verify :: (Monad m) => a -> [a -> m ()] -> m () diff --git a/lib/http-bridge/test/integration/Test/Integration/Framework/TestData.hs b/lib/http-bridge/test/integration/Test/Integration/Framework/TestData.hs index fd28672b680..e1ea047e76e 100644 --- a/lib/http-bridge/test/integration/Test/Integration/Framework/TestData.hs +++ b/lib/http-bridge/test/integration/Test/Integration/Framework/TestData.hs @@ -40,6 +40,9 @@ module Test.Integration.Framework.TestData , updatePassPayload -- * Error messages + , errMsg403Fee + , errMsg403NotEnoughMoney + , errMsg403UTxO , errMsg403WrongPass , errMsg404NoEndpoint , errMsg404NoRootKey @@ -47,6 +50,7 @@ module Test.Integration.Framework.TestData , errMsg405 , errMsg406 , errMsg415 + , errMsg500 ) where import Prelude @@ -204,6 +208,23 @@ updatePassPayload oldPass newPass = Json [json| { --- --- Error messages --- +errMsg403Fee :: String +errMsg403Fee = "I'm unable to adjust the given transaction to cover the\ + \ associated fee! In order to do so, I'd have to select one or\ + \ more additional inputs, but I can't do that without increasing\ + \ the size of the transaction beyond the acceptable limit." + +errMsg403NotEnoughMoney :: Int -> Int -> String +errMsg403NotEnoughMoney has needs = "I can't process this payment because there's\ + \ not enough UTxO available in the wallet. The total UTxO sums up to\ + \ " ++ show has ++ " Lovelace, but I need " ++ show needs ++ " Lovelace\ + \ (excluding fee amount) in order to proceed with the payment." + +errMsg403UTxO :: String +errMsg403UTxO = "When creating new transactions, I'm not able to re-use the\ + \ same UTxO for different outputs. Here, I only have 1\ + \ available, but there are 2 outputs." + errMsg403WrongPass :: String errMsg403WrongPass = "The given encryption passphrase doesn't match the one\ \ I use to encrypt the root private key of the given wallet" @@ -238,3 +259,9 @@ errMsg415 = "I'm really sorry but I only understand 'application/json'. I need\ \ you to tell me what language you're speaking in order for me to understand\ \ your message. Please double-check your 'Content-Type' request header and\ \ make sure it's set to 'application/json'" + +errMsg500 :: String +errMsg500 = "That's embarassing. It looks like I've created an invalid\ + \ transaction that could not be parsed by the node. Here's an error\ + \ message that may help with debugging: Transaction failed verification:\ + \ output with no credited value" diff --git a/lib/http-bridge/test/integration/Test/Integration/Scenario/API/Transactions.hs b/lib/http-bridge/test/integration/Test/Integration/Scenario/API/Transactions.hs index 7ddcfef97be..0e13da1ff83 100644 --- a/lib/http-bridge/test/integration/Test/Integration/Scenario/API/Transactions.hs +++ b/lib/http-bridge/test/integration/Test/Integration/Scenario/API/Transactions.hs @@ -52,12 +52,16 @@ import Test.Integration.Framework.DSL ) import Test.Integration.Framework.TestData ( arabicWalletName + , errMsg403Fee + , errMsg403NotEnoughMoney + , errMsg403UTxO , errMsg403WrongPass , errMsg404NoEndpoint , errMsg404NoWallet , errMsg405 , errMsg406 , errMsg415 + , errMsg500 , falseWalletIds , kanjiWalletName , polishWalletName @@ -252,10 +256,7 @@ spec = do r <- request @(ApiTransaction t) ctx (postTx wSrc) Default payload verify r [ expectResponseCode HTTP.status403 - , expectErrorMessage - "When creating new transactions, I'm not able to re-use the \ - \same UTxO for different outputs. Here, I only have 1 \ - \available, but there are 2 outputs." + , expectErrorMessage errMsg403UTxO ] it "TRANS_CREATE_03 - 0 balance after transaction" $ \ctx -> do @@ -319,11 +320,7 @@ spec = do r <- request @(ApiTransaction t) ctx (postTx wSrc) Default payload verify r [ expectResponseCode HTTP.status403 - , expectErrorMessage - "I'm unable to adjust the given transaction to cover the \ - \associated fee! In order to do so, I'd have to select one or \ - \more additional inputs, but I can't do that without increasing \ - \the size of the transaction beyond the acceptable limit." + , expectErrorMessage errMsg403Fee ] it "TRANS_CREATE_04 - Not enough money" $ \ctx -> do @@ -345,11 +342,7 @@ spec = do r <- request @(ApiTransaction t) ctx (postTx wSrc) Default payload verify r [ expectResponseCode HTTP.status403 - , expectErrorMessage - "I can't process this payment because there's not enough \ - \UTxO available in the wallet. The total UTxO sums up to \ - \100000 Lovelace, but I need 1000000 Lovelace (excluding fee \ - \amount) in order to proceed with the payment." + , expectErrorMessage (errMsg403NotEnoughMoney 100_000 1000_000) ] it "TRANS_CREATE_04 - Wrong password" $ \ctx -> do @@ -466,12 +459,7 @@ spec = do [ ( "Quantity = 0" , [json|{"quantity": 0, "unit": "lovelace"}|] , [ expectResponseCode HTTP.status500 - , expectErrorMessage "That's embarassing. It looks\ - \ like I've created an invalid transaction that\ - \ could not be parsed by the node. Here's an error\ - \ message that may help with debugging:\ - \ Transaction failed verification: output with no\ - \ credited value" ] + , expectErrorMessage errMsg500 ] -- TODO change after #364 ) , ( "Quantity = 1.5" , [json|{"quantity": 1.5, "unit": "lovelace"}|] diff --git a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Transactions.hs b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Transactions.hs index ca9755221aa..8ca243142cf 100644 --- a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Transactions.hs +++ b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Transactions.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DataKinds #-} +{-# LANGUAGE NumericUnderscores #-} {-# LANGUAGE OverloadedLabels #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} @@ -12,45 +13,428 @@ import Prelude import Cardano.Wallet.Api.Types ( ApiAddress, ApiTransaction, getApiT ) import Cardano.Wallet.Primitive.Types - ( DecodeAddress (..), EncodeAddress (..) ) + ( DecodeAddress (..) + , EncodeAddress (..) + , Direction (..) + , TxStatus (..) + , encodeAddress + ) +import Control.Monad + ( forM_ ) import Data.Generics.Internal.VL.Lens ( (^.) ) import Data.Proxy ( Proxy (..) ) +import qualified Data.Text as T +import System.Command + ( Exit (..), Stdout (..) ) import System.Exit ( ExitCode (..) ) import Test.Hspec - ( SpecWith, it ) + ( SpecWith, describe, it ) import Test.Hspec.Expectations.Lifted - ( shouldBe ) + ( shouldBe, shouldContain ) import Test.Integration.Framework.DSL ( Context (..) - , Payload (..) + , amount + , balanceAvailable + , balanceTotal + , deleteWalletViaCLI + , direction , emptyWallet + , expectCliFieldBetween + , expectCliFieldEqual + , expectEventually' , expectValidJSON + , faucetAmt + , faucetUtxoAmt , fixtureWallet - , getAddresses + , fixtureWalletWith + , getWalletViaCLI + , listAddresses , postTransactionViaCLI - , unsafeRequest + , status + , verify , walletId ) - -import qualified Data.Text as T +import Test.Integration.Framework.TestData + ( arabicWalletName + , errMsg403Fee + , errMsg403NotEnoughMoney + , errMsg403UTxO + , errMsg403WrongPass + , errMsg500 + , falseWalletIds + , kanjiWalletName + , polishWalletName + , wildcardsWalletName + ) spec :: forall t. (EncodeAddress t, DecodeAddress t) => SpecWith (Context t) spec = do - - it "TRANS_CREATE_01 - Can create transaction" $ \ctx -> do + it "TRANS_CREATE_01 - Can create transaction via CLI" $ \ctx -> do wSrc <- fixtureWallet ctx wDest <- emptyWallet ctx - (_, addr:_) <- unsafeRequest @[ApiAddress t] ctx (getAddresses wDest) Empty + addr:_ <- listAddresses ctx wDest let addrStr = encodeAddress (Proxy @t) (getApiT $ fst $ addr ^. #id) + let amt = 14 + let (feeMin, feeMax) = (168609, 168785) let args = T.unpack <$> [ wSrc ^. walletId - , "--payment", "14@" <> addrStr + , "--payment", T.pack (show amt) <> "@" <> addrStr ] + + -- post transaction (c, out, err) <- postTransactionViaCLI "cardano-wallet" args err `shouldBe` "Please enter a passphrase: **************\nOk.\n" - expectValidJSON (Proxy @(ApiTransaction t)) out + txJson <- expectValidJSON (Proxy @(ApiTransaction t)) out + verify txJson + [ expectCliFieldBetween amount (feeMin + amt, feeMax + amt) + , expectCliFieldEqual direction Outgoing + , expectCliFieldEqual status Pending + ] + c `shouldBe` ExitSuccess + + -- verify balance on src wallet + Stdout gOutSrc <- getWalletViaCLI (T.unpack (wSrc ^. walletId)) + gJson <- expectValidJSON (Proxy @ApiWallet) gOutSrc + verify gJson + [ expectCliFieldBetween balanceTotal + ( faucetAmt - feeMax - amt + , faucetAmt - feeMin - amt + ) + , expectCliFieldEqual balanceAvailable (faucetAmt - faucetUtxoAmt) + ] + + expectEventually' ctx balanceAvailable amt wDest + expectEventually' ctx balanceTotal amt wDest + + -- verify balance on dest wallet + Stdout gOutDest <- getWalletViaCLI (T.unpack (wDest ^. walletId)) + destJson <- expectValidJSON (Proxy @ApiWallet) gOutDest + verify destJson + [ expectCliFieldEqual balanceAvailable amt + , expectCliFieldEqual balanceTotal amt + ] + + it "TRANS_CREATE_02 - Multiple Output Tx to single wallet via CLI" $ \ctx -> do + wSrc <- fixtureWallet ctx + wDest <- emptyWallet ctx + addr <- listAddresses ctx wDest + let addr1 = + encodeAddress (Proxy @t) (getApiT $ fst $ addr !! 1 ^. #id) + let addr2 = + encodeAddress (Proxy @t) (getApiT $ fst $ addr !! 2 ^. #id) + let amt = 14 + let (feeMin, feeMax) = (181487, 181839) + let args = T.unpack <$> + [ wSrc ^. walletId + , "--payment", T.pack (show amt) <> "@" <> addr1 + , "--payment", T.pack (show amt) <> "@" <> addr2 + ] + + -- post transaction + (c, out, err) <- postTransactionViaCLI "cardano-wallet" args + err `shouldBe` "Please enter a passphrase: **************\nOk.\n" + txJson <- expectValidJSON (Proxy @(ApiTransaction t)) out + verify txJson + [ expectCliFieldBetween amount (feeMin + amt, feeMax + amt) + , expectCliFieldEqual direction Outgoing + , expectCliFieldEqual status Pending + ] + c `shouldBe` ExitSuccess + + -- verify balance on src wallet + Stdout gOutSrc <- getWalletViaCLI (T.unpack (wSrc ^. walletId)) + gJson <- expectValidJSON (Proxy @ApiWallet) gOutSrc + verify gJson + [ expectCliFieldBetween balanceTotal + ( faucetAmt - feeMax - amt + , faucetAmt - feeMin - amt + ) + , expectCliFieldEqual balanceAvailable (faucetAmt - 2*faucetUtxoAmt) + ] + + expectEventually' ctx balanceAvailable (2*amt) wDest + expectEventually' ctx balanceTotal (2*amt) wDest + + -- verify balance on dest wallet + Stdout gOutDest <- getWalletViaCLI (T.unpack (wDest ^. walletId)) + destJson <- expectValidJSON (Proxy @ApiWallet) gOutDest + verify destJson + [ expectCliFieldEqual balanceAvailable (2*amt) + , expectCliFieldEqual balanceTotal (2*amt) + ] + + it "TRANS_CREATE_02 - Multiple Output Tx to different wallets via CLI" $ \ctx -> do + wSrc <- fixtureWallet ctx + wDest1 <- emptyWallet ctx + wDest2 <- emptyWallet ctx + addr1:_ <- listAddresses ctx wDest1 + addr2:_ <- listAddresses ctx wDest2 + let addr1' = + encodeAddress (Proxy @t) (getApiT $ fst $ addr1 ^. #id) + let addr2' = + encodeAddress (Proxy @t) (getApiT $ fst $ addr2 ^. #id) + let amt = 14 + let (feeMin, feeMax) = (181487, 181839) + let args = T.unpack <$> + [ wSrc ^. walletId + , "--payment", T.pack (show amt) <> "@" <> addr1' + , "--payment", T.pack (show amt) <> "@" <> addr2' + ] + + -- post transaction + (c, out, err) <- postTransactionViaCLI "cardano-wallet" args + err `shouldBe` "Please enter a passphrase: **************\nOk.\n" + txJson <- expectValidJSON (Proxy @(ApiTransaction t)) out + verify txJson + [ expectCliFieldBetween amount (feeMin + amt, feeMax + amt) + , expectCliFieldEqual direction Outgoing + , expectCliFieldEqual status Pending + ] + c `shouldBe` ExitSuccess + + -- verify balance on src wallet + Stdout gOutSrc <- getWalletViaCLI (T.unpack (wSrc ^. walletId)) + gJson <- expectValidJSON (Proxy @ApiWallet) gOutSrc + verify gJson + [ expectCliFieldBetween balanceTotal + ( faucetAmt - feeMax - amt + , faucetAmt - feeMin - amt + ) + , expectCliFieldEqual balanceAvailable (faucetAmt - 2*faucetUtxoAmt) + ] + + forM_ [wDest1, wDest2] $ \wDest -> do + expectEventually' ctx balanceAvailable amt wDest + expectEventually' ctx balanceTotal amt wDest + + -- verify balance on dest wallets + Stdout gOutDest <- getWalletViaCLI (T.unpack (wDest ^. walletId)) + destJson <- expectValidJSON (Proxy @ApiWallet) gOutDest + verify destJson + [ expectCliFieldEqual balanceAvailable amt + , expectCliFieldEqual balanceTotal amt + ] + + it "TRANS_CREATE_02 - Multiple Output Txs don't work on single UTxO" $ \ctx -> do + wSrc <- fixtureWalletWith ctx [2_124_333] + wDest <- emptyWallet ctx + addrs <- listAddresses ctx wDest + + let addr1 = + encodeAddress (Proxy @t) (getApiT $ fst $ addrs !! 1 ^. #id) + let addr2 = + encodeAddress (Proxy @t) (getApiT $ fst $ addrs !! 2 ^. #id) + let args = T.unpack <$> + [ wSrc ^. walletId + , "--payment", "12333@" <> addr1 + , "--payment", "4666@" <> addr2 + ] + + (c, out, err) <- postTransactionViaCLI "cardano-wallet" args + (T.unpack err) `shouldContain` errMsg403UTxO + out `shouldBe` "" + c `shouldBe` ExitSuccess + + it "TRANS_CREATE_03 - 0 balance after transaction" $ \ctx -> do + let balance = 168434 + wSrc <- fixtureWalletWith ctx [balance] + wDest <- emptyWallet ctx + addrs:_ <- listAddresses ctx wDest + let addr = + encodeAddress (Proxy @t) (getApiT $ fst $ addrs ^. #id) + let args = T.unpack <$> + [ wSrc ^. walletId + , "--payment", "1@" <> addr + ] + + (c, out, err) <- postTransactionViaCLI "Secure Passphrase" args + err `shouldBe` "Please enter a passphrase: *****************\nOk.\n" + txJson <- expectValidJSON (Proxy @(ApiTransaction t)) out + verify txJson + [ expectCliFieldEqual amount balance + , expectCliFieldEqual direction Outgoing + , expectCliFieldEqual status Pending + ] + c `shouldBe` ExitSuccess + + Stdout gOutSrc <- getWalletViaCLI (T.unpack (wSrc ^. walletId)) + gJson <- expectValidJSON (Proxy @ApiWallet) gOutSrc + verify gJson + [ expectCliFieldEqual balanceTotal 0 + , expectCliFieldEqual balanceAvailable 0 + ] + + expectEventually' ctx balanceAvailable 1 wDest + expectEventually' ctx balanceTotal 1 wDest + + Stdout gOutDest <- getWalletViaCLI (T.unpack (wDest ^. walletId)) + destJson <- expectValidJSON (Proxy @ApiWallet) gOutDest + verify destJson + [ expectCliFieldEqual balanceAvailable 1 + , expectCliFieldEqual balanceTotal 1 + ] + + it "TRANS_CREATE_04 - Can't cover fee" $ \ctx -> do + wSrc <- fixtureWalletWith ctx [100_000] + wDest <- emptyWallet ctx + addrs:_ <- listAddresses ctx wDest + let addr = + encodeAddress (Proxy @t) (getApiT $ fst $ addrs ^. #id) + let args = T.unpack <$> + [ wSrc ^. walletId + , "--payment", "1@" <> addr + ] + + (c, out, err) <- postTransactionViaCLI "Secure Passphrase" args + (T.unpack err) `shouldContain` errMsg403Fee + out `shouldBe` "" + c `shouldBe` ExitSuccess + + it "TRANS_CREATE_04 - Not enough money" $ \ctx -> do + wSrc <- fixtureWalletWith ctx [100_000, 1000] + wDest <- emptyWallet ctx + addrs:_ <- listAddresses ctx wDest + let addr = + encodeAddress (Proxy @t) (getApiT $ fst $ addrs ^. #id) + let args = T.unpack <$> + [ wSrc ^. walletId + , "--payment", "1000000@" <> addr + ] + + (c, out, err) <- postTransactionViaCLI "Secure Passphrase" args + (T.unpack err) `shouldContain` (errMsg403NotEnoughMoney 101_000 1000_000) + out `shouldBe` "" + c `shouldBe` ExitSuccess + + it "TRANS_CREATE_04 - Wrong password" $ \ctx -> do + wSrc <- fixtureWallet ctx + wDest <- emptyWallet ctx + addrs:_ <- listAddresses ctx wDest + let addr = + encodeAddress (Proxy @t) (getApiT $ fst $ addrs ^. #id) + let args = T.unpack <$> + [ wSrc ^. walletId + , "--payment", "14@" <> addr + ] + + (c, out, err) <- postTransactionViaCLI "This password is wrong" args + (T.unpack err) `shouldContain` errMsg403WrongPass + out `shouldBe` "" + c `shouldBe` ExitSuccess + + describe "TRANS_CREATE_05 - Invalid addresses" $ do + let longAddr = replicate 10000 '1' + let byronErr = "Unable to decode Address: not a valid Byron address." + let base58Err = "Unable to decode Address: expected Base58 encoding." + let parseErr = "Parse error. Expecting format \"@
\"" + let matrix = + [ ( "long hex", longAddr, byronErr ) + , ( "short hex", "1", byronErr ) + , ( "-1000", "-1000", base58Err ), ( "q", "q", byronErr ) + , ( "empty", "", byronErr ) + , ( "wildcards", T.unpack wildcardsWalletName, parseErr ) + , ( "arabic", T.unpack arabicWalletName, base58Err ) + , ( "kanji", T.unpack kanjiWalletName, base58Err ) + , ( "polish", T.unpack polishWalletName, base58Err ) + , ( "[]", "[]", base58Err ) + , ( "no address", "", byronErr ) + , ( "address is space", " ", base58Err ) + ] + forM_ matrix $ \(title, addr, errMsg) -> it title $ \ctx -> do + wSrc <- fixtureWallet ctx + let args = T.unpack <$> + [ wSrc ^. walletId + , "--payment", "12@" <> (T.pack addr) + ] + + (c, out, err) <- postTransactionViaCLI "Secure Passphrase" args + (T.unpack err) `shouldContain` errMsg + out `shouldBe` "" + c `shouldBe` (ExitFailure 1) + + describe "TRANS_CREATE_06 - Invalid amount" $ do + let errNum = "Expecting natural number" + let parseErr = "Parse error. Expecting format \"@
\"" + let matrix = + [ ("0", "0", errMsg500) -- TODO change after #364 + , ("1.5", "1.5", errNum), ("-1000", "-1000", errNum) + , ("[]", "[]", errNum) + , ("string with diacritics", polishWalletName, errNum) + , ("string with wildcards", wildcardsWalletName, parseErr) + , ("no amount", "", errNum) + ] + forM_ matrix $ \(title, amt, errMsg) -> it title $ \ctx -> do + wSrc <- fixtureWallet ctx + wDest <- emptyWallet ctx + addrs:_ <- listAddresses ctx wDest + let addr = + encodeAddress (Proxy @t) (getApiT $ fst $ addrs ^. #id) + let args = T.unpack <$> + [ wSrc ^. walletId + , "--payment", amt <> "@" <> addr + ] + + (c, out, err) <- postTransactionViaCLI "cardano-wallet" args + (T.unpack err) `shouldContain` errMsg + out `shouldBe` "" + if (title == "0") then + c `shouldBe` ExitSuccess + else + c `shouldBe` (ExitFailure 1) + + describe "TRANS_CREATE_07 - False wallet ids" $ do + forM_ falseWalletIds $ \(title, walId) -> it title $ \ctx -> do + wDest <- emptyWallet ctx + addrs:_ <- listAddresses ctx wDest + let addr = + encodeAddress (Proxy @t) (getApiT $ fst $ addrs ^. #id) + let args = [ walId, "--payment", "12@" ++ (T.unpack addr) ] + + (c, out, err) <- postTransactionViaCLI "Secure Passphrase" args + out `shouldBe` "" + if (title == "40 chars hex") then + (T.unpack err) `shouldContain` "I couldn't find a wallet with \ + \the given id: 1111111111111111111111111111111111111111" + else + (T.unpack err) `shouldContain` "wallet id should be an \ + \hex-encoded string of 40 characters" + if (title == "40 chars hex") then + c `shouldBe` ExitSuccess + else + c `shouldBe` (ExitFailure 1) + + it "TRANSCLI_CREATE_07 - 'almost' valid walletId" $ \ctx -> do + wSrc <- fixtureWallet ctx + wDest <- emptyWallet ctx + addrs:_ <- listAddresses ctx wDest + let addr = + encodeAddress (Proxy @t) (getApiT $ fst $ addrs ^. #id) + let args = T.unpack <$> + [ (T.append (wSrc ^. walletId) "0"), "--payment", "11@" <> addr ] + + (c, out, err) <- postTransactionViaCLI "cardano-wallet" args + (T.unpack err) `shouldContain` "wallet id should be an hex-encoded\ + \ string of 40 characters" + out `shouldBe` "" + c `shouldBe` (ExitFailure 1) + + it "TRANS_CREATE_07 - Deleted wallet" $ \ctx -> do + wSrc <- fixtureWallet ctx + Exit ex <- deleteWalletViaCLI (T.unpack ( wSrc ^. walletId )) + ex `shouldBe` ExitSuccess + + wDest <- emptyWallet ctx + addrs:_ <- listAddresses ctx wDest + let addr = + encodeAddress (Proxy @t) (getApiT $ fst $ addrs ^. #id) + let args = T.unpack <$> [ wSrc ^. walletId, "--payment", "11@" <> addr ] + + (c, out, err) <- postTransactionViaCLI "cardano-wallet" args + (T.unpack err) `shouldContain` "I couldn't find a wallet with \ + \the given id: " ++ T.unpack ( wSrc ^. walletId ) + out `shouldBe` "" c `shouldBe` ExitSuccess diff --git a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Wallets.hs b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Wallets.hs index 33a9fef72c9..072d642af1f 100644 --- a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Wallets.hs +++ b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Wallets.hs @@ -100,7 +100,7 @@ spec = do walId <- emptyWallet' ctx (Exit c, Stdout out, Stderr err) <- getWalletViaCLI walId err `shouldBe` "Ok.\n" - expectValidJSON (Proxy @ApiWallet) out + _ <- expectValidJSON (Proxy @ApiWallet) out out `shouldContain` "Empty Wallet" c `shouldBe` ExitSuccess @@ -124,7 +124,7 @@ spec = do emptyWallet' ctx $> () <* emptyWallet' ctx (Exit c, Stdout out, Stderr err) <- listWalletsViaCLI err `shouldBe` "Ok.\n" - expectValidJSON (Proxy @[ApiWallet]) out + _ <- expectValidJSON (Proxy @[ApiWallet]) out out `shouldContain` "Empty Wallet" c `shouldBe` ExitSuccess @@ -133,7 +133,7 @@ spec = do let args = [walId, "--name", "new name"] (Exit c, Stdout out, Stderr err) <- updateWalletViaCLI args err `shouldBe` "Ok.\n" - expectValidJSON (Proxy @ApiWallet) out + _ <- expectValidJSON (Proxy @ApiWallet) out out `shouldContain` "new name" c `shouldBe` ExitSuccess From 07aac25079d73bcb66f4151049e5a5b175e2458c Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Wed, 5 Jun 2019 08:49:24 +0200 Subject: [PATCH 4/4] Rebase and code review fixes --- exe/wallet/Main.hs | 2 -- .../Test/Integration/Framework/DSL.hs | 21 +++---------------- .../Integration/Scenario/CLI/Addresses.hs | 2 +- .../Integration/Scenario/CLI/Transactions.hs | 4 ++-- 4 files changed, 6 insertions(+), 23 deletions(-) diff --git a/exe/wallet/Main.hs b/exe/wallet/Main.hs index 095adc4dba4..8b11116a563 100644 --- a/exe/wallet/Main.hs +++ b/exe/wallet/Main.hs @@ -59,8 +59,6 @@ import Cardano.Wallet.Primitive.Mnemonic ( entropyToMnemonic, genEntropy, mnemonicToText ) import Cardano.Wallet.Primitive.Types ( DecodeAddress, EncodeAddress ) -import Control.Applicative - ( many ) import Control.Arrow ( second ) import Control.Monad diff --git a/lib/http-bridge/test/integration/Test/Integration/Framework/DSL.hs b/lib/http-bridge/test/integration/Test/Integration/Framework/DSL.hs index e55cc09a124..277c8fb1f12 100644 --- a/lib/http-bridge/test/integration/Test/Integration/Framework/DSL.hs +++ b/lib/http-bridge/test/integration/Test/Integration/Framework/DSL.hs @@ -319,9 +319,11 @@ expectEventually ctx getter target (_, res) = case res of let target' = getFromResponse getter r unless (target' >= target) $ loopUntilRestore wid +-- | Same as `expectEventually` but work directly on ApiWallet +-- , not response from the API expectEventually' :: (MonadIO m, MonadCatch m, MonadFail m, Ord a) - => Context + => Context t -> Lens' ApiWallet a -> a -> ApiWallet @@ -345,23 +347,6 @@ expectValidJSON _ str = Left e -> fail $ "expected valid JSON but failed decoding: " <> show e Right a -> return a --- | Expects wallet from the request to eventually reach the given state or --- beyond --- expectCliEventually --- :: (MonadIO m, MonadCatch m, MonadFail m, Ord a) --- => Lens' ApiWallet a --- -> a --- -> ApiWallet --- -> m () --- expectCliEventually getter target w = loopUntilRestore (w ^. walletId) --- where --- loopUntilRestore :: (MonadIO m, MonadCatch m) => Text -> IO () --- loopUntilRestore wid = do --- Stdout out <- getWalletViaCLI (T.unpack wid) --- outJson <- expectValidJSON (Proxy @ApiWallet) out --- let target' = view getter outJson --- unless (target' >= target) $ loopUntilRestore wid - expectCliFieldBetween :: (MonadIO m, MonadFail m, Show a, Ord a) => Lens' s a diff --git a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Addresses.hs b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Addresses.hs index 678f9afee48..2ceafa22fe6 100644 --- a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Addresses.hs +++ b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Addresses.hs @@ -42,7 +42,7 @@ spec = do walId <- emptyWallet' ctx (Exit c, Stdout out, Stderr err) <- listAddressesViaCLI walId err `shouldBe` "Ok.\n" - expectValidJSON (Proxy @[ApiAddress t]) out + _ <- expectValidJSON (Proxy @[ApiAddress t]) out c `shouldBe` ExitSuccess where diff --git a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Transactions.hs b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Transactions.hs index 8ca243142cf..9934a2701ea 100644 --- a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Transactions.hs +++ b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Transactions.hs @@ -11,11 +11,11 @@ module Test.Integration.Scenario.CLI.Transactions import Prelude import Cardano.Wallet.Api.Types - ( ApiAddress, ApiTransaction, getApiT ) + ( ApiTransaction, ApiWallet, getApiT ) import Cardano.Wallet.Primitive.Types ( DecodeAddress (..) - , EncodeAddress (..) , Direction (..) + , EncodeAddress (..) , TxStatus (..) , encodeAddress )