Skip to content

Commit

Permalink
Add CLI unit tests for transaction create --metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Sep 21, 2020
1 parent 2f8cc49 commit 2af98a3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/cli/cardano-wallet-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ test-suite unit
base
, cardano-wallet-cli
, cardano-wallet-core
, containers
, filepath
, hspec
, network-uri
, optparse-applicative
, QuickCheck
, shelley-spec-ledger
, temporary
, text
, text-class
Expand Down
26 changes: 26 additions & 0 deletions lib/cli/test/unit/Cardano/CLISpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Cardano.CLI
, cmdWalletCreate
, hGetLine
, hGetSensitiveLine
, metadataOption
, smashURLOption
)
import Cardano.Wallet.Api.Client
Expand All @@ -37,6 +38,10 @@ import Cardano.Wallet.Api.Client
, transactionClient
, walletClient
)
import Cardano.Wallet.Api.Types
( ApiT (..), ApiTxMetadata (..) )
import Cardano.Wallet.Primitive.Types
( TxMetadata (..) )
import Control.Concurrent
( forkFinally )
import Control.Concurrent.MVar
Expand Down Expand Up @@ -91,8 +96,10 @@ import Test.QuickCheck
import Test.Text.Roundtrip
( textRoundtrip )

import qualified Data.Map as Map
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import qualified Shelley.Spec.Ledger.MetaData as MD

spec :: Spec
spec = do
Expand Down Expand Up @@ -659,6 +666,25 @@ spec = do
, ( "relative", "/home/user", err )
]

describe "Tx Metadata JSON option" $ do
let parse arg = execParserPure defaultPrefs
(info metadataOption mempty) ["--metadata", arg]
let md = ApiT (TxMetadata (MD.MetaData (Map.singleton 42 (MD.S "hi"))))
let ok ex (Success res) = ex == getApiTxMetadata res
ok _ _ = False
let err (Failure _) = True
err _ = False
mapM_
(\(desc, arg, tst) -> it desc (parse arg `shouldSatisfy` tst))
[ ("valid", "{ \"42\": \"hi\" }", ok (Just md))
, ("malformed", "testing", err)
, ("malformed trailling", "{ \"0\": \"\" } arstneio", err)
, ("invalid", "{ \"json\": true }", err)
, ("null 1", "{ \"0\": null }", err)
, ("null 2", "null", ok Nothing)
, ("null 3", "{ }", ok (Just (ApiT mempty)))
]

where
backspace :: Text
backspace = T.singleton (toEnum 127)
Expand Down
2 changes: 2 additions & 0 deletions nix/.stack.nix/cardano-wallet-cli.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2af98a3

Please sign in to comment.