-
Notifications
You must be signed in to change notification settings - Fork 217
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
Conversation
1b91d3c
to
b9a78da
Compare
b9a78da
to
558666e
Compare
|
||
it "CLI - Can generate mnemonics with default size" $ do | ||
Stdout out <- command [] "cardano-wallet" ["mnemonic", "generate"] | ||
length (splitOn " " out) `shouldBe` 15 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
564a022
to
67e5dd6
Compare
it "CLI - Shows help with --help" $ do | ||
(Exit c, Stdout out) <- command [] "cardano-wallet" ["--help"] | ||
out `shouldContain` "Cardano Wallet CLI" | ||
c `shouldBe` ExitFailure 1 |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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 :)
There was a problem hiding this 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 \ |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
¯_(ツ)_/¯
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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...
Issue Number
#96
Overview
wallet create
))Comments