Skip to content

Commit

Permalink
adjust integration tests to check default ports combinations
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Jun 12, 2019
1 parent 8eac9eb commit fb2f74a
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 16 deletions.
17 changes: 13 additions & 4 deletions lib/core/test/integration/Test/Integration/Framework/DSL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -742,12 +742,19 @@ createWalletViaCLI
-> String
-> String
-> String
-> Maybe String
-> IO (ExitCode, String, Text)
createWalletViaCLI args mnemonics secondFactor passphrase = do
createWalletViaCLI args mnemonics secondFactor passphrase portM = do
let fullArgs =
[ "exec", "--", "cardano-wallet"
, "wallet", "create", "--port", "1337"
] ++ args
case portM of
Nothing ->
[ "exec", "--", "cardano-wallet"
, "wallet", "create"
] ++ args
Just port ->
[ "exec", "--", "cardano-wallet"
, "wallet", "create", "--port", port
] ++ args
let process = (proc "stack" fullArgs)
{ std_in = CreatePipe, std_out = CreatePipe, std_err = CreatePipe }
withCreateProcess process $ \(Just stdin) (Just stdout) (Just stderr) h -> do
Expand All @@ -762,6 +769,8 @@ createWalletViaCLI args mnemonics secondFactor passphrase = do
err <- TIO.hGetContents stderr
return (c, T.unpack out, err)



deleteWalletViaCLI :: CmdResult r => String -> IO r
deleteWalletViaCLI walId = cardanoWalletCLI
["wallet", "delete", "--port", "1337", walId ]
Expand Down
91 changes: 79 additions & 12 deletions lib/core/test/integration/Test/Integration/Scenario/CLI/Wallets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

module Test.Integration.Scenario.CLI.Wallets
( spec
, specPorts
) where

import Prelude
Expand All @@ -23,7 +24,7 @@ import System.Command
import System.Exit
( ExitCode (..) )
import Test.Hspec
( SpecWith, describe, it )
( SpecWith, describe, it, xit )
import Test.Hspec.Expectations.Lifted
( shouldBe, shouldContain, shouldNotContain )
import Test.Integration.Framework.DSL
Expand All @@ -48,13 +49,13 @@ spec = 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]
let passphrase = "Secure passphrase"

(c, out, err) <- createWalletViaCLI [walletName] mnemonics "\n" passphrase
c `shouldBe` ExitSuccess
T.unpack err `shouldContain` "Ok.\n"
out `shouldContain` walletName
checkSimpleCreateWallet
(Just "1337")
size
walletName
(`shouldBe` ExitSuccess)
(`shouldContain` "Ok.\n")
(`shouldContain` walletName)

describe "WALLETS_CREATE_05 - Can't create wallet with wrong size of mnemonic" $ do
forM_ ["9", "12"] $ \(size) -> it size $ \_ -> do
Expand All @@ -63,7 +64,7 @@ spec = do
Stdout mnemonics2 <- generateMnemonicsViaCLI ["--size", size]
let passphrase = "Secure passphrase"

(c, out, err) <- createWalletViaCLI [walletName] mnemonics mnemonics2 passphrase
(c, out, err) <- createWalletViaCLI [walletName] mnemonics mnemonics2 passphrase (Just "1337")
c `shouldBe` (ExitFailure 1)
out `shouldBe` ""
T.unpack err `shouldContain` "Invalid number of words: 15, 18, 21\
Expand All @@ -78,7 +79,7 @@ spec = do
Stdout mnemonics2 <- generateMnemonicsViaCLI ["--size", size]
let passphrase = "Secure passphrase"

(c, out, err) <- createWalletViaCLI [walletName] mnemonics mnemonics2 passphrase
(c, out, err) <- createWalletViaCLI [walletName] mnemonics mnemonics2 passphrase (Just "1337")
c `shouldBe` ExitSuccess
T.unpack err `shouldContain` "Ok.\n"
out `shouldContain` walletName
Expand All @@ -90,7 +91,7 @@ spec = do
Stdout mnemonics2 <- generateMnemonicsViaCLI ["--size", size]
let passphrase = "Secure passphrase"

(c, out, err) <- createWalletViaCLI [walletName] mnemonics mnemonics2 passphrase
(c, out, err) <- createWalletViaCLI [walletName] mnemonics mnemonics2 passphrase (Just "1337")
c `shouldBe` (ExitFailure 1)
out `shouldBe` ""
T.unpack err `shouldContain` "Invalid number of words: 9 or 12\
Expand All @@ -99,6 +100,27 @@ spec = do
Stdout outList <- listWalletsViaCLI
outList `shouldNotContain` walletName

it "WALLETS_CREATE_06 - Cannot create wallet with wrong port" $ \_ -> do
let walletName = "Wallet created via CLI"
checkSimpleCreateWallet
(Just "1338")
"15"
walletName
(`shouldBe` ExitSuccess)
(`shouldContain` "does not exist (Connection refused))\n")
(`shouldNotContain` walletName)

xit "WALLETS_CREATE_06 - Cannot create wallet with default port" $ \_ -> do
let walletName = "Wallet created via CLI"
checkSimpleCreateWallet
Nothing
"15"
walletName
(`shouldBe` ExitSuccess)
(`shouldContain` "does not exist (Connection refused))\n")
(`shouldNotContain` walletName)


it "WALLETS_GET_01 - Can get a wallet" $ \ctx -> do
walId <- emptyWallet' ctx
(Exit c, Stdout out, Stderr err) <- getWalletViaCLI walId
Expand Down Expand Up @@ -142,7 +164,52 @@ spec = do
err `shouldBe` "Ok.\n"
out `shouldNotContain` "CLI Wallet"
c `shouldBe` ExitSuccess

where
emptyWallet' :: Context t -> IO String
emptyWallet' = fmap (T.unpack . view walletId) . emptyWallet

specPorts :: SpecWith (Context t)
specPorts = do
it "PORTS_01 - Can create wallet with specifying port" $ \_ -> do
let walletName = "Wallet created via CLI"
checkSimpleCreateWallet
(Just "9080")
"15"
walletName
(`shouldBe` ExitSuccess)
(`shouldContain` "Ok.\n")
(`shouldContain` walletName)
xit "PORTS_02 - Can create wallet with relying on default port" $ \_ -> do
let walletName = "Wallet created via CLI"
checkSimpleCreateWallet
Nothing
"15"
walletName
(`shouldBe` ExitSuccess)
(`shouldContain` "Ok.\n")
(`shouldContain` walletName)
it "PORTS_03 - Cannot create wallet with wrong port" $ \_ -> do
let walletName = "Wallet created via CLI"
checkSimpleCreateWallet
(Just "9081")
"15"
walletName
(`shouldBe` ExitSuccess)
(`shouldContain` "does not exist (Connection refused))\n")
(`shouldNotContain` walletName)

checkSimpleCreateWallet
:: Maybe String
-> String
-> String
-> (ExitCode -> IO ())
-> (String -> IO ())
-> (String -> IO ())
-> IO ()
checkSimpleCreateWallet portM mnemonicSize walletName exitCodeCheck errCheck outCheck = do
Stdout mnemonics <- generateMnemonicsViaCLI ["--size", mnemonicSize]
let passphrase = "Secure passphrase"
(c, out, err) <- createWalletViaCLI [walletName] mnemonics "\n" passphrase portM
exitCodeCheck c
errCheck (T.unpack err)
outCheck out
2 changes: 2 additions & 0 deletions lib/http-bridge/test/integration/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ main = hspec $ do
describe "Wallets CLI tests" WalletsCLI.spec
describe "Transactions CLI tests" TransactionsCLI.spec
describe "Addresses CLI tests" AddressesCLI.spec
beforeAll (startCluster Nothing) $ afterAll killCluster $ after tearDown $ do
describe "Port tests using wallets CLI" WalletsCLI.specPorts
where
oneSecond :: Int
oneSecond = 1 * 1000 * 1000 -- 1 second in microseconds
Expand Down

0 comments on commit fb2f74a

Please sign in to comment.