From d54252a6ce5a82b69a4f16a5e1c57101c6709afb Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Sat, 12 Sep 2020 10:57:19 +1000 Subject: [PATCH 01/12] Update check-bundle.rb to test linking of executables --- nix/linux-release.nix | 2 +- nix/macos-release.nix | 7 ++++++- scripts/check-bundle.rb | 21 ++++++++++++++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/nix/linux-release.nix b/nix/linux-release.nix index 2886d625f25..c6efef3b68a 100644 --- a/nix/linux-release.nix +++ b/nix/linux-release.nix @@ -21,7 +21,7 @@ let in pkgs.stdenv.mkDerivation { inherit name; buildInputs = with pkgs.buildPackages; [ gnutar gzip binutils ]; - checkInputs = [ pkgs.buildPackages.ruby ]; + checkInputs = with pkgs.buildPackages; [ ruby gnugrep glibc.bin ]; doCheck = true; phases = [ "buildPhase" "checkPhase" ]; tarname = "${name}-linux64.tar.gz"; diff --git a/nix/macos-release.nix b/nix/macos-release.nix index b702f8e62ac..64db193e027 100644 --- a/nix/macos-release.nix +++ b/nix/macos-release.nix @@ -21,7 +21,12 @@ let in pkgs.stdenv.mkDerivation { inherit name; buildInputs = with pkgs.buildPackages; [ gnutar gzip binutils ]; - checkInputs = [ pkgs.buildPackages.ruby ]; + checkInputs = with pkgs.buildPackages; [ + ruby + gnugrep + gnused + darwin.cctools + ]; doCheck = true; phases = [ "buildPhase" "checkPhase" ]; tarname = "${name}-macos64.tar.gz"; diff --git a/scripts/check-bundle.rb b/scripts/check-bundle.rb index b4c6da3ebb1..ecc38f0a8a9 100755 --- a/scripts/check-bundle.rb +++ b/scripts/check-bundle.rb @@ -3,6 +3,8 @@ ############################################################################ # Checks that every executable required in the release package is # present and works. +# On Linux it checks if executables are statically linked. +# On macOS it checks that there are no /nix/store dylibs. ############################################################################ require 'open3' @@ -33,15 +35,28 @@ def report(cmd, status) end cmd = "#{wallet} version" -ver, status = Open3.capture2("#{runner} #{cmd}") -report(cmd, status.to_i) +begin + ver, status = Open3.capture2("#{runner} #{cmd}") + report(cmd, status.to_i) +rescue Errno::ENOENT + report(cmd, 1) +end -tests[wallet].each do |cmd| +tests[wallet].unshift(wallet).each do |cmd| begin stdout_str, status = Open3.capture2("#{runner} #{cmd} --help") report(cmd, status.to_i) rescue Errno::ENOENT report(cmd, 1) + next + end + + if /darwin/ =~ RUBY_PLATFORM then + system("! otool -L `type -p #{cmd}` | sed 1d | grep nix"); + report("#{cmd} is free of /nix/store", $?.exitstatus) + elsif /linux/ =~ RUBY_PLATFORM then + system("! ldd `type -p #{cmd}` > /dev/null"); + report("#{cmd} is static linked", $?.exitstatus) end end From 9e7bbf50ff146ca12b2813cf4b0d6c0970789d61 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Sat, 12 Sep 2020 10:55:59 +1000 Subject: [PATCH 02/12] Fix dylib references of bundled programs on macOS Resolves #2134 --- nix/macos-release.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/nix/macos-release.nix b/nix/macos-release.nix index 64db193e027..1c506ecf3b3 100644 --- a/nix/macos-release.nix +++ b/nix/macos-release.nix @@ -20,7 +20,13 @@ let in pkgs.stdenv.mkDerivation { inherit name; - buildInputs = with pkgs.buildPackages; [ gnutar gzip binutils ]; + buildInputs = with pkgs.buildPackages; [ + gnutar + gzip + binutils + commonLib.haskell-nix-extra-packages.haskellBuildUtils.package + nix + ]; checkInputs = with pkgs.buildPackages; [ ruby gnugrep @@ -34,6 +40,7 @@ in pkgs.stdenv.mkDerivation { mkdir $name cp -nR ${concatMapStringsSep " " (exe: "${exe}/bin/*") exes} $name chmod -R 755 $name + ( cd $name; rewrite-libs . `ls -1 | grep -Fv .dylib` ) mkdir -p $out/nix-support tar -czf $out/$tarname $name From e43dace01a8dd4e6180e19ed74f471932cedc9b2 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Mon, 14 Sep 2020 17:26:55 +1000 Subject: [PATCH 03/12] Drop jormungandr/jcli from cardano-wallet-jormungandr release zips Looks like there is some issue in iohk-nix, and they aren't getting statically built on linux any more. --- release.nix | 8 +++----- scripts/check-bundle.rb | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/release.nix b/release.nix index fdd2d5abff8..082ac6245ee 100644 --- a/release.nix +++ b/release.nix @@ -183,20 +183,18 @@ let # Release distribution jobs - these all have a Hydra download link. # Which exes should be put in the release archive. - releaseContents = rec { + releaseContents = { jormungandr = [ "cardano-wallet-jormungandr" - "jormungandr" - "jormungandr-cli" ]; - cardanoNodeCommon = [ + shelley = [ + "cardano-wallet" "bech32" "cardano-address" "cardano-cli" "cardano-node" "cardano-tx" ]; - shelley = [ "cardano-wallet" ] ++ cardanoNodeCommon; }; # function to take a list of jobs by name from a jobset. diff --git a/scripts/check-bundle.rb b/scripts/check-bundle.rb index ecc38f0a8a9..43f14ee5b25 100755 --- a/scripts/check-bundle.rb +++ b/scripts/check-bundle.rb @@ -10,7 +10,7 @@ require 'open3' tests = { - "cardano-wallet-jormungandr" => [ "jormungandr", "jcli" ], + "cardano-wallet-jormungandr" => [ ], "cardano-wallet" => [ "cardano-node", "cardano-cli", "bech32", "cardano-tx", "cardano-address" ] } From dae5ba9ff6230fceae7e7f43ad106afc2394a749 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Wed, 9 Sep 2020 16:54:44 +1000 Subject: [PATCH 04/12] CLI: Add option "cardano-wallet transaction create --metadata=JSON" --- lib/cli/src/Cardano/CLI.hs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/cli/src/Cardano/CLI.hs b/lib/cli/src/Cardano/CLI.hs index 6530cbbcb3a..de0d003b068 100644 --- a/lib/cli/src/Cardano/CLI.hs +++ b/lib/cli/src/Cardano/CLI.hs @@ -54,6 +54,7 @@ module Cardano.CLI , syncToleranceOption , tlsOption , smashURLOption + , metadataOption -- * Option parsers for configuring tracing , LoggingOptions (..) @@ -128,6 +129,7 @@ import Cardano.Wallet.Api.Types , ApiPostRandomAddressData (..) , ApiT (..) , ApiTxId (ApiTxId) + , ApiTxMetadata (..) , ApiWallet , ByronWalletPostData (..) , ByronWalletStyle (..) @@ -687,6 +689,7 @@ data TransactionCreateArgs t = TransactionCreateArgs { _port :: Port "Wallet" , _id :: WalletId , _payments :: NonEmpty Text + , _metadata :: ApiTxMetadata } cmdTransactionCreate @@ -702,7 +705,8 @@ cmdTransactionCreate mkTxClient mkWalletClient = <$> portOption <*> walletIdArgument <*> fmap NE.fromList (some paymentOption) - exec (TransactionCreateArgs wPort wId wAddressAmounts) = do + <*> metadataOption + exec (TransactionCreateArgs wPort wId wAddressAmounts md) = do wPayments <- either (fail . getTextDecodingError) pure $ traverse (fromText @(AddressAmount Text)) wAddressAmounts res <- sendRequest wPort $ getWallet mkWalletClient $ ApiT wId @@ -715,6 +719,7 @@ cmdTransactionCreate mkTxClient mkWalletClient = (Aeson.object [ "payments" .= wPayments , "passphrase" .= ApiT wPwd + , "metadata" .= md ] ) Left _ -> @@ -733,7 +738,8 @@ cmdTransactionFees mkTxClient mkWalletClient = <$> portOption <*> walletIdArgument <*> fmap NE.fromList (some paymentOption) - exec (TransactionCreateArgs wPort wId wAddressAmounts) = do + <*> metadataOption + exec (TransactionCreateArgs wPort wId wAddressAmounts md) = do wPayments <- either (fail . getTextDecodingError) pure $ traverse (fromText @(AddressAmount Text)) wAddressAmounts res <- sendRequest wPort $ getWallet mkWalletClient $ ApiT wId @@ -742,7 +748,10 @@ cmdTransactionFees mkTxClient mkWalletClient = runClient wPort Aeson.encodePretty $ postTransactionFee mkTxClient (ApiT wId) - (Aeson.object [ "payments" .= wPayments ]) + (Aeson.object + [ "payments" .= wPayments + , "metadata" .= md + ]) Left _ -> handleResponse Aeson.encodePretty res @@ -1348,6 +1357,21 @@ transactionSubmitPayloadArgument = argumentT $ mempty <> metavar "BINARY_BLOB" <> help "hex-encoded binary blob of externally-signed transaction." +-- | +-- +-- Note: we decode the JSON just so that we can validate more client-side. +metadataOption :: Parser ApiTxMetadata +metadataOption = option txMetadataReader $ mempty + <> long "metadata" + <> metavar "JSON" + <> value (ApiTxMetadata Nothing) + <> help ("Application-specific transaction metadata as a JSON object. " + <> "The value must match the schema defined in the " + <> "cardano-wallet OpenAPI specification.") + +txMetadataReader :: ReadM ApiTxMetadata +txMetadataReader = eitherReader (Aeson.eitherDecode' . BL8.pack) + -- | addressIdArgument :: Parser Text addressIdArgument = argumentT $ mempty From cd8cf0bd21075c53849a8d931e5593b724fc8731 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Thu, 10 Sep 2020 19:52:26 +1000 Subject: [PATCH 05/12] Add integration test for transaction create --metadata --- .../Scenario/CLI/Shelley/Transactions.hs | 56 ++++++++++++++++--- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/lib/core-integration/src/Test/Integration/Scenario/CLI/Shelley/Transactions.hs b/lib/core-integration/src/Test/Integration/Scenario/CLI/Shelley/Transactions.hs index 106b25e7dbe..f22aeaebf42 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/CLI/Shelley/Transactions.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/CLI/Shelley/Transactions.hs @@ -15,6 +15,7 @@ import Cardano.CLI ( Port ) import Cardano.Wallet.Api.Types ( ApiFee (..) + , ApiT (..) , ApiTransaction , ApiWallet , DecodeAddress @@ -23,7 +24,7 @@ import Cardano.Wallet.Api.Types , getApiT ) import Cardano.Wallet.Primitive.Types - ( Direction (..), SortOrder (..), TxStatus (..) ) + ( Direction (..), SortOrder (..), TxMetadata (..), TxStatus (..) ) import Control.Monad ( forM_, join ) import Data.Generics.Internal.VL.Lens @@ -36,6 +37,8 @@ import Data.Proxy ( Proxy (..) ) import Data.Quantity ( Quantity (..) ) +import Data.Text + ( Text ) import Data.Text.Class ( showT ) import Data.Time.Utils @@ -96,7 +99,9 @@ import Test.Integration.Framework.TestData , wildcardsWalletName ) +import qualified Data.Map as Map import qualified Data.Text as T +import qualified Shelley.Spec.Ledger.MetaData as MD spec :: forall n t. ( KnownCommand t @@ -110,16 +115,17 @@ spec = describe "SHELLEY_CLI_TRANSACTIONS" $ do wDest <- emptyWallet ctx let amt = fromIntegral minUTxOValue - args <- postTxArgs ctx wSrc wDest amt + args <- postTxArgs ctx wSrc wDest amt Nothing Stdout feeOut <- postTransactionFeeViaCLI @t ctx args ApiFee (Quantity feeMin) (Quantity feeMax) <- expectValidJSON Proxy feeOut - txJson <- postTxViaCLI ctx wSrc wDest amt + txJson <- postTxViaCLI ctx wSrc wDest amt Nothing verify txJson [ expectCliField (#amount . #getQuantity) (between (feeMin + amt, feeMax + amt)) , expectCliField (#direction . #getApiT) (`shouldBe` Outgoing) , expectCliField (#status . #getApiT) (`shouldBe` Pending) + , expectCliField (#metadata . #getApiTxMetadata) (`shouldBe` Nothing) ] -- verify balance on src wallet @@ -295,6 +301,36 @@ spec = describe "SHELLEY_CLI_TRANSACTIONS" $ do out `shouldBe` "" c `shouldBe` ExitFailure 1 + it "TRANSMETA_CREATE_01 - Transaction with metadata via CLI" $ \ctx -> do + (wSrc, wDest) <- (,) <$> fixtureWallet ctx <*> emptyWallet ctx + let amt = 100000 + let md = Just "{ \"1\": \"hello\" }" + let expected = Just (ApiT (TxMetadata (MD.MetaData (Map.singleton 1 (MD.S "hello"))))) + + args <- postTxArgs ctx wSrc wDest amt md + Stdout feeOut <- postTransactionFeeViaCLI @t ctx args + ApiFee (Quantity feeMin) (Quantity feeMax) <- expectValidJSON Proxy feeOut + + txJson <- postTxViaCLI ctx wSrc wDest amt md + verify txJson + [ expectCliField (#amount . #getQuantity) + (between (feeMin + amt, feeMax + amt)) + , expectCliField (#direction . #getApiT) (`shouldBe` Outgoing) + , expectCliField (#status . #getApiT) (`shouldBe` Pending) + , expectCliField (#metadata . #getApiTxMetadata) (`shouldBe` expected) + ] + + eventually "metadata is confirmed in transaction list" $ do + (Exit code, Stdout out, Stderr err) <- + listTransactionsViaCLI @t ctx [T.unpack $ wSrc ^. walletId] + err `shouldBe` "Ok.\n" + code `shouldBe` ExitSuccess + outJson <- expectValidJSON (Proxy @([ApiTransaction n])) out + verify outJson + [ expectCliListField 0 (#metadata . #getApiTxMetadata) (`shouldBe` expected) + , expectCliListField 0 (#status . #getApiT) (`shouldBe` InLedger) + ] + describe "TRANS_ESTIMATE_08 - Invalid addresses" $ do forM_ matrixInvalidAddrs $ \(title, addr, errMsg) -> it title $ \ctx -> do wSrc <- emptyWallet ctx @@ -679,7 +715,7 @@ spec = describe "SHELLEY_CLI_TRANSACTIONS" $ do let wSrcId = T.unpack (wSrc ^. walletId) -- post transaction - txJson <- postTxViaCLI ctx wSrc wDest minUTxOValue + txJson <- postTxViaCLI ctx wSrc wDest minUTxOValue Nothing verify txJson [ expectCliField (#direction . #getApiT) (`shouldBe` Outgoing) , expectCliField (#status . #getApiT) (`shouldBe` Pending) @@ -734,7 +770,7 @@ spec = describe "SHELLEY_CLI_TRANSACTIONS" $ do -- post tx wSrc <- fixtureWallet ctx wDest <- emptyWallet ctx - txJson <- postTxViaCLI ctx wSrc wDest minUTxOValue + txJson <- postTxViaCLI ctx wSrc wDest minUTxOValue Nothing -- try to forget from different wallet widDiff <- emptyWallet' ctx @@ -801,9 +837,10 @@ spec = describe "SHELLEY_CLI_TRANSACTIONS" $ do -> ApiWallet -> ApiWallet -> Natural + -> Maybe Text -> IO (ApiTransaction n) - postTxViaCLI ctx wSrc wDest amt = do - args <- postTxArgs ctx wSrc wDest amt + postTxViaCLI ctx wSrc wDest amt md = do + args <- postTxArgs ctx wSrc wDest amt md -- post transaction (c, out, err) <- postTransactionViaCLI @t ctx "cardano-wallet" args @@ -816,14 +853,15 @@ spec = describe "SHELLEY_CLI_TRANSACTIONS" $ do -> ApiWallet -> ApiWallet -> Natural + -> Maybe Text -> IO [String] - postTxArgs ctx wSrc wDest amt = do + postTxArgs ctx wSrc wDest amt md = do addr:_ <- listAddresses @n ctx wDest let addrStr = encodeAddress @n (getApiT $ fst $ addr ^. #id) return $ T.unpack <$> [ wSrc ^. walletId , "--payment", T.pack (show amt) <> "@" <> addrStr - ] + ] ++ maybe [] (\json -> ["--metadata", json]) md fixtureWallet' :: Context t -> IO String fixtureWallet' = fmap (T.unpack . view walletId) . fixtureWallet From 074379eaef6582a206669113b8efc98ec7200f14 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Tue, 15 Sep 2020 12:14:43 +1000 Subject: [PATCH 06/12] Update CLISpec golden tests --- lib/cli/test/unit/Cardano/CLISpec.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/cli/test/unit/Cardano/CLISpec.hs b/lib/cli/test/unit/Cardano/CLISpec.hs index b46c39f1aea..82ce507b167 100644 --- a/lib/cli/test/unit/Cardano/CLISpec.hs +++ b/lib/cli/test/unit/Cardano/CLISpec.hs @@ -262,7 +262,7 @@ spec = do ["transaction", "create", "--help"] `shouldShowUsage` [ "Usage: transaction create [--port INT] WALLET_ID" - , " --payment PAYMENT" + , " --payment PAYMENT [--metadata JSON]" , " Create and submit a new transaction." , "" , "Available options:" @@ -272,10 +272,15 @@ spec = do , " --payment PAYMENT address to send to and amount to send" , " separated by @, e.g." , " '@
'" + , " --metadata JSON Application-specific transaction" + , " metadata as a JSON object. The value" + , " must match the schema defined in the" + , " cardano-wallet OpenAPI specification." ] ["transaction", "fees", "--help"] `shouldShowUsage` [ "Usage: transaction fees [--port INT] WALLET_ID --payment PAYMENT" + , " [--metadata JSON]" , " Estimate fees for a transaction." , "" , "Available options:" @@ -285,6 +290,10 @@ spec = do , " --payment PAYMENT address to send to and amount to send" , " separated by @, e.g." , " '@
'" + , " --metadata JSON Application-specific transaction" + , " metadata as a JSON object. The value" + , " must match the schema defined in the" + , " cardano-wallet OpenAPI specification." ] ["transaction", "list", "--help"] `shouldShowUsage` From 7498249f2a3054267b5c605929a1c91d918bfcd3 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Tue, 15 Sep 2020 15:13:28 +1000 Subject: [PATCH 07/12] Add CLI unit tests for transaction create --metadata --- lib/cli/cardano-wallet-cli.cabal | 2 ++ lib/cli/test/unit/Cardano/CLISpec.hs | 26 ++++++++++++++++++++++++++ nix/.stack.nix/cardano-wallet-cli.nix | 2 ++ 3 files changed, 30 insertions(+) diff --git a/lib/cli/cardano-wallet-cli.cabal b/lib/cli/cardano-wallet-cli.cabal index a265e4c78fd..49fa4a6e1dd 100644 --- a/lib/cli/cardano-wallet-cli.cabal +++ b/lib/cli/cardano-wallet-cli.cabal @@ -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 diff --git a/lib/cli/test/unit/Cardano/CLISpec.hs b/lib/cli/test/unit/Cardano/CLISpec.hs index 82ce507b167..7aa61c9daf5 100644 --- a/lib/cli/test/unit/Cardano/CLISpec.hs +++ b/lib/cli/test/unit/Cardano/CLISpec.hs @@ -28,6 +28,7 @@ import Cardano.CLI , cmdWalletCreate , hGetLine , hGetSensitiveLine + , metadataOption , smashURLOption ) import Cardano.Wallet.Api.Client @@ -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 @@ -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 @@ -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) diff --git a/nix/.stack.nix/cardano-wallet-cli.nix b/nix/.stack.nix/cardano-wallet-cli.nix index c51a6a51801..0916ad03f8a 100644 --- a/nix/.stack.nix/cardano-wallet-cli.nix +++ b/nix/.stack.nix/cardano-wallet-cli.nix @@ -55,11 +55,13 @@ (hsPkgs."base" or (errorHandler.buildDepError "base")) (hsPkgs."cardano-wallet-cli" or (errorHandler.buildDepError "cardano-wallet-cli")) (hsPkgs."cardano-wallet-core" or (errorHandler.buildDepError "cardano-wallet-core")) + (hsPkgs."containers" or (errorHandler.buildDepError "containers")) (hsPkgs."filepath" or (errorHandler.buildDepError "filepath")) (hsPkgs."hspec" or (errorHandler.buildDepError "hspec")) (hsPkgs."network-uri" or (errorHandler.buildDepError "network-uri")) (hsPkgs."optparse-applicative" or (errorHandler.buildDepError "optparse-applicative")) (hsPkgs."QuickCheck" or (errorHandler.buildDepError "QuickCheck")) + (hsPkgs."shelley-spec-ledger" or (errorHandler.buildDepError "shelley-spec-ledger")) (hsPkgs."temporary" or (errorHandler.buildDepError "temporary")) (hsPkgs."text" or (errorHandler.buildDepError "text")) (hsPkgs."text-class" or (errorHandler.buildDepError "text-class")) From 3665332826066b1935d603db418ea1c8cedafcff Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Wed, 16 Sep 2020 12:37:59 +0200 Subject: [PATCH 08/12] Disable STAKE_POOLS_* tests due to #2140 --- .../Integration/Jormungandr/Scenario/API/StakePools.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/StakePools.hs b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/StakePools.hs index 93d9d143683..a73b321a077 100644 --- a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/StakePools.hs +++ b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/StakePools.hs @@ -331,6 +331,9 @@ spec = do ] it "STAKE_POOLS_JOIN_04 - Rewards accumulate and stop" $ \(_,_,ctx) -> do + + pendingWith "https://github.com/input-output-hk/cardano-wallet/issues/2140" + w <- fixtureWallet ctx (_, p:_) <- eventually "Stake pools are listed" $ unsafeRequest @[ApiStakePool] ctx Link.listJormungandrStakePools Empty @@ -365,6 +368,9 @@ spec = do it "STAKE_POOLS_JOIN_04 -\ \Delegate, stop in the next epoch, and still earn rewards" $ \(_,_,ctx) -> do + + pendingWith "https://github.com/input-output-hk/cardano-wallet/issues/2140" + w <- fixtureWallet ctx (_, p1:_) <- eventually "Stake pools are listed" $ unsafeRequest @[ApiStakePool] ctx Link.listJormungandrStakePools Empty @@ -680,6 +686,9 @@ spec = do expectErrorMessage errMsg403WrongPass r it "STAKE_POOL_NEXT_01 - Can join/re-join another but cannot quit stake pool" $ \(_,_,ctx) -> do + + pendingWith "https://github.com/input-output-hk/cardano-wallet/issues/2140" + (_, p1:p2:_) <- eventually "Stake pools are listed" $ unsafeRequest @[ApiStakePool] ctx Link.listJormungandrStakePools Empty w <- fixtureWallet ctx From 6e276af1c97ee31f4d2b7c7aadf5d206f75526c2 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Tue, 15 Sep 2020 11:15:11 +0200 Subject: [PATCH 09/12] Remove hard-coded mnemonics in case not necessary in integration tests --- .../src/Test/Integration/Framework/DSL.hs | 38 +++- .../Test/Integration/Framework/TestData.hs | 47 +---- .../Integration/Scenario/API/Byron/Wallets.hs | 3 +- .../Scenario/API/Shelley/Wallets.hs | 170 ++++++------------ .../Jormungandr/Scenario/API/Transactions.hs | 4 +- 5 files changed, 99 insertions(+), 163 deletions(-) diff --git a/lib/core-integration/src/Test/Integration/Framework/DSL.hs b/lib/core-integration/src/Test/Integration/Framework/DSL.hs index 4a1eb13df2d..cf6dfdeac12 100644 --- a/lib/core-integration/src/Test/Integration/Framework/DSL.hs +++ b/lib/core-integration/src/Test/Integration/Framework/DSL.hs @@ -15,6 +15,7 @@ module Test.Integration.Framework.DSL ( Context(..) + , MnemonicLength(..) , KnownCommand(..) , TxDescription(..) @@ -62,6 +63,8 @@ module Test.Integration.Framework.DSL , emptyWalletWith , emptyByronWalletFromXPrvWith , rewardWallet + , genMnemonics + , genMnemonics' , getFromResponse , getFromResponseList , json @@ -142,9 +145,14 @@ module Test.Integration.Framework.DSL import Cardano.CLI ( Port (..) ) import Cardano.Mnemonic - ( MkSomeMnemonic (..) + ( ConsistentEntropy + , EntropySize + , MkSomeMnemonic (..) , Mnemonic + , MnemonicWords , SomeMnemonic (..) + , ValidChecksumSize + , ValidEntropySize , entropyToMnemonic , genEntropy , mnemonicToText @@ -519,6 +527,28 @@ walletId = minUTxOValue :: Natural minUTxOValue = 1_000_000 +genMnemonics + :: forall mw ent csz. + ( ConsistentEntropy ent mw csz + , ValidEntropySize ent + , ValidChecksumSize ent csz + , ent ~ EntropySize mw + , mw ~ MnemonicWords ent + ) + => IO [Text] +genMnemonics = + mnemonicToText . entropyToMnemonic @mw <$> genEntropy + +data MnemonicLength = M9 | M12 | M15 | M18 | M21 | M24 deriving (Show) + +genMnemonics' :: MnemonicLength -> IO [Text] +genMnemonics' M9 = genMnemonics @9 +genMnemonics' M12 = genMnemonics @12 +genMnemonics' M15 = genMnemonics @15 +genMnemonics' M18 = genMnemonics @18 +genMnemonics' M21 = genMnemonics @21 +genMnemonics' M24 = genMnemonics @24 + getTxId :: (ApiTransaction n) -> String getTxId tx = T.unpack $ toUrlPiece $ ApiTxId (tx ^. #id) @@ -1642,12 +1672,12 @@ postTransactionViaCLI ctx passphrase args = do hClose stdin out <- TIO.hGetContents stdout err <- TIO.hGetContents stderr - -- For some reason, when - -- - waitForProcess is called before hGetContents + -- For some reason, when + -- - waitForProcess is called before hGetContents -- - os is windows -- - postTransactionViaCLI was called with >= 5 outputs -- waitForProcess blocks indefinetely. Hence we call waitForProcess - -- last. + -- last. c <- waitForProcess h return (c, T.unpack out, err) diff --git a/lib/core-integration/src/Test/Integration/Framework/TestData.hs b/lib/core-integration/src/Test/Integration/Framework/TestData.hs index 5a6cdba65c7..2a7a88745ae 100644 --- a/lib/core-integration/src/Test/Integration/Framework/TestData.hs +++ b/lib/core-integration/src/Test/Integration/Framework/TestData.hs @@ -11,15 +11,7 @@ module Test.Integration.Framework.TestData , invalidMnemonics15 , japaneseMnemonics12 , japaneseMnemonics15 - , mnemonics3 - , mnemonics6 - , mnemonics9 - , mnemonics12 - , mnemonics15 , notInDictMnemonics15 - , mnemonics18 - , mnemonics21 - , mnemonics24 , specMnemonicByron , specMnemonicSentence , specMnemonicSecondFactor @@ -106,41 +98,6 @@ falseWalletIds = , ("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"] @@ -240,7 +197,9 @@ payloadWith' name mnemonics gap = Json [json| { simplePayload :: Payload simplePayload = Json [json| { "name": "Secure Wallet", - "mnemonic_sentence": #{mnemonics21}, + "mnemonic_sentence": ["click", "puzzle", "athlete", "morning", "fold", "retreat", + "across", "timber", "essay", "drill", "finger", "erase", "galaxy", + "spoon", "swift", "eye", "awesome", "shrimp", "depend", "zebra", "token"], "passphrase": #{fixturePassphrase} } |] diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Byron/Wallets.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Byron/Wallets.hs index d2b40cab4d6..d65f7b0a6a8 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Byron/Wallets.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Byron/Wallets.hs @@ -76,6 +76,7 @@ import Test.Integration.Framework.DSL , expectWalletUTxO , fixturePassphrase , fixturePassphraseEncrypted + , genMnemonics , getFromResponse , json , request @@ -89,7 +90,6 @@ import Test.Integration.Framework.TestData , errMsg403WrongPass , errMsg404NoWallet , kanjiWalletName - , mnemonics12 , polishWalletName , russianWalletName , updateEmptyPassPayload @@ -312,6 +312,7 @@ spec = describe "BYRON_WALLETS" $ do ] forM_ matrix $ \(title, passphrase, expectations) -> it title $ \ctx -> do + mnemonics12 <- genMnemonics @12 let payload = Json [json| { "name": "Secure Wallet", "mnemonic_sentence": #{mnemonics12}, diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Wallets.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Wallets.hs index 4b87dde8f7b..7223e85b4cc 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Wallets.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Wallets.hs @@ -17,15 +17,7 @@ module Test.Integration.Scenario.API.Shelley.Wallets import Prelude import Cardano.Mnemonic - ( ConsistentEntropy - , EntropySize - , MnemonicWords - , ValidChecksumSize - , ValidEntropySize - , entropyToMnemonic - , genEntropy - , mnemonicToText - ) + ( entropyToMnemonic, genEntropy, mnemonicToText ) import Cardano.Wallet.Api.Types ( AddressAmount (..) , ApiByronWallet @@ -77,6 +69,7 @@ import Test.Hspec.Extra import Test.Integration.Framework.DSL ( Context (..) , Headers (..) + , MnemonicLength (..) , Payload (..) , emptyByronWalletWith , emptyRandomWallet @@ -91,6 +84,8 @@ import Test.Integration.Framework.DSL , expectWalletUTxO , fixturePassphrase , fixtureWallet + , genMnemonics + , genMnemonics' , getFromResponse , json , listAddresses @@ -110,12 +105,6 @@ import Test.Integration.Framework.TestData , errMsg406 , errMsg415 , kanjiWalletName - , mnemonics12 - , mnemonics15 - , mnemonics18 - , mnemonics21 - , mnemonics24 - , mnemonics9 , payloadWith , payloadWith' , polishWalletName @@ -141,10 +130,12 @@ spec :: forall n t. ) => SpecWith (Context t) spec = describe "SHELLEY_WALLETS" $ do it "WALLETS_CREATE_01 - Create a wallet" $ \ctx -> do + m15 <- genMnemonics @15 + m12 <- genMnemonics @12 let payload = Json [json| { "name": "1st Wallet", - "mnemonic_sentence": #{mnemonics15}, - "mnemonic_second_factor": #{mnemonics12}, + "mnemonic_sentence": #{m15}, + "mnemonic_second_factor": #{m12}, "passphrase": #{fixturePassphrase}, "address_pool_gap": 30 } |] @@ -160,8 +151,6 @@ spec = describe "SHELLEY_WALLETS" $ do , expectField (#balance . #getApiT . #reward) (`shouldBe` Quantity 0) , expectField #delegation (`shouldBe` notDelegating []) - , expectField - walletId (`shouldBe` "2cf060fe53e4e0593f145f22b858dfc60676d4ab") , expectField #passphrase (`shouldNotBe` Nothing) ] let wid = getFromResponse id r @@ -276,9 +265,10 @@ spec = describe "SHELLEY_WALLETS" $ do ] it "WALLETS_CREATE_03,09 - Cannot create wallet that exists" $ \ctx -> do + m21 <- genMnemonics @21 let payload = Json [json| { "name": "Some Wallet", - "mnemonic_sentence": #{mnemonics21}, + "mnemonic_sentence": #{m21}, "passphrase": #{fixturePassphrase} } |] r1 <- request @ApiWallet ctx (Link.postWallet @'Shelley) Default payload @@ -344,9 +334,10 @@ spec = describe "SHELLEY_WALLETS" $ do ) ] forM_ matrix $ \(title, walName, expectations) -> it title $ \ctx -> do + m24 <- genMnemonics @24 let payload = Json [json| { "name": #{walName}, - "mnemonic_sentence": #{mnemonics24}, + "mnemonic_sentence": #{m24}, "passphrase": #{fixturePassphrase} } |] r <- request @ApiWallet ctx (Link.postWallet @'Shelley) Default payload @@ -354,103 +345,63 @@ spec = describe "SHELLEY_WALLETS" $ do describe "WALLETS_CREATE_05 - Mnemonics" $ do let matrix = - [ ( "15 mnemonic words", mnemonics15 - , [ expectResponseCode @IO HTTP.status201 - , expectField walletId - (`shouldBe` "b062e8ccf3685549b6c489a4e94966bc4695b75b") - ] - ) - , ( "18 mnemonic words", mnemonics18 - , [ expectResponseCode @IO HTTP.status201 - , expectField walletId - (`shouldBe` "f52ee0daaefd75a0212d70c9fbe15ee8ada9fc11") - ] - ) - , ( "21 mnemonic words" , mnemonics21 - , [ expectResponseCode @IO HTTP.status201 - , expectField walletId - (`shouldBe` "7e8c1af5ff2218f388a313f9c70f0ff0550277e4") - ] - ) - , ( "24 mnemonic words", mnemonics24 - , [ expectResponseCode @IO HTTP.status201 - , expectField walletId - (`shouldBe` "a6b6625cd2bfc51a296b0933f77020991cc80374") - ] - ) + [ ( "15 mnemonic words", M15 ) + , ( "18 mnemonic words", M18 ) + , ( "21 mnemonic words", M21 ) + , ( "24 mnemonic words", M24 ) ] - forM_ matrix $ \(title, mnemonics, expectations) -> it title $ \ctx -> do + forM_ matrix $ \(title, mnemonics) -> it title $ \ctx -> do + m <- genMnemonics' mnemonics let payload = Json [json| { "name": "Just a łallet", - "mnemonic_sentence": #{mnemonics}, + "mnemonic_sentence": #{m}, "passphrase": #{fixturePassphrase} } |] r <- request @ApiWallet ctx (Link.postWallet @'Shelley) Default payload - verify r expectations + verify r [ expectResponseCode @IO HTTP.status201 ] describe "WALLETS_CREATE_06 - Mnemonics second factor" $ do let matrix = - [ ( "9 mnemonic words", mnemonics9 - , [ expectResponseCode @IO HTTP.status201 - , expectField walletId - (`shouldBe` "4b1a865e39d1006efb99f538b05ea2343b567108") - ] - ) - , ( "12 mnemonic words", mnemonics12 - , [ expectResponseCode @IO HTTP.status201 - , expectField walletId - (`shouldBe` "2cf060fe53e4e0593f145f22b858dfc60676d4ab") - ] - ) + [ ( "9 mnemonic words", M9 ) + , ( "12 mnemonic words", M12 ) ] - forM_ matrix $ \(title, mnemonics, expectations) -> it title $ \ctx -> do + forM_ matrix $ \(title, mnemonics) -> it title $ \ctx -> do + m15 <- genMnemonics' M15 + mSecondFactor <- genMnemonics' mnemonics + let payload = Json [json| { "name": "Just a łallet", - "mnemonic_sentence": #{mnemonics15}, - "mnemonic_second_factor": #{mnemonics}, + "mnemonic_sentence": #{m15}, + "mnemonic_second_factor": #{mSecondFactor}, "passphrase": #{fixturePassphrase} } |] r <- request @ApiWallet ctx (Link.postWallet @'Shelley) Default payload - verify r expectations + verify r [ expectResponseCode @IO HTTP.status201 ] describe "WALLETS_CREATE_07 - Passphrase" $ do let minLength = passphraseMinLength (Proxy @"raw") let maxLength = passphraseMaxLength (Proxy @"raw") let matrix = [ ( show minLength ++ " char long" - , T.pack (replicate minLength 'ź') - , [ expectResponseCode @IO HTTP.status201 - ] - ) + , T.pack (replicate minLength 'ź') ) , ( show maxLength ++ " char long" - , T.pack (replicate maxLength 'ą') - , [ expectResponseCode @IO HTTP.status201 ] - ) - , ( "Russian passphrase", russianWalletName - , [ expectResponseCode @IO HTTP.status201 ] - ) - , ( "Polish passphrase", polishWalletName - , [ expectResponseCode @IO HTTP.status201 ] - ) - , ( "Kanji passphrase", kanjiWalletName - , [ expectResponseCode @IO HTTP.status201 ] - ) - , ( "Arabic passphrase", arabicWalletName - , [ expectResponseCode @IO HTTP.status201 ] - ) - , ( "Wildcards passphrase", wildcardsWalletName - , [ expectResponseCode @IO HTTP.status201 ] - ) + , T.pack (replicate maxLength 'ą') ) + , ( "Russian passphrase", russianWalletName ) + , ( "Polish passphrase", polishWalletName ) + , ( "Kanji passphrase", kanjiWalletName ) + , ( "Arabic passphrase", arabicWalletName ) + , ( "Wildcards passphrase", wildcardsWalletName ) ] - forM_ matrix $ \(title, passphrase, expectations) -> it title $ \ctx -> do + forM_ matrix $ \(title, passphrase) -> it title $ \ctx -> do + m24 <- genMnemonics @24 let payload = Json [json| { "name": "Secure Wallet", - "mnemonic_sentence": #{mnemonics24}, + "mnemonic_sentence": #{m24}, "passphrase": #{passphrase} } |] r <- request @ApiWallet ctx (Link.postWallet @'Shelley) Default payload - verify r expectations + verify r [ expectResponseCode @IO HTTP.status201 ] describe "WALLETS_CREATE_08 - address_pool_gap" $ do let addrPoolMin = fromIntegral @_ @Int $ getAddressPoolGap minBound @@ -470,7 +421,8 @@ spec = describe "SHELLEY_WALLETS" $ do ) ] forM_ matrix $ \(title, addrPoolGap, expectations) -> it title $ \ctx -> do - let payload = payloadWith' "Secure Wallet" mnemonics24 (fromIntegral addrPoolGap) + m24 <- genMnemonics @24 + let payload = payloadWith' "Secure Wallet" m24 (fromIntegral addrPoolGap) rW <- request @ApiWallet ctx (Link.postWallet @'Shelley) Default payload verify rW expectations -- FIXME: ADP-436 @@ -478,16 +430,15 @@ spec = describe "SHELLEY_WALLETS" $ do -- let w = getFromResponse id rW -- rA <- request @[ApiAddress n] ctx -- (Link.listAddresses @'Shelley w) Default Empty - -- _ <- request @ApiWallet ctx - -- (Link.deleteWallet @'Shelley w) Default Empty -- verify rA -- [ expectListSize addrPoolGap -- ] it "WALLETS_CREATE_08 - default address_pool_gap" $ \ctx -> do + m21 <- genMnemonics @21 let payload = Json [json| { "name": "Secure Wallet", - "mnemonic_sentence": #{mnemonics21}, + "mnemonic_sentence": #{m21}, "passphrase": "Secure passphrase" } |] r <- request @ApiWallet ctx (Link.postWallet @'Shelley) Default payload @@ -526,9 +477,10 @@ spec = describe "SHELLEY_WALLETS" $ do ) ] forM_ matrix $ \(title, headers, expectations) -> it title $ \ctx -> do + m21 <- genMnemonics @21 let payload = Json [json| { "name": "Secure Wallet", - "mnemonic_sentence": #{mnemonics21}, + "mnemonic_sentence": #{m21}, "passphrase": "Secure passphrase" } |] r <- request @ApiWallet ctx (Link.postWallet @'Shelley) headers payload @@ -568,10 +520,12 @@ spec = describe "SHELLEY_WALLETS" $ do expectErrorMessage (errMsg404NoWallet $ w ^. walletId) rg it "WALLETS_LIST_01 - Created a wallet can be listed" $ \ctx -> do + m18 <- genMnemonics @18 + m9 <- genMnemonics @9 let payload = Json [json| { "name": "Wallet to be listed", - "mnemonic_sentence": #{mnemonics18}, - "mnemonic_second_factor": #{mnemonics9}, + "mnemonic_sentence": #{m18}, + "mnemonic_second_factor": #{m9}, "passphrase": #{fixturePassphrase}, "address_pool_gap": 20 } |] @@ -592,13 +546,14 @@ spec = describe "SHELLEY_WALLETS" $ do , expectListField 0 (#balance . #getApiT . #reward) (`shouldBe` Quantity 0) , expectListField 0 #delegation (`shouldBe` notDelegating []) - , expectListField 0 walletId - (`shouldBe` "dfe87fcf0560fb57937a6468ea51e860672fad79") ] it "WALLETS_LIST_01 - Wallets are listed from oldest to newest" $ \ctx -> do - let walletDetails = [("1", mnemonics15), ("2", mnemonics18) - , ("3", mnemonics21)] + m15 <- genMnemonics @15 + m18 <- genMnemonics @18 + m21 <- genMnemonics @21 + let walletDetails = [("1", m15), ("2", m18) + , ("3", m21)] forM_ walletDetails $ \(name, mnemonics) -> do let payload = payloadWith name mnemonics request @ApiWallet ctx (Link.postWallet @'Shelley) Default payload @@ -850,9 +805,10 @@ spec = describe "SHELLEY_WALLETS" $ do , ( "Wildcards passphrase", wildcardsWalletName ) ] forM_ matrix $ \(title, oldPass) -> it title $ \ctx -> do + m24 <- genMnemonics @24 let createPayload = Json [json| { "name": "Name of the wallet", - "mnemonic_sentence": #{mnemonics24}, + "mnemonic_sentence": #{m24}, "passphrase": #{oldPass} } |] (_, w) <- unsafeRequest @ApiWallet ctx @@ -1299,15 +1255,3 @@ spec = describe "SHELLEY_WALLETS" $ do , expectField (#tip . #slotNumber . #getApiT) (`shouldBe` slotNum) , expectField (#tip . #height) (`shouldBe` blockHeight) ] - where - genMnemonics - :: forall mw ent csz. - ( ConsistentEntropy ent mw csz - , ValidEntropySize ent - , ValidChecksumSize ent csz - , ent ~ EntropySize mw - , mw ~ MnemonicWords ent - ) - => IO [Text] - genMnemonics = - mnemonicToText . entropyToMnemonic @mw <$> genEntropy diff --git a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs index 8b4b97523e2..d476396b8c0 100644 --- a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs +++ b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs @@ -94,6 +94,7 @@ import Test.Integration.Framework.DSL as DSL , fixtureRandomWallet , fixtureRawTx , fixtureWallet + , genMnemonics , getFromResponse , json , listAddresses @@ -103,7 +104,7 @@ import Test.Integration.Framework.DSL as DSL , walletId ) import Test.Integration.Framework.TestData - ( errMsg400MalformedTxPayload, errMsg404CannotFindTx, mnemonics15 ) + ( errMsg400MalformedTxPayload, errMsg404CannotFindTx ) import Test.Integration.Jcli ( getBlock0H ) import Test.QuickCheck @@ -483,6 +484,7 @@ fixtureExternalTx ctx toSend = do let (Just keysAddrChng) = isOwned st' (rootXPrv, pwd) addrChng -- we create destination empty wallet + mnemonics15 <- genMnemonics @15 let createWallet = Json [json| { "name": "Destination Wallet", "mnemonic_sentence": #{mnemonics15}, From 038c36594579dce16a42f895bda3d60c4e2db132 Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Tue, 15 Sep 2020 13:22:26 +0200 Subject: [PATCH 10/12] Remove Shelley specific transaction suite. Add few more basic transaction tests to Jormungandr suite. --- lib/jormungandr/test/integration/Main.hs | 6 +- .../Jormungandr/Scenario/API/Transactions.hs | 188 +++++++++++++++++- 2 files changed, 188 insertions(+), 6 deletions(-) diff --git a/lib/jormungandr/test/integration/Main.hs b/lib/jormungandr/test/integration/Main.hs index 3dc9f0ce32c..e9fc203981a 100644 --- a/lib/jormungandr/test/integration/Main.hs +++ b/lib/jormungandr/test/integration/Main.hs @@ -117,7 +117,6 @@ import qualified Test.Integration.Scenario.API.Byron.Wallets as ByronWallets import qualified Test.Integration.Scenario.API.Network as Network import qualified Test.Integration.Scenario.API.Shelley.Addresses as Addresses import qualified Test.Integration.Scenario.API.Shelley.HWWallets as HWWallets -import qualified Test.Integration.Scenario.API.Shelley.Transactions as Transactions import qualified Test.Integration.Scenario.API.Shelley.Wallets as Wallets import qualified Test.Integration.Scenario.CLI.Miscellaneous as MiscellaneousCLI import qualified Test.Integration.Scenario.CLI.Network as NetworkCLI @@ -142,7 +141,6 @@ main = withUtf8Encoding $ withLogging Nothing Info $ \(_, tr) -> do describe "API Specifications" $ specWithServer @n tr $ do withCtxOnly $ Addresses.spec @n - withCtxOnly $ Transactions.spec @n withCtxOnly $ Wallets.spec @n withCtxOnly $ ByronWallets.spec @n withCtxOnly $ ByronTransactions.spec @n @@ -191,10 +189,10 @@ specWithServer tr = aroundAll withContext . after (tearDown . thd3) let setupContext wAddr nPort np = do let baseUrl = "http://" <> T.pack (show wAddr) <> "/" logInfo tr baseUrl - let sixtySeconds = 60*1000*1000 -- 60s in microseconds + let fiveMinutes = 300*1000*1000 -- 5min in microseconds manager <- (baseUrl,) <$> newManager (defaultManagerSettings { managerResponseTimeout = - responseTimeoutMicro sixtySeconds + responseTimeoutMicro fiveMinutes }) let feePolicy = getFeePolicy $ txParameters diff --git a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs index d476396b8c0..6d1c82349dc 100644 --- a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs +++ b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs @@ -22,7 +22,7 @@ import Cardano.Mnemonic ( MkSomeMnemonic (..), mnemonicToText ) import Cardano.Wallet.Api.Types ( AddressAmount (..) - , ApiFee + , ApiFee (..) , ApiT (..) , ApiTransaction (..) , ApiTxId (..) @@ -81,6 +81,7 @@ import Test.Integration.Framework.DSL as DSL , Headers (..) , Payload (..) , TxDescription (..) + , between , emptyRandomWallet , emptyWallet , eventually @@ -90,21 +91,29 @@ import Test.Integration.Framework.DSL as DSL , expectResponseCode , expectSuccess , faucetAmt + , faucetUtxoAmt , fixturePassphrase , fixtureRandomWallet , fixtureRawTx , fixtureWallet + , fixtureWalletWith , genMnemonics , getFromResponse , json , listAddresses , listAllTransactions , request + , unsafeRequest , verify , walletId + , (.>=) ) import Test.Integration.Framework.TestData - ( errMsg400MalformedTxPayload, errMsg404CannotFindTx ) + ( errMsg400MalformedTxPayload + , errMsg403Fee + , errMsg403NotEnoughMoney + , errMsg404CannotFindTx + ) import Test.Integration.Jcli ( getBlock0H ) import Test.QuickCheck @@ -130,6 +139,181 @@ spec :: forall n t. , DelegationAddress n JormungandrKey ) => SpecWith (Context t) spec = do + it "TRANS_CREATE_01 - Single Output Transaction" $ \ctx -> do + (wa, wb) <- (,) <$> fixtureWallet ctx <*> fixtureWallet ctx + let amt = (1 :: Natural) + + addrs <- listAddresses @n ctx wb + let destination = (addrs !! 1) ^. #id + let payload = Json [json|{ + "payments": [{ + "address": #{destination}, + "amount": { + "quantity": #{amt}, + "unit": "lovelace" + } + }], + "passphrase": #{fixturePassphrase} + }|] + + (_, ApiFee (Quantity minFee) (Quantity maxFee)) <- unsafeRequest ctx + (Link.getTransactionFee @'Shelley wa) payload + + r <- request @(ApiTransaction n) ctx + (Link.createTransaction @'Shelley wa) Default payload + + verify r + [ expectSuccess + , expectResponseCode HTTP.status202 + , expectField (#amount . #getQuantity) $ + between (minFee + amt, maxFee + amt) + , expectField (#direction . #getApiT) (`shouldBe` Outgoing) + , expectField (#status . #getApiT) (`shouldBe` Pending) + , expectField (#metadata . #getApiTxMetadata) (`shouldBe` Nothing) + ] + + ra <- request @ApiWallet ctx (Link.getWallet @'Shelley wa) Default Empty + verify ra + [ expectSuccess + , expectField (#balance . #getApiT . #total) $ + between + ( Quantity (faucetAmt - maxFee - amt) + , Quantity (faucetAmt - minFee - amt) + ) + , expectField + (#balance . #getApiT . #available) + (.>= Quantity (faucetAmt - faucetUtxoAmt)) + ] + + eventually "wa and wb balances are as expected" $ do + rb <- request @ApiWallet ctx + (Link.getWallet @'Shelley wb) Default Empty + expectField + (#balance . #getApiT . #available) + (`shouldBe` Quantity (faucetAmt + amt)) rb + + ra2 <- request @ApiWallet ctx + (Link.getWallet @'Shelley wa) Default Empty + expectField + (#balance . #getApiT . #available) + (`shouldBe` Quantity (faucetAmt - maxFee - amt)) ra2 + + it "TRANS_CREATE_02 - Multiple Output Tx to single wallet" $ \ctx -> do + wSrc <- fixtureWallet ctx + wDest <- emptyWallet ctx + addrs <- listAddresses @n ctx wDest + + let amt = (1 :: Natural) + let destination1 = (addrs !! 1) ^. #id + let destination2 = (addrs !! 2) ^. #id + let payload = Json [json|{ + "payments": [{ + "address": #{destination1}, + "amount": { + "quantity": #{amt}, + "unit": "lovelace" + } + }, + { + "address": #{destination2}, + "amount": { + "quantity": #{amt}, + "unit": "lovelace" + } + }], + "passphrase": "cardano-wallet" + }|] + + (_, ApiFee (Quantity minFee) (Quantity maxFee)) <- unsafeRequest ctx + (Link.getTransactionFee @'Shelley wSrc) payload + + r <- request @(ApiTransaction n) ctx + (Link.createTransaction @'Shelley wSrc) Default payload + + ra <- request @ApiWallet ctx (Link.getWallet @'Shelley wSrc) Default Empty + verify r + [ expectResponseCode HTTP.status202 + , expectField (#amount . #getQuantity) $ + between (minFee + (2*amt), maxFee + (2*amt)) + , expectField (#direction . #getApiT) (`shouldBe` Outgoing) + , expectField (#status . #getApiT) (`shouldBe` Pending) + ] + verify ra + [ expectField (#balance . #getApiT . #total) $ + between + ( Quantity (faucetAmt - maxFee - (2*amt)) + , Quantity (faucetAmt - minFee - (2*amt)) + ) + , expectField + (#balance . #getApiT . #available) + (.>= Quantity (faucetAmt - 2 * faucetUtxoAmt)) + ] + eventually "wDest balance is as expected" $ do + rd <- request @ApiWallet ctx + (Link.getWallet @'Shelley wDest) Default Empty + verify rd + [ expectField + (#balance . #getApiT . #available) + (`shouldBe` Quantity (2*amt)) + , expectField + (#balance . #getApiT . #total) + (`shouldBe` Quantity (2*amt)) + ] + + it "TRANS_CREATE_04 - Can't cover fee" $ \ctx -> do + wDest <- fixtureWallet ctx + + let amt = (1 :: Natural) + addrs <- listAddresses @n ctx wDest + let destination = (addrs !! 1) ^. #id + let payload = Json [json|{ + "payments": [{ + "address": #{destination}, + "amount": { + "quantity": #{amt}, + "unit": "lovelace" + } + }], + "passphrase": #{fixturePassphrase} + }|] + + (_, ApiFee (Quantity minFee) _) <- unsafeRequest ctx + (Link.getTransactionFee @'Shelley wDest) payload + + wSrc <- fixtureWalletWith @n ctx [minFee `div` 2] + + r <- request @(ApiTransaction n) ctx + (Link.createTransaction @'Shelley wSrc) Default payload + verify r + [ expectResponseCode HTTP.status403 + , expectErrorMessage errMsg403Fee + ] + + it "TRANS_CREATE_04 - Not enough money" $ \ctx -> do + let (srcAmt, reqAmt) = (1, 1_000_000) + wSrc <- fixtureWalletWith @n ctx [srcAmt] + wDest <- emptyWallet ctx + + addrs <- listAddresses @n ctx wDest + let destination = (addrs !! 1) ^. #id + let payload = Json [json|{ + "payments": [{ + "address": #{destination}, + "amount": { + "quantity": #{reqAmt}, + "unit": "lovelace" + } + }], + "passphrase": #{fixturePassphrase} + }|] + + r <- request @(ApiTransaction n) ctx + (Link.createTransaction @'Shelley wSrc) Default payload + verify r + [ expectResponseCode HTTP.status403 + , expectErrorMessage $ errMsg403NotEnoughMoney srcAmt reqAmt + ] + it "TRANS_CREATE_09 - 0 amount transaction is accepted on single output tx" $ \ctx -> do (wSrc, payload) <- fixtureZeroAmtSingle ctx r <- request @(ApiTransaction n) ctx From 6e98d4b10829b4b732c755273d9e9449ca4ee52f Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Wed, 16 Sep 2020 10:52:21 +0200 Subject: [PATCH 11/12] BYRON_MIGRATE_01 - make Jormungandr big wallet for migration smaller (the same as Shelley one) and adjust to pass on both backends --- .../Scenario/API/Byron/Migrations.hs | 16 +- .../test/data/jormungandr/block0.bin | Bin 248327 -> 221027 bytes .../test/data/jormungandr/genesis.yaml | 902 +----------------- 3 files changed, 13 insertions(+), 905 deletions(-) diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Byron/Migrations.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Byron/Migrations.hs index d1da388d487..6268af58f71 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Byron/Migrations.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Byron/Migrations.hs @@ -47,6 +47,8 @@ import Data.Quantity ( Quantity (..) ) import Data.Text ( Text ) +import Data.Typeable + ( Typeable, typeOf ) import Data.Word ( Word64 ) import Test.Hspec @@ -99,6 +101,7 @@ spec :: forall n t. , PaymentAddress n ShelleyKey , PaymentAddress n IcarusKey , PaymentAddress n ByronKey + , Typeable t ) => SpecWith (Context t) spec = describe "BYRON_MIGRATIONS" $ do it "BYRON_CALCULATE_01 - \ @@ -257,17 +260,23 @@ spec = describe "BYRON_MIGRATIONS" $ do addrs <- listAddresses @n ctx wNew let addr1 = (addrs !! 1) ^. #id + numOfTxs <- case (show (typeOf (_target ctx))) of + s | s == "Proxy * Jormungandr" -> pure 1 + s | s == "Proxy * (IO Shelley)" -> pure 20 + _ -> fail "unknown target backend?" + let payloadMigrate = Json [json| { passphrase: #{fixturePassphrase} , addresses: [#{addr1}] }|] - request @[ApiTransaction n] ctx + rm <- request @[ApiTransaction n] ctx (Link.migrateWallet @'Byron wOld) Default - payloadMigrate >>= flip verify + payloadMigrate + verify rm [ expectResponseCode @IO HTTP.status202 - , expectField id ((`shouldBe` 20). length) + , expectField id ( (`shouldBe` (numOfTxs)) . length ) ] -- Check that funds become available in the target wallet: @@ -284,7 +293,6 @@ spec = describe "BYRON_MIGRATIONS" $ do (#balance . #getApiT . #total) ( `shouldBe` Quantity expectedBalance) ] - -- Analyze the target wallet UTxO distribution request @ApiUtxoStatistics ctx (Link.getUTxOsStatistics @'Shelley wNew) Default diff --git a/lib/jormungandr/test/data/jormungandr/block0.bin b/lib/jormungandr/test/data/jormungandr/block0.bin index a2fcf7297fa2facd5f877192a2b1d39716aeb7e8..c5a57982c24d10b05bacd95c51e86f6b790124a6 100644 GIT binary patch delta 88 zcmZpl!vA<5uL(mC0|NtdJU@_xgQQ^By^?1FS7rQu&A%vH#5k&D#&N!5!66X;45wNd)C^UHS3Al3k?J>l8HnB9RL6@x++lr|Nnn6VI03A-aGU~yyv9( zv&{TlMQVOKaM!sInAL%j2YAxcc1SVkg71gjM+>`;UUeU1P%`Z+4F-{dGR8j7J!LG+ zmfN2XW25);n&Y0TE(tj_iQp6B=Aaod7||ufZ>|N1-pA*E{u2UDI;fbGW?b*I!ezC{%--aa*I_oXKW3x7rF00QTC4-Ge3EJiehSq728NG@seu8);QcZJ)hs2gOL_ zqoj3^Qae;*+G4M`D~@4K${D^u8w^H%Ur1BZJb_`U(uW9o(NN zUYp4Y=P17v_d!Z+kUd?~dYLAVrD5=EJ^e2(LIC&&t(*9NC3(>q*QB%Ek6%`42A0z` zQ%rSIj=U+0CoaZyZQ{6u;29F6)C@U&tFO`;Pj%`kRKb7Fx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q_&?eYv*T8qYGO%8*Pi4y# z1He?vocr)cH_tbv8mO5mVra5K13kMJo>EaAa5J5mbQNAef}{C&fUku@7AyX=Yy1ZpkBd&W&@8E zF18(^9^95U=cpzE;b$>8rhigPZt>an)heM$j4}d$X=hK9-PRSc=+=uyu9T0tA$HP! z%;+5JvA6FZS2o8pTcb|QU$$AWw6!qmVWT{BGaTK zOHri*Hug_Ww@aEQ=8bSFt7 zM-GEIp+Tr8^59JGRtD8)#_-}O(}Hea4@vWh2_dPi zr7w}3oM8AT$Mbk5E%)yXG9-3r+T(|A>dPh>;yW?o<{2M#Q7Qhw4{um%SQEQxZWx@X z~AReO}H^K9L`|XTW4!mDbNy}_&*<&slgS08YPHDTsRAwdOtpEPee_ zEks*+2S`)Uc-|V#ul5U>0beyn{}Zj8{F}R&w(twm=~2_gQva zbz$juXO#8H`V{NOFX=k{6{8XVWv|>=rc$x!34ltFF)>3D``;~`WD8Ev={$#Jhs) Date: Wed, 16 Sep 2020 11:38:25 +0200 Subject: [PATCH 12/12] adjust genMnemonics to be more standard --- .../src/Test/Integration/Framework/DSL.hs | 24 ++--- .../Integration/Scenario/API/Byron/Wallets.hs | 99 +++++++------------ .../Scenario/API/Shelley/Wallets.hs | 47 +++++---- .../Integration/Scenario/CLI/Byron/Wallets.hs | 79 ++++++--------- .../Jormungandr/Scenario/API/Transactions.hs | 3 +- 5 files changed, 104 insertions(+), 148 deletions(-) diff --git a/lib/core-integration/src/Test/Integration/Framework/DSL.hs b/lib/core-integration/src/Test/Integration/Framework/DSL.hs index cf6dfdeac12..c8c155c791f 100644 --- a/lib/core-integration/src/Test/Integration/Framework/DSL.hs +++ b/lib/core-integration/src/Test/Integration/Framework/DSL.hs @@ -527,7 +527,17 @@ walletId = minUTxOValue :: Natural minUTxOValue = 1_000_000 -genMnemonics +data MnemonicLength = M9 | M12 | M15 | M18 | M21 | M24 deriving (Show) + +genMnemonics :: MnemonicLength -> IO [Text] +genMnemonics M9 = genMnemonics' @9 +genMnemonics M12 = genMnemonics' @12 +genMnemonics M15 = genMnemonics' @15 +genMnemonics M18 = genMnemonics' @18 +genMnemonics M21 = genMnemonics' @21 +genMnemonics M24 = genMnemonics' @24 + +genMnemonics' :: forall mw ent csz. ( ConsistentEntropy ent mw csz , ValidEntropySize ent @@ -536,19 +546,9 @@ genMnemonics , mw ~ MnemonicWords ent ) => IO [Text] -genMnemonics = +genMnemonics' = mnemonicToText . entropyToMnemonic @mw <$> genEntropy -data MnemonicLength = M9 | M12 | M15 | M18 | M21 | M24 deriving (Show) - -genMnemonics' :: MnemonicLength -> IO [Text] -genMnemonics' M9 = genMnemonics @9 -genMnemonics' M12 = genMnemonics @12 -genMnemonics' M15 = genMnemonics @15 -genMnemonics' M18 = genMnemonics @18 -genMnemonics' M21 = genMnemonics @21 -genMnemonics' M24 = genMnemonics @24 - getTxId :: (ApiTransaction n) -> String getTxId tx = T.unpack $ toUrlPiece $ ApiTxId (tx ^. #id) diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Byron/Wallets.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Byron/Wallets.hs index d65f7b0a6a8..c4c9532d537 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Byron/Wallets.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Byron/Wallets.hs @@ -15,16 +15,6 @@ module Test.Integration.Scenario.API.Byron.Wallets import Prelude -import Cardano.Mnemonic - ( ConsistentEntropy - , EntropySize - , MnemonicWords - , ValidChecksumSize - , ValidEntropySize - , entropyToMnemonic - , genEntropy - , mnemonicToText - ) import Cardano.Wallet.Api.Types ( ApiByronWallet , ApiUtxoStatistics @@ -50,8 +40,6 @@ import Data.Proxy ( Proxy (..) ) import Data.Quantity ( Quantity (..) ) -import Data.Text - ( Text ) import Test.Hspec ( SpecWith, describe, runIO, shouldNotBe, shouldSatisfy ) import Test.Hspec.Expectations.Lifted @@ -61,6 +49,7 @@ import Test.Hspec.Extra import Test.Integration.Framework.DSL ( Context (..) , Headers (..) + , MnemonicLength (..) , Payload (..) , emptyByronWalletFromXPrvWith , emptyByronWalletWith @@ -117,9 +106,9 @@ spec = describe "BYRON_WALLETS" $ do it "BYRON_LIST_01 - Byron Wallets are listed from oldest to newest" $ \ctx -> do - m1 <- genMnemonics @12 - m2 <- genMnemonics @12 - m3 <- genMnemonics @12 + m1 <- genMnemonics M12 + m2 <- genMnemonics M12 + m3 <- genMnemonics M12 _ <- emptyByronWalletWith ctx "random" ("b1", m1, fixturePassphrase) _ <- emptyByronWalletWith ctx "random" ("b2", m2, fixturePassphrase) _ <- emptyByronWalletWith ctx "random" ("b3", m3, fixturePassphrase) @@ -138,9 +127,9 @@ spec = describe "BYRON_WALLETS" $ do it "BYRON_LIST_01 - Interleave of Icarus and Random wallets" $ \ctx -> do let pwd = fixturePassphrase - genMnemonics @15 >>= \m -> void (emptyByronWalletWith ctx "icarus" ("ica1", m, pwd)) - genMnemonics @12 >>= \m -> void (emptyByronWalletWith ctx "random" ("rnd2", m, pwd)) - genMnemonics @15 >>= \m -> void (emptyByronWalletWith ctx "icarus" ("ica3", m, pwd)) + genMnemonics M15 >>= \m -> void (emptyByronWalletWith ctx "icarus" ("ica1", m, pwd)) + genMnemonics M12 >>= \m -> void (emptyByronWalletWith ctx "random" ("rnd2", m, pwd)) + genMnemonics M15 >>= \m -> void (emptyByronWalletWith ctx "icarus" ("ica3", m, pwd)) rl <- request @[ApiByronWallet] ctx (Link.listWallets @'Byron) Default Empty verify rl [ expectResponseCode @IO HTTP.status200 @@ -223,37 +212,37 @@ spec = describe "BYRON_WALLETS" $ do , "words" ] - it' "random" (genMnemonics @9) scenarioFailure -- ❌ - it' "random" (genMnemonics @12) scenarioSuccess -- ✔️ - it' "random" (genMnemonics @15) scenarioSuccess -- ✔️ - it' "random" (genMnemonics @18) scenarioSuccess -- ✔️ - it' "random" (genMnemonics @21) scenarioSuccess -- ✔️ - it' "random" (genMnemonics @24) scenarioSuccess -- ✔️ - - it' "icarus" (genMnemonics @9) scenarioFailure -- ❌ - it' "icarus" (genMnemonics @12) scenarioSuccess -- ✔️ - it' "icarus" (genMnemonics @15) scenarioSuccess -- ✔️ - it' "icarus" (genMnemonics @18) scenarioSuccess -- ✔️ - it' "icarus" (genMnemonics @21) scenarioSuccess -- ✔️ - it' "icarus" (genMnemonics @24) scenarioSuccess -- ✔️ - - it' "trezor" (genMnemonics @9) scenarioFailure -- ❌ - it' "trezor" (genMnemonics @12) scenarioSuccess -- ✔️ - it' "trezor" (genMnemonics @15) scenarioSuccess -- ✔️ - it' "trezor" (genMnemonics @18) scenarioSuccess -- ✔️ - it' "trezor" (genMnemonics @21) scenarioSuccess -- ✔️ - it' "trezor" (genMnemonics @24) scenarioSuccess -- ✔️ - - it' "ledger" (genMnemonics @9) scenarioFailure -- ❌ - it' "ledger" (genMnemonics @12) scenarioSuccess -- ✔️ - it' "ledger" (genMnemonics @15) scenarioSuccess -- ✔️ - it' "ledger" (genMnemonics @18) scenarioSuccess -- ✔️ - it' "ledger" (genMnemonics @21) scenarioSuccess -- ✔️ - it' "ledger" (genMnemonics @24) scenarioSuccess -- ✔️ + it' "random" (genMnemonics M9) scenarioFailure -- ❌ + it' "random" (genMnemonics M12) scenarioSuccess -- ✔️ + it' "random" (genMnemonics M15) scenarioSuccess -- ✔️ + it' "random" (genMnemonics M18) scenarioSuccess -- ✔️ + it' "random" (genMnemonics M21) scenarioSuccess -- ✔️ + it' "random" (genMnemonics M24) scenarioSuccess -- ✔️ + + it' "icarus" (genMnemonics M9) scenarioFailure -- ❌ + it' "icarus" (genMnemonics M12) scenarioSuccess -- ✔️ + it' "icarus" (genMnemonics M15) scenarioSuccess -- ✔️ + it' "icarus" (genMnemonics M18) scenarioSuccess -- ✔️ + it' "icarus" (genMnemonics M21) scenarioSuccess -- ✔️ + it' "icarus" (genMnemonics M24) scenarioSuccess -- ✔️ + + it' "trezor" (genMnemonics M9) scenarioFailure -- ❌ + it' "trezor" (genMnemonics M12) scenarioSuccess -- ✔️ + it' "trezor" (genMnemonics M15) scenarioSuccess -- ✔️ + it' "trezor" (genMnemonics M18) scenarioSuccess -- ✔️ + it' "trezor" (genMnemonics M21) scenarioSuccess -- ✔️ + it' "trezor" (genMnemonics M24) scenarioSuccess -- ✔️ + + it' "ledger" (genMnemonics M9) scenarioFailure -- ❌ + it' "ledger" (genMnemonics M12) scenarioSuccess -- ✔️ + it' "ledger" (genMnemonics M15) scenarioSuccess -- ✔️ + it' "ledger" (genMnemonics M18) scenarioSuccess -- ✔️ + it' "ledger" (genMnemonics M21) scenarioSuccess -- ✔️ + it' "ledger" (genMnemonics M24) scenarioSuccess -- ✔️ it "BYRON_RESTORE_02 - One can restore previously deleted wallet" $ \ctx -> do - m <- genMnemonics @12 + m <- genMnemonics M12 w <- emptyByronWalletWith ctx "random" ("Byron Wallet", m, fixturePassphrase) rd <- request @@ -264,7 +253,7 @@ spec = describe "BYRON_WALLETS" $ do w ^. walletId `shouldBe` wr ^. walletId it "BYRON_RESTORE_03 - Cannot restore wallet that exists" $ \ctx -> do - mnemonic <- genMnemonics @12 + mnemonic <- genMnemonics M12 let payload = Json [json| { "name": "Some Byron Wallet", "mnemonic_sentence": #{mnemonic}, @@ -312,7 +301,7 @@ spec = describe "BYRON_WALLETS" $ do ] forM_ matrix $ \(title, passphrase, expectations) -> it title $ \ctx -> do - mnemonics12 <- genMnemonics @12 + mnemonics12 <- genMnemonics M12 let payload = Json [json| { "name": "Secure Wallet", "mnemonic_sentence": #{mnemonics12}, @@ -347,7 +336,7 @@ spec = describe "BYRON_WALLETS" $ do it "BYRON_UPDATE_NAME_02 - Update names of wallets from Xprv" $ \ctx -> do -- Wallet from XPRV let wName = "Byron Wallet from XPRV" - mnemonics <- genMnemonics @12 + mnemonics <- genMnemonics M12 let rootXPrv = rootPrvKeyFromMnemonics mnemonics fixturePassphrase w <- emptyByronWalletFromXPrvWith ctx "random" (wName, rootXPrv, fixturePassphraseEncrypted) @@ -454,15 +443,3 @@ spec = describe "BYRON_WALLETS" $ do verify r [ expectResponseCode @IO HTTP.status204 ] - - where - genMnemonics - :: forall mw ent csz. - ( ConsistentEntropy ent mw csz - , ValidEntropySize ent - , ValidChecksumSize ent csz - , ent ~ EntropySize mw - , mw ~ MnemonicWords ent - ) - => IO [Text] - genMnemonics = mnemonicToText . entropyToMnemonic @mw <$> genEntropy diff --git a/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Wallets.hs b/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Wallets.hs index 7223e85b4cc..63053d17fd8 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Wallets.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/API/Shelley/Wallets.hs @@ -85,7 +85,6 @@ import Test.Integration.Framework.DSL , fixturePassphrase , fixtureWallet , genMnemonics - , genMnemonics' , getFromResponse , json , listAddresses @@ -130,8 +129,8 @@ spec :: forall n t. ) => SpecWith (Context t) spec = describe "SHELLEY_WALLETS" $ do it "WALLETS_CREATE_01 - Create a wallet" $ \ctx -> do - m15 <- genMnemonics @15 - m12 <- genMnemonics @12 + m15 <- genMnemonics M15 + m12 <- genMnemonics M12 let payload = Json [json| { "name": "1st Wallet", "mnemonic_sentence": #{m15}, @@ -265,7 +264,7 @@ spec = describe "SHELLEY_WALLETS" $ do ] it "WALLETS_CREATE_03,09 - Cannot create wallet that exists" $ \ctx -> do - m21 <- genMnemonics @21 + m21 <- genMnemonics M21 let payload = Json [json| { "name": "Some Wallet", "mnemonic_sentence": #{m21}, @@ -334,7 +333,7 @@ spec = describe "SHELLEY_WALLETS" $ do ) ] forM_ matrix $ \(title, walName, expectations) -> it title $ \ctx -> do - m24 <- genMnemonics @24 + m24 <- genMnemonics M24 let payload = Json [json| { "name": #{walName}, "mnemonic_sentence": #{m24}, @@ -352,7 +351,7 @@ spec = describe "SHELLEY_WALLETS" $ do ] forM_ matrix $ \(title, mnemonics) -> it title $ \ctx -> do - m <- genMnemonics' mnemonics + m <- genMnemonics mnemonics let payload = Json [json| { "name": "Just a łallet", "mnemonic_sentence": #{m}, @@ -367,8 +366,8 @@ spec = describe "SHELLEY_WALLETS" $ do , ( "12 mnemonic words", M12 ) ] forM_ matrix $ \(title, mnemonics) -> it title $ \ctx -> do - m15 <- genMnemonics' M15 - mSecondFactor <- genMnemonics' mnemonics + m15 <- genMnemonics M15 + mSecondFactor <- genMnemonics mnemonics let payload = Json [json| { "name": "Just a łallet", @@ -394,7 +393,7 @@ spec = describe "SHELLEY_WALLETS" $ do , ( "Wildcards passphrase", wildcardsWalletName ) ] forM_ matrix $ \(title, passphrase) -> it title $ \ctx -> do - m24 <- genMnemonics @24 + m24 <- genMnemonics M24 let payload = Json [json| { "name": "Secure Wallet", "mnemonic_sentence": #{m24}, @@ -421,7 +420,7 @@ spec = describe "SHELLEY_WALLETS" $ do ) ] forM_ matrix $ \(title, addrPoolGap, expectations) -> it title $ \ctx -> do - m24 <- genMnemonics @24 + m24 <- genMnemonics M24 let payload = payloadWith' "Secure Wallet" m24 (fromIntegral addrPoolGap) rW <- request @ApiWallet ctx (Link.postWallet @'Shelley) Default payload verify rW expectations @@ -435,7 +434,7 @@ spec = describe "SHELLEY_WALLETS" $ do -- ] it "WALLETS_CREATE_08 - default address_pool_gap" $ \ctx -> do - m21 <- genMnemonics @21 + m21 <- genMnemonics M21 let payload = Json [json| { "name": "Secure Wallet", "mnemonic_sentence": #{m21}, @@ -477,7 +476,7 @@ spec = describe "SHELLEY_WALLETS" $ do ) ] forM_ matrix $ \(title, headers, expectations) -> it title $ \ctx -> do - m21 <- genMnemonics @21 + m21 <- genMnemonics M21 let payload = Json [json| { "name": "Secure Wallet", "mnemonic_sentence": #{m21}, @@ -520,8 +519,8 @@ spec = describe "SHELLEY_WALLETS" $ do expectErrorMessage (errMsg404NoWallet $ w ^. walletId) rg it "WALLETS_LIST_01 - Created a wallet can be listed" $ \ctx -> do - m18 <- genMnemonics @18 - m9 <- genMnemonics @9 + m18 <- genMnemonics M18 + m9 <- genMnemonics M9 let payload = Json [json| { "name": "Wallet to be listed", "mnemonic_sentence": #{m18}, @@ -549,9 +548,9 @@ spec = describe "SHELLEY_WALLETS" $ do ] it "WALLETS_LIST_01 - Wallets are listed from oldest to newest" $ \ctx -> do - m15 <- genMnemonics @15 - m18 <- genMnemonics @18 - m21 <- genMnemonics @21 + m15 <- genMnemonics M15 + m18 <- genMnemonics M18 + m21 <- genMnemonics M21 let walletDetails = [("1", m15), ("2", m18) , ("3", m21)] forM_ walletDetails $ \(name, mnemonics) -> do @@ -805,7 +804,7 @@ spec = describe "SHELLEY_WALLETS" $ do , ( "Wildcards passphrase", wildcardsWalletName ) ] forM_ matrix $ \(title, oldPass) -> it title $ \ctx -> do - m24 <- genMnemonics @24 + m24 <- genMnemonics M24 let createPayload = Json [json| { "name": "Name of the wallet", "mnemonic_sentence": #{m24}, @@ -1145,9 +1144,9 @@ spec = describe "SHELLEY_WALLETS" $ do it "BYRON_LIST_02,03 -\ \ Byron wallets listed only via Byron endpoints \\\ \ Shelley wallets listed only via new endpoints" $ \ctx -> do - m1 <- genMnemonics @12 - m2 <- genMnemonics @12 - m3 <- genMnemonics @12 + m1 <- genMnemonics M12 + m2 <- genMnemonics M12 + m3 <- genMnemonics M12 _ <- emptyByronWalletWith ctx "random" ("byron1", m1, fixturePassphrase) _ <- emptyByronWalletWith ctx "random" ("byron2", m2, fixturePassphrase) _ <- emptyByronWalletWith ctx "random" ("byron3", m3, fixturePassphrase) @@ -1183,9 +1182,9 @@ spec = describe "SHELLEY_WALLETS" $ do it "BYRON_LIST_04, DELETE_01 -\ \ Deleted wallets cannot be listed" $ \ctx -> do - m1 <- genMnemonics @12 - m2 <- genMnemonics @12 - m3 <- genMnemonics @12 + m1 <- genMnemonics M12 + m2 <- genMnemonics M12 + m3 <- genMnemonics M12 _ <- emptyByronWalletWith ctx "random" ("byron1", m1, fixturePassphrase) wb2 <- emptyByronWalletWith ctx "random" ("byron2", m2, fixturePassphrase) _ <- emptyByronWalletWith ctx "random" ("byron3", m3, fixturePassphrase) diff --git a/lib/core-integration/src/Test/Integration/Scenario/CLI/Byron/Wallets.hs b/lib/core-integration/src/Test/Integration/Scenario/CLI/Byron/Wallets.hs index 9eb079b06cd..b17f0d6c7fb 100644 --- a/lib/core-integration/src/Test/Integration/Scenario/CLI/Byron/Wallets.hs +++ b/lib/core-integration/src/Test/Integration/Scenario/CLI/Byron/Wallets.hs @@ -13,16 +13,6 @@ module Test.Integration.Scenario.CLI.Byron.Wallets import Prelude -import Cardano.Mnemonic - ( ConsistentEntropy - , EntropySize - , MnemonicWords - , ValidChecksumSize - , ValidEntropySize - , entropyToMnemonic - , genEntropy - , mnemonicToText - ) import Cardano.Wallet.Api.Types ( ApiByronWallet, ApiUtxoStatistics, DecodeAddress ) import Cardano.Wallet.Primitive.AddressDerivation @@ -39,8 +29,6 @@ import Data.Proxy ( Proxy (..) ) import Data.Quantity ( Quantity (..) ) -import Data.Text - ( Text ) import System.Command ( Exit (..), Stderr (..), Stdout (..) ) import System.Exit @@ -58,6 +46,7 @@ import Test.Hspec import Test.Integration.Framework.DSL ( Context (..) , KnownCommand (..) + , MnemonicLength (..) , createWalletViaCLI , deleteWalletViaCLI , emptyIcarusWallet @@ -68,6 +57,7 @@ import Test.Integration.Framework.DSL , expectValidJSON , expectWalletUTxO , fixturePassphrase + , genMnemonics , getWalletUtxoStatisticsViaCLI , getWalletViaCLI , listWalletsViaCLI @@ -97,8 +87,8 @@ spec = describe "BYRON_CLI_WALLETS" $ do describe "CLI_BYRON_GET_04, CLI_BYRON_DELETE_01, BYRON_RESTORE_02, BYRON_RESTORE_03 -\ \ Deleted wallet is not available, but can be restored" $ do - let matrix = [ ("random", genMnemonics @12) - , ("icarus", genMnemonics @15) + let matrix = [ ("random", genMnemonics M12) + , ("icarus", genMnemonics M15) ] forM_ matrix $ \(style, genM) -> it style $ \ctx -> do mnemonic <- genM @@ -203,33 +193,33 @@ spec = describe "BYRON_CLI_WALLETS" $ do , "words" ] - it' "random" (genMnemonics @9) scenarioFailure -- ❌ - it' "random" (genMnemonics @12) scenarioSuccess -- ✔️ - it' "random" (genMnemonics @15) scenarioSuccess -- ✔️ - it' "random" (genMnemonics @18) scenarioSuccess -- ✔️ - it' "random" (genMnemonics @21) scenarioSuccess -- ✔️ - it' "random" (genMnemonics @24) scenarioSuccess -- ✔️ + it' "random" (genMnemonics M9) scenarioFailure -- ❌ + it' "random" (genMnemonics M12) scenarioSuccess -- ✔️ + it' "random" (genMnemonics M15) scenarioSuccess -- ✔️ + it' "random" (genMnemonics M18) scenarioSuccess -- ✔️ + it' "random" (genMnemonics M21) scenarioSuccess -- ✔️ + it' "random" (genMnemonics M24) scenarioSuccess -- ✔️ - it' "icarus" (genMnemonics @9) scenarioFailure -- ❌ - it' "icarus" (genMnemonics @12) scenarioSuccess -- ✔️ - it' "icarus" (genMnemonics @15) scenarioSuccess -- ✔️ - it' "icarus" (genMnemonics @18) scenarioSuccess -- ✔️ - it' "icarus" (genMnemonics @21) scenarioSuccess -- ✔️ - it' "icarus" (genMnemonics @24) scenarioSuccess -- ✔️ + it' "icarus" (genMnemonics M9) scenarioFailure -- ❌ + it' "icarus" (genMnemonics M12) scenarioSuccess -- ✔️ + it' "icarus" (genMnemonics M15) scenarioSuccess -- ✔️ + it' "icarus" (genMnemonics M18) scenarioSuccess -- ✔️ + it' "icarus" (genMnemonics M21) scenarioSuccess -- ✔️ + it' "icarus" (genMnemonics M24) scenarioSuccess -- ✔️ - it' "trezor" (genMnemonics @9) scenarioFailure -- ❌ - it' "trezor" (genMnemonics @12) scenarioSuccess -- ✔️ - it' "trezor" (genMnemonics @15) scenarioSuccess -- ✔️ - it' "trezor" (genMnemonics @18) scenarioSuccess -- ✔️ - it' "trezor" (genMnemonics @21) scenarioSuccess -- ✔️ - it' "trezor" (genMnemonics @24) scenarioSuccess -- ✔️ + it' "trezor" (genMnemonics M9) scenarioFailure -- ❌ + it' "trezor" (genMnemonics M12) scenarioSuccess -- ✔️ + it' "trezor" (genMnemonics M15) scenarioSuccess -- ✔️ + it' "trezor" (genMnemonics M18) scenarioSuccess -- ✔️ + it' "trezor" (genMnemonics M21) scenarioSuccess -- ✔️ + it' "trezor" (genMnemonics M24) scenarioSuccess -- ✔️ - it' "ledger" (genMnemonics @9) scenarioFailure -- ❌ - it' "ledger" (genMnemonics @12) scenarioSuccess -- ✔️ - it' "ledger" (genMnemonics @15) scenarioSuccess -- ✔️ - it' "ledger" (genMnemonics @18) scenarioSuccess -- ✔️ - it' "ledger" (genMnemonics @21) scenarioSuccess -- ✔️ - it' "ledger" (genMnemonics @24) scenarioSuccess -- ✔️ + it' "ledger" (genMnemonics M9) scenarioFailure -- ❌ + it' "ledger" (genMnemonics M12) scenarioSuccess -- ✔️ + it' "ledger" (genMnemonics M15) scenarioSuccess -- ✔️ + it' "ledger" (genMnemonics M18) scenarioSuccess -- ✔️ + it' "ledger" (genMnemonics M21) scenarioSuccess -- ✔️ + it' "ledger" (genMnemonics M24) scenarioSuccess -- ✔️ describe "CLI_BYRON_RESTORE_06 - Passphrase" $ do let minLength = passphraseMinLength (Proxy @"raw") @@ -251,7 +241,7 @@ spec = describe "BYRON_CLI_WALLETS" $ do [ "Name of the wallet" , "--wallet-style", "random" ] - mnemonic <- genMnemonics @12 + mnemonic <- genMnemonics M12 (c, out, err) <- createWalletViaCLI @t ctx args (unwords $ T.unpack <$> mnemonic) "\n" (T.unpack passphrase) @@ -346,14 +336,3 @@ spec = describe "BYRON_CLI_WALLETS" $ do T.unpack e `shouldContain` errMsg c `shouldBe` ExitFailure 1 o `shouldBe` mempty - -genMnemonics - :: forall mw ent csz. - ( ConsistentEntropy ent mw csz - , ValidEntropySize ent - , ValidChecksumSize ent csz - , ent ~ EntropySize mw - , mw ~ MnemonicWords ent - ) - => IO [Text] -genMnemonics = mnemonicToText . entropyToMnemonic @mw <$> genEntropy diff --git a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs index 6d1c82349dc..016b32ffb40 100644 --- a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs +++ b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/API/Transactions.hs @@ -79,6 +79,7 @@ import Test.Integration.Faucet import Test.Integration.Framework.DSL as DSL ( Context (..) , Headers (..) + , MnemonicLength (..) , Payload (..) , TxDescription (..) , between @@ -668,7 +669,7 @@ fixtureExternalTx ctx toSend = do let (Just keysAddrChng) = isOwned st' (rootXPrv, pwd) addrChng -- we create destination empty wallet - mnemonics15 <- genMnemonics @15 + mnemonics15 <- genMnemonics M15 let createWallet = Json [json| { "name": "Destination Wallet", "mnemonic_sentence": #{mnemonics15},