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

Basic integration scenarios for CLI #264

Merged
merged 10 commits into from
May 16, 2019
Merged

Basic integration scenarios for CLI #264

merged 10 commits into from
May 16, 2019

Conversation

piotr-iohk
Copy link
Contributor

Issue Number

#96

Overview

  • I have added some basic integration tests for CLI (get, list, update, delete, mnemonics, version). Let's see if this approach works... 🤞 (However, for know, still don't know how to test prompt command line with this (wallet create))

Comments


it "CLI - Can generate mnemonics with default size" $ do
Stdout out <- command [] "cardano-wallet" ["mnemonic", "generate"]
length (splitOn " " out) `shouldBe` 15
Copy link
Member

Choose a reason for hiding this comment

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

You're probably just looking for: https://hackage.haskell.org/package/base-4.11.1.0/docs/Data-List.html#v:words from the base package. No need for the extra split package here 🙏

it "CLI - Shows version" $ do
Stdout out <- command [] "cardano-wallet" ["--version"]
cabal <- readFile "../../cardano-wallet.cabal"
cabal `shouldContain` out
Copy link
Member

Choose a reason for hiding this comment

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

That's somewhat unsatisfactory haha ^^" ... Perhaps we can better have the bits extracting the version number from the cardano-wallet.cabal available in the libraries, or instead, expect the version to match a known version. We'll have to update that version number of each version bump, but I think that's a fair price to pay :)

forM_ [9, 12, 15, 18, 21, 24] $ \size -> it (show size) $ do
Stdout out <- command [] "cardano-wallet"
["mnemonic", "generate", "--size", show size]
length (splitOn " " out) `shouldBe` size
Copy link
Member

Choose a reason for hiding this comment

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

Would deserve some negative tests too I think (not saying this should be part of this PR, but for exhaustiveness)

walId <- createWallet ctx "CLI Wallet" mnemonics15
Stdout out <- command [] "cardano-wallet"
["wallet", "delete", "--port", "1337", walId ]
out `shouldNotContain` "CLI Wallet"
Copy link
Member

Choose a reason for hiding this comment

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

Interesting approach. I think we could add some special assertion function too here to verify the output even more deeply. The CLI do output some Ok or Error on stderr and, if any, output responses on stdout (without any noise). So in practice, we could even verify that whatever gets printed on stdout is always a valid JSON object.

The CmdResult allows us to check both stderr and stdout, and also response codes! Which is kinda cool. So we can definitely go crazy here 😛

Side-note: variable indentation --> not cool.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely there's room for going crazy and I had the same idea to check the somehow cast the output to JSON or maybe even ApiWallet (still the main intention here was to check if the approach works)

Side-note: variable indentation --> not cool.

it was not my intention :) it's just trying to comply with 80 chars rule...

@piotr-iohk piotr-iohk force-pushed the piotr/96/testing branch 2 times, most recently from 564a022 to 67e5dd6 Compare May 15, 2019 21:42
it "CLI - Shows help with --help" $ do
(Exit c, Stdout out) <- command [] "cardano-wallet" ["--help"]
out `shouldContain` "Cardano Wallet CLI"
c `shouldBe` ExitFailure 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder if this is expected...

Copy link
Member

Choose a reason for hiding this comment

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

No it's not. I noticed some days ago (and fixed but never pushed it actually :|) while I was trying to generate code-completion for the CLI. That's not right -> Let's have 0 here and a fix :)

@KtorZ KtorZ force-pushed the piotr/96/testing branch from 3505283 to e82e0e9 Compare May 16, 2019 10:06
@KtorZ KtorZ merged commit bae73e2 into master May 16, 2019
@iohk-bors iohk-bors bot deleted the piotr/96/testing branch May 16, 2019 11:59
Copy link
Contributor

@akegalj akegalj left a comment

Choose a reason for hiding this comment

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

looks good so far

@@ -149,7 +150,7 @@ Options:
Examples:
# Create a transaction and send 22 lovelace from wallet-id to specified addres
cardano-wallet transaction create \
--wallet-id 2512a00e9653fe49a44a5886202e24d77eeb998f \
2512a00e9653fe49a44a5886202e24d77eeb998f \
Copy link
Contributor

Choose a reason for hiding this comment

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

good catch, my mistake

specWithCluster :: SpecWith Context
specWithCluster = do
it "CLI - Can get a wallet" $ \ctx -> do
walId <- createWallet ctx "1st CLI Wallet" mnemonics15
Copy link
Contributor

Choose a reason for hiding this comment

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

why not use arbitrary name and mnemonics? (I can help with this if needed)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

¯_(ツ)_/¯

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One benefit in case of mnemonics is that they were all generated with https://iancoleman.io/bip39/ (i.e. using something that is outside of our codebase, which makes sense in terms of testing/verifying that they work)

let test size = it ("--size=" <> show size) $ do
(Exit c, Stdout out) <- command [] "cardano-wallet"
["mnemonic", "generate", "--size", show size]
length (words out) `shouldBe` size
Copy link
Contributor

Choose a reason for hiding this comment

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

we could even test is it valid bip39 here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hm, probably yes. But then we would be using the same code that generates the mnemonics to verify if they are valid (?) Then, not sure if there would be any additional value...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants