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