Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More integration tests for CLI (including minor fixes in CLI) #278

Merged
merged 4 commits into from
May 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion exe/launcher/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import System.Console.Docopt
, isPresent
, longOption
, parseArgsOrExit
, shortOption
)
import System.Environment
( getArgs )
Expand All @@ -57,7 +58,7 @@ in the directory.

Usage:
cardano-wallet-launcher [options]
cardano-wallet-launcher --help
cardano-wallet-launcher -h | --help

Options:
--wallet-server-port <PORT> port used for serving the wallet API [default: 8090]
Expand All @@ -68,6 +69,7 @@ main :: IO ()
main = do
args <- parseArgsOrExit cli =<< getArgs
when (args `isPresent` (longOption "help")) $ help cli
when (args `isPresent` (shortOption 'h')) $ help cli

bridgePort <- args `parseArg` longOption "http-bridge-port"
walletPort <- args `parseArg` longOption "wallet-server-port"
Expand Down
18 changes: 11 additions & 7 deletions exe/wallet/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ import Data.Functor
import qualified Data.List.NonEmpty as NE
import Data.Proxy
( Proxy (..) )
import Data.Text
( Text )
import Data.Text.Class
( FromText (..), ToText (..) )
import Data.Typeable
Expand All @@ -95,6 +97,7 @@ import System.Console.Docopt
, isPresent
, longOption
, parseArgsOrExit
, shortOption
)
import System.Environment
( getArgs )
Expand Down Expand Up @@ -170,6 +173,7 @@ main = do
exec :: Manager -> Arguments -> IO ()
exec manager args
| args `isPresent` (longOption "help") = help cli
| args `isPresent` (shortOption 'h') = help cli

| args `isPresent` command "server" = do
walletPort <- args `parseArg` longOption "port"
Expand Down Expand Up @@ -343,15 +347,15 @@ execServer (Port port) (Port bridgePort) = do

-- | Generate a random mnemonic of the given size 'n' (n = number of words),
-- and print it to stdout.
execGenerateMnemonic :: Int -> IO ()
execGenerateMnemonic :: Text -> IO ()
execGenerateMnemonic n = do
m <- case n of
9 -> mnemonicToText @9 . entropyToMnemonic <$> genEntropy
12 -> mnemonicToText @12 . entropyToMnemonic <$> genEntropy
15 -> mnemonicToText @15 . entropyToMnemonic <$> genEntropy
18 -> mnemonicToText @18 . entropyToMnemonic <$> genEntropy
21 -> mnemonicToText @21 . entropyToMnemonic <$> genEntropy
24 -> mnemonicToText @24 . entropyToMnemonic <$> genEntropy
"9" -> mnemonicToText @9 . entropyToMnemonic <$> genEntropy
"12" -> mnemonicToText @12 . entropyToMnemonic <$> genEntropy
"15" -> mnemonicToText @15 . entropyToMnemonic <$> genEntropy
"18" -> mnemonicToText @18 . entropyToMnemonic <$> genEntropy
"21" -> mnemonicToText @21 . entropyToMnemonic <$> genEntropy
"24" -> mnemonicToText @24 . entropyToMnemonic <$> genEntropy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet :o

_ -> do
putErrLn "Invalid mnemonic size. Expected one of: 9,12,15,18,21,24"
exitFailure
Expand Down
1 change: 1 addition & 0 deletions lib/http-bridge/cardano-wallet-http-bridge.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ test-suite integration
Test.Integration.Faucet
Test.Integration.Framework.DSL
Test.Integration.Framework.Request
Test.Integration.Framework.TestData
Test.Integration.Scenario.Addresses
Test.Integration.Scenario.Transactions
Test.Integration.Scenario.Wallets
Expand Down
75 changes: 75 additions & 0 deletions lib/http-bridge/test/integration/Test/Integration/Framework/DSL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ module Test.Integration.Framework.DSL
, json
, tearDown
, fixtureWallet

-- * CLI
, cardanoWalletCLI
, cardanoWalletLauncherCLI
, generateMnemonicsViaCLI
, createWalletViaCLI
, deleteWalletViaCLI
, getWalletViaCLI
, listAddressesViaCLI
, listWalletsViaCLI
, updateWalletViaCLI
) where

import Prelude hiding
Expand Down Expand Up @@ -112,6 +123,19 @@ import Language.Haskell.TH.Quote
( QuasiQuoter )
import Numeric.Natural
( Natural )
import System.Command
( CmdResult, command )
import System.Exit
( ExitCode (..) )
import System.IO
( hClose, hFlush, hPutStr )
import System.Process
( CreateProcess (..)
, StdStream (..)
, proc
, waitForProcess
, withCreateProcess
)
import Test.Hspec.Expectations.Lifted
( shouldBe, shouldContain, shouldNotBe )
import Test.Integration.Faucet
Expand Down Expand Up @@ -438,3 +462,54 @@ wantedErrorButSuccess
-> m void
wantedErrorButSuccess =
fail . ("expected an error but got a successful response: " <>) . show


---
--- CLI
---
cardanoWalletLauncherCLI :: CmdResult r => [String] -> IO r
cardanoWalletLauncherCLI = command [] "cardano-wallet-launcher"

cardanoWalletCLI :: CmdResult r => [String] -> IO r
cardanoWalletCLI = command [] "cardano-wallet"

generateMnemonicsViaCLI :: CmdResult r => [String] -> IO r
generateMnemonicsViaCLI args = cardanoWalletCLI (["mnemonic", "generate"] ++ args)

createWalletViaCLI :: [String] -> String -> String -> String -> IO ExitCode
createWalletViaCLI args mnemonics mnemonics2 passphrase = do
let fullArgs = ["wallet", "create", "--port", "1337"] ++ args
let process = (proc "cardano-wallet" fullArgs)
{ std_in = CreatePipe, std_out = CreatePipe, std_err = CreatePipe }
withCreateProcess process $ \stdIn _ _ h -> do
case stdIn of
Nothing -> return ()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should "throw". Since we use CreatePipe this must be Just. If not, the test might hang forever.

Just i -> do
hPutStr i mnemonics
hPutStr i mnemonics2
hPutStr i (passphrase ++ "\n")
hPutStr i (passphrase ++ "\n")
hFlush i
hClose i
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My man ❤️


waitForProcess h


deleteWalletViaCLI :: CmdResult r => String -> IO r
deleteWalletViaCLI walId = cardanoWalletCLI ["wallet", "delete", "--port",
"1337", walId ]

getWalletViaCLI :: CmdResult r => String -> IO r
getWalletViaCLI walId = cardanoWalletCLI ["wallet", "get", "--port", "1337"
, walId ]

listAddressesViaCLI :: CmdResult r => String -> IO r
listAddressesViaCLI walId = cardanoWalletCLI ["address", "list", "--port",
"1337", walId]

listWalletsViaCLI :: CmdResult r => IO r
listWalletsViaCLI = cardanoWalletCLI ["wallet", "list", "--port", "1337" ]

updateWalletViaCLI :: CmdResult r => [String] -> IO r
updateWalletViaCLI args = cardanoWalletCLI (["wallet", "update", "--port",
"1337"] ++ args)
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
module Test.Integration.Framework.TestData
( -- * Mnemonics
chineseMnemonics9
, chineseMnemonics18
, frenchMnemonics12
, frenchMnemonics21
, invalidMnemonics12
, invalidMnemonics15
, japaneseMnemonics12
, japaneseMnemonics15
, mnemonics3
, mnemonics6
, mnemonics9
, mnemonics12
, mnemonics15
, mnemonics18
, mnemonics21
, mnemonics24
, specMnemonicSentence
, specMnemonicSecondFactor

-- * Wallets
, arabicWalletName
, falseWalletIds
, kanjiWalletName
, polishWalletName
, russianWalletName
, wildcardsWalletName


-- * Helpers
, addressPoolGapMax
, addressPoolGapMin
, passphraseMaxLength
, passphraseMinLength
) where

import Prelude

import Data.Text
( Text )

falseWalletIds :: [(String, String)]
falseWalletIds =
[ ("40 chars hex", replicate 40 '1')
, ("40 chars non-hex", replicate 40 'ś')
, ("39 chars hex", replicate 39 '1')
, ("41 chars hex", replicate 41 '1')
]

mnemonics3 :: [Text]
mnemonics3 = ["diamond", "flee", "window"]

mnemonics6 :: [Text]
mnemonics6 = ["tornado", "canvas", "peasant", "spike", "enrich", "dilemma"]

mnemonics9 :: [Text]
mnemonics9 = ["subway", "tourist", "abstract", "roast", "border", "curious",
"exercise", "work", "narrow"]

mnemonics12 :: [Text]
mnemonics12 = ["agent", "siren", "roof", "water", "giant", "pepper",
"obtain", "oxygen", "treat", "vessel", "hip", "garlic"]

mnemonics15 :: [Text]
mnemonics15 = ["network", "empty", "cause", "mean", "expire", "private",
"finger", "accident", "session", "problem", "absurd", "banner", "stage",
"void", "what"]

mnemonics18 :: [Text]
mnemonics18 = ["whisper", "control", "diary", "solid", "cattle", "salmon",
"whale", "slender", "spread", "ice", "shock", "solve", "panel",
"caution", "upon", "scatter", "broken", "tonight"]

mnemonics21 :: [Text]
mnemonics21 = ["click", "puzzle", "athlete", "morning", "fold", "retreat",
"across", "timber", "essay", "drill", "finger", "erase", "galaxy",
"spoon", "swift", "eye", "awesome", "shrimp", "depend", "zebra", "token"]

mnemonics24 :: [Text]
mnemonics24 = ["decade", "distance", "denial", "jelly", "wash", "sword",
"olive", "perfect", "jewel", "renew", "wrestle", "cupboard", "record",
"scale", "pattern", "invite", "other", "fruit", "gloom", "west", "oak",
"deal", "seek", "hand"]

invalidMnemonics12 :: [Text]
invalidMnemonics12 = ["word","word","word","word","word","word","word",
"word","word","word","word","hill"]

invalidMnemonics15 :: [Text]
invalidMnemonics15 = ["word","word","word","word","word","word","word",
"word","word","word","word","word","word","word","word"]

specMnemonicSentence :: [Text]
specMnemonicSentence = ["squirrel", "material", "silly", "twice", "direct",
"slush", "pistol", "razor", "become", "junk", "kingdom", "flee",
"squirrel", "silly", "twice"]

specMnemonicSecondFactor :: [Text]
specMnemonicSecondFactor = ["squirrel", "material", "silly", "twice",
"direct", "slush", "pistol", "razor", "become"]

japaneseMnemonics12 :: [Text]
japaneseMnemonics12 = ["そうだん", "ひよう", "にもつ", "やさしい", "きふく", 
"ねつい", "だったい", "けんてい", "けいろ", "ざつがく", "ほうもん", "すこし"]

japaneseMnemonics15 :: [Text]
japaneseMnemonics15 = ["うめる", "せんく", "えんぎ", "はんぺん", "おくりがな",
"さんち", "きなが", "といれ", "からい", "らくだ", "うえる", "ふめん", "せびろ",
"られつ", "なにわ"]

chineseMnemonics9 :: [Text]
chineseMnemonics9 = ["钢", "看", "磁", "塑", "凤", "魏", "世", "腐", "恶" ]

chineseMnemonics18 :: [Text]
chineseMnemonics18 = ["盗", "精", "序", "郎", "赋", "姿", "委", "善", "酵",
"祥", "赛", "矩", "蜡", "注", "韦", "效", "义", "冻"]

frenchMnemonics12 :: [Text]
frenchMnemonics12 = ["palmarès", "supplier", "visuel", "gardien", "adorer",
"cordage", "notifier", "réglage", "employer", "abandon", "scénario",
"proverbe"]

frenchMnemonics21 :: [Text]
frenchMnemonics21 = ["pliage", "exhorter", "brasier", "chausson", "bloquer",
"besace", "sorcier", "absurde", "neutron", "forgeron", "geyser",
"moulin", "cynique", "cloche", "baril", "infliger", "rompre", "typique",
"renifler", "creuser", "matière"]

russianWalletName :: Text
russianWalletName = "АаБбВвГгДдЕеЁёЖжЗз ИиЙйКкЛлМмНнО оПпРрСсТтУуФф ХхЦцЧчШшЩщЪъ ЫыЬьЭэЮюЯяІ ѢѲѴѵѳѣі"

polishWalletName :: Text
polishWalletName = "aąbcćdeęfghijklłmnoóprsś\r\ntuvwyzżźAĄBCĆDEĘFGHIJKLŁMNOP\rRSŚTUVWYZŻŹ"

kanjiWalletName :: Text
kanjiWalletName = "亜哀挨愛曖悪握圧扱宛嵐安案暗以衣位囲医依委威為畏胃尉異移萎偉椅彙意違維慰\
\遺緯域育一壱逸茨芋引印因咽姻員院淫陰飲隠韻右宇羽雨唄鬱畝浦運雲永泳英映栄\n営詠影鋭衛易疫益液駅悦越謁\
\閲円延沿炎怨宴媛援園煙猿遠鉛塩演縁艶汚王凹\r\n央応往押旺欧殴桜翁奥横岡屋億憶臆虞乙俺卸音恩温穏下化火加\
\可仮何花佳価果河苛科架夏家荷華菓貨渦過嫁暇禍靴寡歌箇稼課蚊牙瓦我画芽賀雅餓介回灰会快戒改怪拐悔海界\
\皆械絵開階塊楷解潰壊懐諧貝外劾害崖涯街慨蓋該概骸垣柿各角拡革格核殻郭覚較隔閣確獲嚇穫学岳楽額顎掛潟\
\括活喝渇割葛滑褐轄且株釜鎌刈干刊甘汗缶\r"

arabicWalletName :: Text
arabicWalletName = "ثم نفس سقطت وبالتحديد،, جزيرتي باستخدام أن دنو. إذ هنا؟ الستار وتنصيب كان. أهّل ايطاليا، بريطانيا-فرنسا قد أخذ. سليمان، إتفاقية بين ما, يذكر الحدود أي بعد, معاملة بولندا، الإطلاق عل إيو."

wildcardsWalletName :: Text
wildcardsWalletName = "`~`!@#$%^&*()_+-=<>,./?;':\"\"'{}[]\\|❤️ 💔 💌 💕 💞 \
\💓 💗 💖 💘 💝 💟 💜 💛 💚 💙0️⃣ 1️⃣ 2️⃣ 3️⃣ 4️⃣ 5️⃣ 6️⃣ 7️⃣ 8️⃣ 9️⃣ 🔟🇺🇸🇷🇺🇸 🇦🇫🇦🇲🇸"

passphraseMinLength :: Int
passphraseMinLength = 10

passphraseMaxLength :: Int
passphraseMaxLength = 255

addressPoolGapMin :: Int
addressPoolGapMin = 10

addressPoolGapMax :: Int
addressPoolGapMax = 100
Loading