From 5e013333c79c8da672347d48ad96b66243011a80 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Sun, 29 Sep 2019 13:05:53 +1000 Subject: [PATCH 1/9] nix: Better source filtering --- nix/default.nix | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/nix/default.nix b/nix/default.nix index ee7f83e2663..a89d1ff87fc 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -31,20 +31,32 @@ let cp -v ${pkgs.libffi}/bin/libffi-6.dll $out/bin '' else postInstall; + # Chop out a subdirectory of the source, so that the package is only + # rebuilt when something in the subdirectory changes. + filterSubDir = dir: with pkgs.lib; let + isFiltered = src ? _isLibCleanSourceWith; + origSrc = if isFiltered then src.origSrc else src; + in cleanSourceWith { + inherit src; + filter = path: type: + type == "directory" || + hasPrefix (toString origSrc + toString dir) path; + } + dir; + pkgSet = haskell.mkStackPkgSet { inherit stack-pkgs; modules = [ # Add source filtering to local packages { - packages.cardano-wallet-core.src = src + /lib/core; - packages.cardano-wallet-core-integration.src = src + /lib/core-integration; - packages.cardano-wallet-cli.src = src + /lib/cli; - packages.cardano-wallet-launcher.src = src + /lib/launcher; - packages.cardano-wallet-http-bridge.src = src + /lib/http-bridge; - packages.cardano-wallet-jormungandr.src = src + /lib/jormungandr; - packages.cardano-wallet-test-utils.src = src + /lib/test-utils; - packages.text-class.src = src + /lib/text-class; - packages.bech32.src = src + /lib/bech32; + packages.cardano-wallet-core.src = filterSubDir /lib/core; + packages.cardano-wallet-core-integration.src = filterSubDir /lib/core-integration; + packages.cardano-wallet-cli.src = filterSubDir /lib/cli; + packages.cardano-wallet-launcher.src = filterSubDir /lib/launcher; + packages.cardano-wallet-http-bridge.src = filterSubDir /lib/http-bridge; + packages.cardano-wallet-jormungandr.src = filterSubDir /lib/jormungandr; + packages.cardano-wallet-test-utils.src = filterSubDir /lib/test-utils; + packages.text-class.src = filterSubDir /lib/text-class; + packages.bech32.src = filterSubDir /lib/bech32; } # Add dependencies @@ -62,7 +74,6 @@ let unit.build-tools = [ jormungandr ]; }; - packages.cardano-wallet-jormungandr.components.exes.cardano-wallet-jormungandr = { build-tools = [ pkgs.makeWrapper]; postInstall = wrapForPosix '' From 484b51932c3bc732f4821e52f704b1a078395556 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Sun, 29 Sep 2019 14:34:28 +1000 Subject: [PATCH 2/9] nix: Refactor windows release dist --- nix/jormungandr.nix | 24 ++++++++++++++++++++++-- nix/windows-release.nix | 35 +++++++++++++++++++++++++++++++++++ release.nix | 37 +++++-------------------------------- 3 files changed, 62 insertions(+), 34 deletions(-) create mode 100644 nix/windows-release.nix diff --git a/nix/jormungandr.nix b/nix/jormungandr.nix index ecec4d67f80..fb0bcb1b40e 100644 --- a/nix/jormungandr.nix +++ b/nix/jormungandr.nix @@ -37,7 +37,27 @@ let cargoSha256 = "0pflam5am760z4pz3j1ga4arsixmay2487sgpqrhrkiaws4nxy57"; }; + windows = rec { + # URL and hash of windows binary release + url = "https://github.com/input-output-hk/jormungandr/releases/download/v${release.version}/jormungandr-v${release.version}-x86_64-pc-windows-msvc.zip"; + sha256 = "0dd2b2r50kcwakn61sv7xvf2s1yl586rlk8zch2bpfw9bjqrs0hl"; + }; + + jormungandr-win64 = pkgs.runCommand "jormungandr-win64-${release.version}" { + nativeBuildInputs = [ pkgs.buildPackages.unzip ]; + } '' + mkdir -p $out/bin + cd $out/bin + unzip ${pkgs.fetchurl windows} + ''; + + nonWindows = pkg: if pkgs.stdenv.hostPlatform.isWindows + then jormungandr-win64 + else pkg; + in { - jormungandr = iohkLib.rust-packages.pkgs.makeJormungandr release; - jormungandr-cli = iohkLib.rust-packages.pkgs.makeJcli release; + jormungandr = nonWindows (iohkLib.rust-packages.pkgs.makeJormungandr release); + jormungandr-cli = nonWindows (iohkLib.rust-packages.pkgs.makeJcli release); + + inherit jormungandr-win64; } diff --git a/nix/windows-release.nix b/nix/windows-release.nix new file mode 100644 index 00000000000..174d8b6f09e --- /dev/null +++ b/nix/windows-release.nix @@ -0,0 +1,35 @@ +{ pkgs +, cardano-wallet-jormungandr +, project +, jpkgs ? import ./jormungandr.nix { inherit pkgs; } +, jormungandr-win64 ? jpkgs.jormungandr-win64 +}: + +let + testData = ../lib/jormungandr/test/data/jormungandr; + name = "cardano-wallet-jormungandr-${project.version}-win64"; + jm-bat = pkgs.writeText "jm.bat" '' + jormungandr.exe --config config.yaml --genesis-block block0.bin --secret secret.yaml + ''; + cw-bat = pkgs.writeText "cw.bat" '' + cardano-wallet-jormungandr.exe serve --node-port 8081 --genesis-hash HASH --database c:\\cardano-wallet-jormungandr\\wallet.db + ''; +in pkgs.runCommand name { + nativeBuildInputs = [ pkgs.zip pkgs.jq pkgs.gnused project.jormungandr-cli ]; +} '' + mkdir -pv jm $out/nix-support + cd jm + + cp -v ${cardano-wallet-jormungandr}/bin/* . + cp -v ${jormungandr-win64}/bin/* . + cp -v ${testData}/block0.bin ${testData}/secret.yaml . + cp -v ${jm-bat} jm.bat + hash="$(jcli genesis hash --input block0.bin)" + sed -e "s/HASH/$hash/" ${cw-bat} > cw.bat + sed -e 's/storage:.*/storage: "c:\\\\cardano-wallet-jormungandr\\\\storage"/' \ + ${testData}/config.yaml > config.yaml + chmod -R +w . + + zip -r $out/${name}.zip . + echo "file binary-dist $out/${name}.zip" > $out/nix-support/hydra-build-products +'' diff --git a/release.nix b/release.nix index 451fe460895..dc8a3de5fa1 100644 --- a/release.nix +++ b/release.nix @@ -38,38 +38,11 @@ let ] ); - cardano-wallet-jormungandr-win64 = let - jm = pkgs.fetchurl { - url = https://github.com/input-output-hk/jormungandr/releases/download/v0.3.3/jormungandr-v0.3.3-x86_64-pc-windows-msvc.zip; - sha256 = "0psva16vq86gcld701k0fi6kk1ydnm2q3yd2mdgflb0x8zpm2i3g"; - }; - testData = ./lib/jormungandr/test/data/jormungandr; - name = "cardano-wallet-jormungandr-${project.version}-win64.zip"; - jm-bat = pkgs.writeText "jm.bat" '' - jormungandr.exe --config config.yaml --genesis-block block0.bin -- --secret secret.yaml - ''; - cw-bat = pkgs.writeText "cw.bat" '' - cardano-wallet-jormungandr.exe serve --node-port 8081 --genesis-block-hash HASH --database c:\\cardano-wallet-jormungandr\\wallets - ''; - in pkgs.runCommand "cardano-wallet-jormungandr-win64" { - buildInputs = [ pkgs.zip pkgs.unzip pkgs.jq pkgs.gnused project.jormungandr-cli ]; - } '' - mkdir -pv jm $out/nix-support - cd jm - - cp -v ${jobs.x86_64-pc-mingw32.cardano-wallet-jormungandr.x86_64-linux}/bin/* . - unzip ${jm} - cp -v ${testData}/block0.bin ${testData}/secret.yaml . - cp -v ${jm-bat} jm.bat - hash="$(jcli genesis hash --input block0.bin)" - sed -e "s/HASH/$hash/" ${cw-bat} > cw.bat - sed -e 's/storage:.*/storage: "c:\\\\cardano-wallet-jormungandr\\\\storage"/' \ - ${testData}/config.yaml > config.yaml - chmod -R +w . - - zip -r $out/${name} . - echo "file binary-dist $out/${name}" > $out/nix-support/hydra-build-products - ''; + # This is used for testing the build on windows. + cardano-wallet-jormungandr-win64 = import ./nix/windows-release.nix { + inherit pkgs project; + cardano-wallet-jormungandr = jobs.x86_64-pc-mingw32.cardano-wallet-jormungandr.x86_64-linux; + }; } # Build the shell derivation in Hydra so that all its dependencies # are cached. From 28a4c242f27f799b787f67c57eba96d96483f3f7 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Fri, 18 Oct 2019 15:19:52 +1000 Subject: [PATCH 3/9] nix: Provide derivations for Daedalus installer --- nix/default.nix | 44 +++++++++++++++++++++++++++++--------------- release.nix | 7 +++++++ 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/nix/default.nix b/nix/default.nix index a89d1ff87fc..89848e19619 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -9,7 +9,11 @@ # Test dependencies of cardano-wallet , cardano-sl-node , cardano-http-bridge -, jormungandr + +# Dependencies of cardano-wallet-jormungandr +, jpkgs ? import ./jormungandr.nix { inherit pkgs; } +, jormungandr-win64 ? jpkgs.jormungandr-win64 +, jormungandr ? jpkgs.jormungandr # Customisations for cross-compiling , iohk-extras ? {} @@ -24,12 +28,11 @@ let # Grab the compiler name from stack-to-nix output. compiler = (stack-pkgs.extras {}).compiler.nix-name; - # Use a postInstall wrapping script if this is not a windows - # build. Otherwise, copy DLL dependencies. - wrapForPosix = postInstall: if pkgs.stdenv.hostPlatform.isWindows - then '' - cp -v ${pkgs.libffi}/bin/libffi-6.dll $out/bin - '' else postInstall; + # Make a postInstall wrapping script to provide dependencies. + # For the windows build, also copy DLL dependencies. + provideDeps = { nix, darwin ? "", windows ? "" }: + with pkgs.stdenv.hostPlatform; + if isWindows then windows else (if isDarwin then darwin else nix); # Chop out a subdirectory of the source, so that the package is only # rebuilt when something in the subdirectory changes. @@ -76,18 +79,29 @@ let packages.cardano-wallet-jormungandr.components.exes.cardano-wallet-jormungandr = { build-tools = [ pkgs.makeWrapper]; - postInstall = wrapForPosix '' - wrapProgram $out/bin/cardano-wallet-jormungandr \ - --prefix PATH : ${jormungandr}/bin - ''; + postInstall = provideDeps { + nix = '' + wrapProgram $out/bin/cardano-wallet-jormungandr \ + --prefix PATH : ${jormungandr}/bin + ''; + darwin = '' + cp ${jormungandr}/bin/* $out/bin + ''; + windows = '' + cp -v ${pkgs.libffi}/bin/libffi-6.dll $out/bin + cp ${jormungandr-win64}/* $out/bin + ''; + }; }; packages.cardano-wallet-http-bridge.components.exes.cardano-wallet-http-bridge = { build-tools = [ pkgs.makeWrapper]; - postInstall = wrapForPosix '' - wrapProgram $out/bin/cardano-wallet-http-bridge \ - --prefix PATH : ${cardano-http-bridge}/bin - ''; + postInstall = provideDeps { + nix = '' + wrapProgram $out/bin/cardano-wallet-http-bridge \ + --prefix PATH : ${cardano-http-bridge}/bin + ''; + }; }; packages.cardano-wallet-http-bridge.components.benchmarks.restore = { diff --git a/release.nix b/release.nix index dc8a3de5fa1..d5553f23360 100644 --- a/release.nix +++ b/release.nix @@ -43,6 +43,13 @@ let inherit pkgs project; cardano-wallet-jormungandr = jobs.x86_64-pc-mingw32.cardano-wallet-jormungandr.x86_64-linux; }; + + # These derivations are used for the Daedalus installer. + daedalus-jormungandr = with jobs; { + linux = native.cardano-wallet-jormungandr.x86_64-linux; + macos = native.cardano-wallet-jormungandr.x86_64-darwin; + windows = x86_64-pc-mingw32.cardano-wallet-jormungandr.x86_64-linux; + }; } # Build the shell derivation in Hydra so that all its dependencies # are cached. From cc7b2c21e2976252045b8f1510cce337e49e4fec Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Mon, 21 Oct 2019 15:49:31 +1000 Subject: [PATCH 4/9] nix: Make bundling of dependencies separate from Haskell.nix build --- default.nix | 16 ++++++++----- nix/default.nix | 38 +++++------------------------ nix/jormungandr.nix | 2 +- nix/package-jormungandr.nix | 48 +++++++++++++++++++++++++++++++++++++ nix/windows-release.nix | 12 +++++++--- 5 files changed, 74 insertions(+), 42 deletions(-) create mode 100644 nix/package-jormungandr.nix diff --git a/default.nix b/default.nix index 884bc93e050..2e1397f93bc 100644 --- a/default.nix +++ b/default.nix @@ -13,8 +13,8 @@ let haskell = iohkLib.nix-tools.haskell { inherit pkgs; }; src = iohkLib.cleanSourceHaskell ./.; - inherit (import ./nix/jormungandr.nix { inherit iohkLib pkgs; }) - jormungandr jormungandr-cli; + jmPkgs = import ./nix/jormungandr.nix { inherit iohkLib pkgs; }; + inherit (jmPkgs) jormungandr jormungandr-cli; cardano-http-bridge = iohkLib.rust-packages.pkgs.callPackage ./nix/cardano-http-bridge.nix { inherit pkgs; }; @@ -26,15 +26,19 @@ let inherit (iohkLib.nix-tools) iohk-extras iohk-module; }; + inherit (haskellPackages.cardano-wallet-core.identifier) version; in { - inherit pkgs iohkLib src haskellPackages; + inherit pkgs iohkLib src haskellPackages version; inherit cardano-http-bridge cardano-sl-node jormungandr jormungandr-cli; - inherit (haskellPackages.cardano-wallet-core.identifier) version; inherit (haskellPackages.cardano-wallet-http-bridge.components.exes) cardano-wallet-http-bridge; - inherit (haskellPackages.cardano-wallet-jormungandr.components.exes) - cardano-wallet-jormungandr; + + cardano-wallet-jormungandr = import ./nix/package-jormungandr.nix { + inherit (haskellPackages.cardano-wallet-jormungandr.components.exes) + cardano-wallet-jormungandr; + inherit pkgs jmPkgs version; + }; tests = collectComponents "tests" isCardanoWallet haskellPackages; benchmarks = collectComponents "benchmarks" isCardanoWallet haskellPackages; diff --git a/nix/default.nix b/nix/default.nix index 89848e19619..bfdeca6db1f 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -11,9 +11,8 @@ , cardano-http-bridge # Dependencies of cardano-wallet-jormungandr -, jpkgs ? import ./jormungandr.nix { inherit pkgs; } -, jormungandr-win64 ? jpkgs.jormungandr-win64 -, jormungandr ? jpkgs.jormungandr +, jmPkgs ? import ./jormungandr.nix { inherit pkgs; } +, jormungandr ? jmPkgs.jormungandr # Customisations for cross-compiling , iohk-extras ? {} @@ -28,12 +27,6 @@ let # Grab the compiler name from stack-to-nix output. compiler = (stack-pkgs.extras {}).compiler.nix-name; - # Make a postInstall wrapping script to provide dependencies. - # For the windows build, also copy DLL dependencies. - provideDeps = { nix, darwin ? "", windows ? "" }: - with pkgs.stdenv.hostPlatform; - if isWindows then windows else (if isDarwin then darwin else nix); - # Chop out a subdirectory of the source, so that the package is only # rebuilt when something in the subdirectory changes. filterSubDir = dir: with pkgs.lib; let @@ -77,31 +70,12 @@ let unit.build-tools = [ jormungandr ]; }; - packages.cardano-wallet-jormungandr.components.exes.cardano-wallet-jormungandr = { - build-tools = [ pkgs.makeWrapper]; - postInstall = provideDeps { - nix = '' - wrapProgram $out/bin/cardano-wallet-jormungandr \ - --prefix PATH : ${jormungandr}/bin - ''; - darwin = '' - cp ${jormungandr}/bin/* $out/bin - ''; - windows = '' - cp -v ${pkgs.libffi}/bin/libffi-6.dll $out/bin - cp ${jormungandr-win64}/* $out/bin - ''; - }; - }; - packages.cardano-wallet-http-bridge.components.exes.cardano-wallet-http-bridge = { build-tools = [ pkgs.makeWrapper]; - postInstall = provideDeps { - nix = '' - wrapProgram $out/bin/cardano-wallet-http-bridge \ - --prefix PATH : ${cardano-http-bridge}/bin - ''; - }; + postInstall = '' + wrapProgram $out/bin/cardano-wallet-http-bridge \ + --prefix PATH : ${cardano-http-bridge}/bin + ''; }; packages.cardano-wallet-http-bridge.components.benchmarks.restore = { diff --git a/nix/jormungandr.nix b/nix/jormungandr.nix index fb0bcb1b40e..45b06242307 100644 --- a/nix/jormungandr.nix +++ b/nix/jormungandr.nix @@ -40,7 +40,7 @@ let windows = rec { # URL and hash of windows binary release url = "https://github.com/input-output-hk/jormungandr/releases/download/v${release.version}/jormungandr-v${release.version}-x86_64-pc-windows-msvc.zip"; - sha256 = "0dd2b2r50kcwakn61sv7xvf2s1yl586rlk8zch2bpfw9bjqrs0hl"; + sha256 = "16pxgi4igvfh2kccsbyizfc4wyxr8fs1872hpsmr99ppna09rqi3"; }; jormungandr-win64 = pkgs.runCommand "jormungandr-win64-${release.version}" { diff --git a/nix/package-jormungandr.nix b/nix/package-jormungandr.nix new file mode 100644 index 00000000000..11761694616 --- /dev/null +++ b/nix/package-jormungandr.nix @@ -0,0 +1,48 @@ +############################################################################ +# Release package for cardano-wallet-jormungandr +# +# This makes release builds of cardano-wallet-jormungandr and bundles +# dependencies as required for different systems. +# +############################################################################ + +{ pkgs +, version +, cardano-wallet-jormungandr +, jmPkgs ? import ./jormungandr.nix { inherit pkgs; } +, jormungandr ? jmPkgs.jormungandr +, jormungandr-win64 ? jmPkgs.jormungandr-win64 +}: + +with pkgs.lib; + +let + name = "cardano-wallet-jormungandr-${version}"; + + deps = { + nix = '' + strip $out/bin/cardano-wallet-jormungandr + wrapProgram $out/bin/cardano-wallet-jormungandr \ + --prefix PATH : ${jormungandr}/bin + ''; + darwin = '' + cp ${jormungandr}/bin/* $out/bin + ''; + windows = '' + cp -v ${pkgs.libffi}/bin/libffi-6.dll $out/bin + cp ${jormungandr-win64}/* $out/bin + ''; + }; + provideDeps = { nix, darwin ? "", windows ? "" }: + with pkgs.stdenv.hostPlatform; + if isWindows then windows else (if isDarwin then darwin else nix); + +in pkgs.runCommand name { + inherit version; + nativeBuildInputs = [ pkgs.makeWrapper pkgs.binutils ]; +} '' + cp -R ${cardano-wallet-jormungandr} $out + chmod -R +w $out + + ${provideDeps deps} +'' diff --git a/nix/windows-release.nix b/nix/windows-release.nix index 174d8b6f09e..653242b64a7 100644 --- a/nix/windows-release.nix +++ b/nix/windows-release.nix @@ -1,8 +1,15 @@ +############################################################################ +# Windows release CARDAN~1.ZIP +# +# This bundles up the windows build and its dependencies, adds an +# example self-node configuration, and some .BAT files for launching, +# and sets up the Hydra build artifact. +# +############################################################################ + { pkgs , cardano-wallet-jormungandr , project -, jpkgs ? import ./jormungandr.nix { inherit pkgs; } -, jormungandr-win64 ? jpkgs.jormungandr-win64 }: let @@ -21,7 +28,6 @@ in pkgs.runCommand name { cd jm cp -v ${cardano-wallet-jormungandr}/bin/* . - cp -v ${jormungandr-win64}/bin/* . cp -v ${testData}/block0.bin ${testData}/secret.yaml . cp -v ${jm-bat} jm.bat hash="$(jcli genesis hash --input block0.bin)" From a0bd85a9cfd6b579cab3ba145f6b54d703c557e6 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Fri, 18 Oct 2019 13:55:35 +1000 Subject: [PATCH 5/9] jormungandr launch: use --rest-listen instead of generating config.yaml --- .../exe/cardano-wallet-jormungandr.hs | 31 ++++++- .../Wallet/Jormungandr/Compatibility.hs | 31 ------- .../src/Cardano/Wallet/Jormungandr/Network.hs | 40 +++----- .../Cardano/Wallet/Jormungandr/Launch.hs | 92 ++++++++++++++++--- lib/jormungandr/test/integration/Main.hs | 11 +-- .../Wallet/Jormungandr/CompatibilitySpec.hs | 26 +----- 6 files changed, 122 insertions(+), 109 deletions(-) diff --git a/lib/jormungandr/exe/cardano-wallet-jormungandr.hs b/lib/jormungandr/exe/cardano-wallet-jormungandr.hs index 7e76d5f0067..62f2b3fc7ca 100644 --- a/lib/jormungandr/exe/cardano-wallet-jormungandr.hs +++ b/lib/jormungandr/exe/cardano-wallet-jormungandr.hs @@ -75,6 +75,8 @@ import Cardano.Wallet.Version ( showVersion, version ) import Control.Applicative ( optional, (<|>) ) +import Data.List + ( isPrefixOf ) import Data.Maybe ( fromMaybe ) import Data.Text @@ -92,11 +94,12 @@ import Options.Applicative , helper , info , long + , many , metavar , progDesc - , some - , str ) +import Options.Applicative.Types + ( readerAsk, readerError ) import System.Exit ( exitWith ) import System.FilePath @@ -163,7 +166,7 @@ data LaunchArgs = LaunchArgs data JormungandrArgs = JormungandrArgs { genesisBlock :: Either (Hash "Genesis") FilePath - , extraJormungandrArgs :: [Text] + , extraJormungandrArgs :: [String] } cmdLaunch @@ -286,7 +289,25 @@ genesisHashOption = optionT $ mempty <> help "Blake2b_256 hash of the genesis block, in base 16." -- | -- [ARGUMENTS...] -extraArguments :: Parser [Text] -extraArguments = some $ argument str $ mempty +extraArguments :: Parser [String] +extraArguments = many $ argument jmArg $ mempty <> metavar "[-- ARGUMENTS...]" <> help "Extra arguments to be passed to jormungandr." + where + jmArg = do + arg <- readerAsk + case validate arg of + Just err -> readerError err + Nothing -> pure arg + validate arg + | "--genesis-block" `isPrefixOf` arg = Just $ + "The " <> arg <> " option must be placed before the --" + | "--rest-listen" `isPrefixOf` arg = Just $ + suggestion "--rest-listen" + | "--storage" `isPrefixOf` arg = Just $ + suggestion "--storage" + | otherwise = Nothing + suggestion arg = "The " <> arg <> " argument is used by " + <> "`cardano-wallet-jormungandr launch'." + <> "\nIf you need this level of flexibility, run `jormungandr' " + <> " separately and use `cardano-wallet-jormungandr serve'." diff --git a/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Compatibility.hs b/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Compatibility.hs index fdf0c73ba2c..32e3ebec4e6 100644 --- a/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Compatibility.hs +++ b/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Compatibility.hs @@ -24,7 +24,6 @@ module Cardano.Wallet.Jormungandr.Compatibility -- * Node's Configuration , BaseUrl (..) , Scheme (..) - , genConfigFile , localhostBaseUrl , baseUrlToText ) where @@ -39,8 +38,6 @@ import Cardano.Wallet.Jormungandr.Environment ( KnownNetwork (..), Network (..) ) import Cardano.Wallet.Jormungandr.Primitive.Types ( Tx (..) ) -import Cardano.Wallet.Network.Ports - ( PortNumber ) import Cardano.Wallet.Primitive.AddressDerivation ( KeyToAddress (..), getRawKey ) import Cardano.Wallet.Primitive.AddressDerivation.Random @@ -60,8 +57,6 @@ import Control.Arrow ( second ) import Control.Monad ( when ) -import Data.Aeson - ( Value (..), object, (.=) ) import Data.ByteString ( ByteString ) import Data.ByteString.Base58 @@ -78,14 +73,11 @@ import Data.Word ( Word16 ) import Servant.Client.Core ( BaseUrl (..), Scheme (..), showBaseUrl ) -import System.FilePath - ( FilePath, () ) import qualified Cardano.Byron.Codec.Cbor as CBOR import qualified Cardano.Wallet.Primitive.Types as W import qualified Codec.Binary.Bech32 as Bech32 import qualified Codec.CBOR.Write as CBOR -import qualified Data.Aeson as Aeson import qualified Data.ByteString as BS import qualified Data.ByteString.Char8 as B8 import qualified Data.Text as T @@ -223,29 +215,6 @@ instance KnownNetwork n => DecodeAddress (Jormungandr n) where <> B8.unpack (BS.pack [discriminant]) <> "." --- | Generate a configuration file for Jörmungandr@0.3.999 -genConfigFile - :: FilePath - -> PortNumber - -> BaseUrl - -> Aeson.Value -genConfigFile stateDir addressPort (BaseUrl _ host port _) = object - [ "storage" .= (stateDir "chain") - , "rest" .= object - [ "listen" .= String listen ] - , "p2p" .= object - [ "trusted_peers" .= ([] :: [()]) - , "topics_of_interest" .= object - [ "messages" .= String "low" - , "blocks" .= String "normal" - ] - , "public_address" .= String publicAddress - ] - ] - where - listen = T.pack $ mconcat [host, ":", show port] - publicAddress = T.pack $ mconcat ["/ip4/127.0.0.1/tcp/", show addressPort] - {------------------------------------------------------------------------------- Base URL -------------------------------------------------------------------------------} diff --git a/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs b/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs index d52a22e4fce..7deca5f2cb9 100644 --- a/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs +++ b/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs @@ -57,7 +57,7 @@ import Prelude import Cardano.BM.Data.Severity ( Severity (..) ) import Cardano.BM.Trace - ( Trace, logInfo ) + ( Trace ) import Cardano.Launcher ( Command (..) , ProcessHasExited @@ -95,7 +95,7 @@ import Cardano.Wallet.Jormungandr.Api.Client import Cardano.Wallet.Jormungandr.Binary ( runGetOrFail ) import Cardano.Wallet.Jormungandr.Compatibility - ( Jormungandr, genConfigFile, localhostBaseUrl ) + ( Jormungandr, localhostBaseUrl ) import Cardano.Wallet.Network ( Cursor, NetworkLayer (..), NextBlocksResult (..), defaultRetryPolicy ) import Cardano.Wallet.Network.BlockHeaders @@ -118,7 +118,7 @@ import Cardano.Wallet.Primitive.Types import Control.Concurrent.MVar.Lifted ( MVar, modifyMVar, newMVar, readMVar ) import Control.Exception - ( Exception, bracket ) + ( Exception ) import Control.Monad.IO.Class ( liftIO ) import Control.Monad.Trans.Class @@ -131,8 +131,6 @@ import Data.ByteArray.Encoding ( Base (Base16), convertToBase ) import Data.Coerce ( coerce ) -import Data.Function - ( (&) ) import Data.Map.Strict ( Map ) import Data.Quantity @@ -141,8 +139,6 @@ import Data.Text ( Text ) import Data.Word ( Word32, Word64 ) -import System.Directory - ( removeFile ) import System.FilePath ( () ) @@ -151,8 +147,6 @@ import qualified Data.ByteString.Char8 as B8 import qualified Data.ByteString.Lazy as BL import qualified Data.Char as C import qualified Data.Map as Map -import qualified Data.Text as T -import qualified Data.Yaml as Yaml -- | Whether to start Jormungandr with the given config, or to connect to an -- already running Jormungandr REST API using the given parameters. @@ -175,7 +169,7 @@ data JormungandrConfig = JormungandrConfig , _restApiPort :: Maybe PortNumber , _minSeverity :: Severity , _outputStream :: StdStream - , _extraArgs :: [Text] + , _extraArgs :: [String] } deriving (Show, Eq) -- | Starts the network layer and runs the given action with a @@ -477,28 +471,16 @@ withJormungandr -> (JormungandrConnParams -> IO a) -- ^ Action to run while node is running. -> IO (Either ErrStartup a) -withJormungandr tr (JormungandrConfig stateDir block0 mPort logSeverity output extraArgs) cb = - bracket setupConfig cleanupConfig startBackend - where - nodeConfigFile = stateDir "jormungandr-config.yaml" - setupConfig = do - apiPort <- maybe getRandomPort pure mPort - p2pPort <- getRandomPort - let baseUrl = localhostBaseUrl $ fromIntegral apiPort - genConfigFile stateDir p2pPort baseUrl - & Yaml.encodeFile nodeConfigFile - logInfo tr $ mempty - <> "Generated Jörmungandr's configuration to: " - <> T.pack nodeConfigFile - pure (apiPort, baseUrl) - cleanupConfig _ = removeFile nodeConfigFile - - startBackend (apiPort, baseUrl) = getGenesisBlockArg block0 >>= \case +withJormungandr tr (JormungandrConfig stateDir block0 mPort logSeverity output extraArgs) cb = do + apiPort <- maybe getRandomPort pure mPort + let baseUrl = localhostBaseUrl $ fromIntegral apiPort + getGenesisBlockArg block0 >>= \case Right (block0H, genesisBlockArg) -> do let args = genesisBlockArg ++ - [ "--config", nodeConfigFile + [ "--rest-listen", "127.0.0.1:" <> show apiPort + , "--storage", stateDir "chain" , "--log-level", C.toLower <$> show logSeverity - ] ++ map T.unpack extraArgs + ] ++ extraArgs let cmd = Command "jormungandr" args (return ()) output let tr' = transformLauncherTrace tr res <- withBackendProcess tr' cmd $ diff --git a/lib/jormungandr/test/integration/Cardano/Wallet/Jormungandr/Launch.hs b/lib/jormungandr/test/integration/Cardano/Wallet/Jormungandr/Launch.hs index 156ed83a25c..08a25bf029d 100644 --- a/lib/jormungandr/test/integration/Cardano/Wallet/Jormungandr/Launch.hs +++ b/lib/jormungandr/test/integration/Cardano/Wallet/Jormungandr/Launch.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DataKinds #-} +{-# LANGUAGE QuasiQuotes #-} -- | -- Copyright: © 2018-2019 IOHK @@ -8,9 +9,9 @@ -- tests. module Cardano.Wallet.Jormungandr.Launch - ( setupConfig - , teardownConfig + ( withConfig , withBackendOnly + , spec ) where import Prelude @@ -21,37 +22,54 @@ import Cardano.Launcher ( StdStream (..) ) import Cardano.Wallet.Jormungandr.Network ( JormungandrConfig (..), JormungandrConnParams, withJormungandr ) +import Cardano.Wallet.Network.Ports + ( PortNumber, getRandomPort ) import Control.Exception ( bracket, throwIO ) +import Data.Aeson + ( Value (..), object, (.=) ) +import Data.Aeson.QQ + ( aesonQQ ) +import Data.Function + ( (&) ) import System.Directory ( doesDirectoryExist, removeDirectoryRecursive ) import System.Environment ( lookupEnv ) import System.FilePath - ( () ) + ( FilePath, () ) import System.IO ( IOMode (..), hClose, openFile ) import System.IO.Temp ( createTempDirectory, getCanonicalTemporaryDirectory ) +import Test.Hspec + ( Spec, describe, it, shouldBe ) +import qualified Data.Aeson as Aeson import qualified Data.Text as T +import qualified Data.Yaml as Yaml -- | Starts jormungandr on a random port using the integration tests config. -- The data directory will be stored in a unique location under the system -- temporary directory. +withConfig :: (JormungandrConfig -> IO a) -> IO a +withConfig = bracket setupConfig teardownConfig + setupConfig :: IO JormungandrConfig setupConfig = do let dir = "test/data/jormungandr" tmp <- getCanonicalTemporaryDirectory configDir <- createTempDirectory tmp "cardano-wallet-jormungandr" logFile <- openFile (configDir "jormungandr.log") WriteMode - pure $ JormungandrConfig - configDir - (Right $ dir "block0.bin") - Nothing - minBound - (UseHandle logFile) - ["--secret", T.pack (dir "secret.yaml")] + let cfg = JormungandrConfig + configDir + (Right $ dir "block0.bin") + Nothing + minBound + (UseHandle logFile) + ["--secret", dir "secret.yaml"] + genConfigYaml cfg + pure cfg teardownConfig :: JormungandrConfig -> IO () teardownConfig (JormungandrConfig d _ _ _ output _) = do @@ -65,8 +83,54 @@ teardownConfig (JormungandrConfig d _ _ _ output _) = do (_, True) -> removeDirectoryRecursive d _ -> pure () --- | Launches jörmungandr, but not the wallet. +-- | Launches jörmungandr with a test config, but not the wallet. withBackendOnly :: (JormungandrConnParams -> IO a) -> IO a -withBackendOnly cb = - bracket setupConfig teardownConfig $ \jmConfig -> - (withJormungandr nullTracer jmConfig cb >>= either throwIO pure) +withBackendOnly cb = withConfig $ \jmConfig -> do + withJormungandr nullTracer jmConfig cb >>= either throwIO pure + +{------------------------------------------------------------------------------- + Generate YAML config file +-------------------------------------------------------------------------------} + +spec :: Spec +spec = describe "genConfigFile integration tests helper" $ do + it "example configuration" $ do + let stateDir = "/state-dir" + genConfigFile stateDir 8081 `shouldBe` [aesonQQ|{ + "storage": "/state-dir/chain", + "p2p": { + "trusted_peers": [], + "topics_of_interest": { + "messages": "low", + "blocks": "normal" + }, + "public_address" : "/ip4/127.0.0.1/tcp/8081" + } + }|] + +genConfigYaml :: JormungandrConfig -> IO () +genConfigYaml (JormungandrConfig stateDir _ _ _ _ _) = do + p2pPort <- getRandomPort + genConfigFile stateDir p2pPort + & Yaml.encodeFile nodeConfigFile + where + nodeConfigFile = stateDir "jormungandr-config.yaml" + +-- | Generate a configuration file for Jörmungandr@0.3.999 +genConfigFile + :: FilePath + -> PortNumber + -> Aeson.Value +genConfigFile stateDir addressPort = object + [ "storage" .= (stateDir "chain") + , "p2p" .= object + [ "trusted_peers" .= ([] :: [()]) + , "topics_of_interest" .= object + [ "messages" .= String "low" + , "blocks" .= String "normal" + ] + , "public_address" .= String publicAddress + ] + ] + where + publicAddress = T.pack $ mconcat ["/ip4/127.0.0.1/tcp/", show addressPort] diff --git a/lib/jormungandr/test/integration/Main.hs b/lib/jormungandr/test/integration/Main.hs index 5eea8eeb674..ed65fcee0f5 100644 --- a/lib/jormungandr/test/integration/Main.hs +++ b/lib/jormungandr/test/integration/Main.hs @@ -29,7 +29,7 @@ import Cardano.Wallet.Jormungandr import Cardano.Wallet.Jormungandr.Compatibility ( Jormungandr, Network (..) ) import Cardano.Wallet.Jormungandr.Launch - ( setupConfig, teardownConfig ) + ( withConfig ) import Cardano.Wallet.Jormungandr.Network ( JormungandrBackend (..) ) import Cardano.Wallet.Primitive.Fee @@ -41,7 +41,7 @@ import Control.Concurrent.Async import Control.Concurrent.MVar ( newEmptyMVar, putMVar, takeMVar ) import Control.Exception - ( bracket, throwIO ) + ( throwIO ) import Data.Proxy ( Proxy (..) ) import Data.Quantity @@ -122,15 +122,14 @@ specWithServer :: (CM.Configuration, Trace IO Text) -> SpecWith (Context (Jormungandr 'Testnet)) -> Spec -specWithServer (cfg, tr) = beforeAll start . after tearDown +specWithServer logCfg = beforeAll start . after tearDown where start :: IO (Context (Jormungandr 'Testnet)) start = do ctx <- newEmptyMVar - pid <- async $ bracket setupConfig teardownConfig $ \jmCfg -> do + pid <- async $ withConfig $ \jmCfg -> do let listen = ListenOnRandomPort - serveWallet (cfg, tr) Nothing "127.0.0.1" listen (Launch jmCfg) $ - \wAddr nPort bp -> do + serveWallet logCfg Nothing "127.0.0.1" listen (Launch jmCfg) $ \wAddr nPort bp -> do let baseUrl = "http://" <> T.pack (show wAddr) <> "/" manager <- (baseUrl,) <$> newManager defaultManagerSettings faucet <- initFaucet diff --git a/lib/jormungandr/test/unit/Cardano/Wallet/Jormungandr/CompatibilitySpec.hs b/lib/jormungandr/test/unit/Cardano/Wallet/Jormungandr/CompatibilitySpec.hs index 493c0438b1e..e6bce3c9063 100644 --- a/lib/jormungandr/test/unit/Cardano/Wallet/Jormungandr/CompatibilitySpec.hs +++ b/lib/jormungandr/test/unit/Cardano/Wallet/Jormungandr/CompatibilitySpec.hs @@ -2,7 +2,6 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} @@ -10,7 +9,7 @@ module Cardano.Wallet.Jormungandr.CompatibilitySpec ( spec - )where + ) where import Prelude @@ -19,7 +18,7 @@ import Cardano.Crypto.Wallet import Cardano.Wallet.Jormungandr.Binary ( signData, singleAddressFromKey ) import Cardano.Wallet.Jormungandr.Compatibility - ( BaseUrl (..), Jormungandr, Scheme (..), genConfigFile ) + ( Jormungandr ) import Cardano.Wallet.Jormungandr.Environment ( KnownNetwork (..), Network (..) ) import Cardano.Wallet.Primitive.AddressDerivation @@ -56,8 +55,6 @@ import Cardano.Wallet.Unsafe ( unsafeDecodeAddress, unsafeFromHex ) import Control.Monad ( replicateM ) -import Data.Aeson.QQ - ( aesonQQ ) import Data.ByteArray.Encoding ( Base (Base16), convertFromBase, convertToBase ) import Data.ByteString @@ -286,25 +283,6 @@ spec = do "ta1sn0e7zr89gafgauz9xu3m25cz5ugs0s4xhtxdhqsuca58r6ycclr7\ \sp2hlmqvhyywy266ghldvxn4p0adxn0esew6a423jkmxpdsc5d8xw6gar" - describe "genConfigFile" $ do - it "example configuration" $ do - let stateDir = "/state-dir" - let baseUrl = BaseUrl Http "127.0.0.1" 8080 "/api" - genConfigFile stateDir 8081 baseUrl `shouldBe` [aesonQQ|{ - "storage": "/state-dir/chain", - "rest": { - "listen": "127.0.0.1:8080" - }, - "p2p": { - "trusted_peers": [], - "topics_of_interest": { - "messages": "low", - "blocks": "normal" - }, - "public_address" : "/ip4/127.0.0.1/tcp/8081" - } - }|] - describe "Random Address Discovery Properties" $ do it "isOurs works as expected during key derivation in testnet" $ do property (prop_derivedKeysAreOurs @'Testnet) From 749dede1bca0e93169b5f2b60761774a5070f0b7 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Mon, 21 Oct 2019 07:50:54 +1000 Subject: [PATCH 6/9] CLI: fix jormungandr args validation messages --- lib/jormungandr/exe/cardano-wallet-jormungandr.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/jormungandr/exe/cardano-wallet-jormungandr.hs b/lib/jormungandr/exe/cardano-wallet-jormungandr.hs index 62f2b3fc7ca..d6b1eb28144 100644 --- a/lib/jormungandr/exe/cardano-wallet-jormungandr.hs +++ b/lib/jormungandr/exe/cardano-wallet-jormungandr.hs @@ -308,6 +308,6 @@ extraArguments = many $ argument jmArg $ mempty suggestion "--storage" | otherwise = Nothing suggestion arg = "The " <> arg <> " argument is used by " - <> "`cardano-wallet-jormungandr launch'." - <> "\nIf you need this level of flexibility, run `jormungandr' " - <> " separately and use `cardano-wallet-jormungandr serve'." + <> "\"cardano-wallet-jormungandr launch\"." + <> "\nIf you need this level of flexibility, run \"jormungandr\" " + <> "separately and use \"cardano-wallet-jormungandr serve\"." From e48f926198d7c864332dfeb2ae81eae0ee6a1c47 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Mon, 21 Oct 2019 07:58:26 +1000 Subject: [PATCH 7/9] JormungandrConfig: Remove minSeverity field --- lib/jormungandr/exe/cardano-wallet-jormungandr.hs | 4 +--- lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs | 7 +------ .../test/integration/Cardano/Wallet/Jormungandr/Launch.hs | 5 ++--- .../integration/Cardano/Wallet/Jormungandr/NetworkSpec.hs | 3 --- 4 files changed, 4 insertions(+), 15 deletions(-) diff --git a/lib/jormungandr/exe/cardano-wallet-jormungandr.hs b/lib/jormungandr/exe/cardano-wallet-jormungandr.hs index d6b1eb28144..4e39536f362 100644 --- a/lib/jormungandr/exe/cardano-wallet-jormungandr.hs +++ b/lib/jormungandr/exe/cardano-wallet-jormungandr.hs @@ -189,8 +189,7 @@ cmdLaunch dataDir = command "launch" $ info (helper <*> cmd) $ mempty <$> genesisBlockOption <*> extraArguments) exec (LaunchArgs hostPreference listen nodePort mStateDir logCfg verbosity jArgs) = do - let minSeverity = verbosityToMinSeverity verbosity - withLogging logCfg minSeverity $ \(cfg, tr) -> do + withLogging logCfg (verbosityToMinSeverity verbosity) $ \(cfg, tr) -> do case genesisBlock jArgs of Right block0File -> requireFilePath block0File Left _ -> pure () @@ -200,7 +199,6 @@ cmdLaunch dataDir = command "launch" $ info (helper <*> cmd) $ mempty { _stateDir = stateDir , _genesisBlock = genesisBlock jArgs , _restApiPort = fromIntegral . getPort <$> nodePort - , _minSeverity = minSeverity , _outputStream = Inherit , _extraArgs = extraJormungandrArgs jArgs } diff --git a/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs b/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs index 7deca5f2cb9..1b8c9d7bd6d 100644 --- a/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs +++ b/lib/jormungandr/src/Cardano/Wallet/Jormungandr/Network.hs @@ -54,8 +54,6 @@ module Cardano.Wallet.Jormungandr.Network import Prelude -import Cardano.BM.Data.Severity - ( Severity (..) ) import Cardano.BM.Trace ( Trace ) import Cardano.Launcher @@ -145,7 +143,6 @@ import System.FilePath import qualified Cardano.Wallet.Jormungandr.Binary as J import qualified Data.ByteString.Char8 as B8 import qualified Data.ByteString.Lazy as BL -import qualified Data.Char as C import qualified Data.Map as Map -- | Whether to start Jormungandr with the given config, or to connect to an @@ -167,7 +164,6 @@ data JormungandrConfig = JormungandrConfig { _stateDir :: FilePath , _genesisBlock :: Either (Hash "Genesis") FilePath , _restApiPort :: Maybe PortNumber - , _minSeverity :: Severity , _outputStream :: StdStream , _extraArgs :: [String] } deriving (Show, Eq) @@ -471,7 +467,7 @@ withJormungandr -> (JormungandrConnParams -> IO a) -- ^ Action to run while node is running. -> IO (Either ErrStartup a) -withJormungandr tr (JormungandrConfig stateDir block0 mPort logSeverity output extraArgs) cb = do +withJormungandr tr (JormungandrConfig stateDir block0 mPort output extraArgs) cb = do apiPort <- maybe getRandomPort pure mPort let baseUrl = localhostBaseUrl $ fromIntegral apiPort getGenesisBlockArg block0 >>= \case @@ -479,7 +475,6 @@ withJormungandr tr (JormungandrConfig stateDir block0 mPort logSeverity output e let args = genesisBlockArg ++ [ "--rest-listen", "127.0.0.1:" <> show apiPort , "--storage", stateDir "chain" - , "--log-level", C.toLower <$> show logSeverity ] ++ extraArgs let cmd = Command "jormungandr" args (return ()) output let tr' = transformLauncherTrace tr diff --git a/lib/jormungandr/test/integration/Cardano/Wallet/Jormungandr/Launch.hs b/lib/jormungandr/test/integration/Cardano/Wallet/Jormungandr/Launch.hs index 08a25bf029d..83c7c7d6eca 100644 --- a/lib/jormungandr/test/integration/Cardano/Wallet/Jormungandr/Launch.hs +++ b/lib/jormungandr/test/integration/Cardano/Wallet/Jormungandr/Launch.hs @@ -65,14 +65,13 @@ setupConfig = do configDir (Right $ dir "block0.bin") Nothing - minBound (UseHandle logFile) ["--secret", dir "secret.yaml"] genConfigYaml cfg pure cfg teardownConfig :: JormungandrConfig -> IO () -teardownConfig (JormungandrConfig d _ _ _ output _) = do +teardownConfig (JormungandrConfig d _ _ output _) = do case output of UseHandle h -> hClose h _ -> pure () @@ -109,7 +108,7 @@ spec = describe "genConfigFile integration tests helper" $ do }|] genConfigYaml :: JormungandrConfig -> IO () -genConfigYaml (JormungandrConfig stateDir _ _ _ _ _) = do +genConfigYaml (JormungandrConfig stateDir _ _ _ _) = do p2pPort <- getRandomPort genConfigFile stateDir p2pPort & Yaml.encodeFile nodeConfigFile diff --git a/lib/jormungandr/test/integration/Cardano/Wallet/Jormungandr/NetworkSpec.hs b/lib/jormungandr/test/integration/Cardano/Wallet/Jormungandr/NetworkSpec.hs index 3dab52b1304..0af73058307 100644 --- a/lib/jormungandr/test/integration/Cardano/Wallet/Jormungandr/NetworkSpec.hs +++ b/lib/jormungandr/test/integration/Cardano/Wallet/Jormungandr/NetworkSpec.hs @@ -12,8 +12,6 @@ module Cardano.Wallet.Jormungandr.NetworkSpec import Prelude -import Cardano.BM.Data.Severity - ( Severity (..) ) import Cardano.BM.Trace ( nullTracer ) import Cardano.Wallet.Jormungandr.Api @@ -341,7 +339,6 @@ spec = do stateDir (Right "test/data/jormungandr/block0.bin") Nothing - Info Inherit ["--secret", "test/data/jormungandr/secret.yaml"] let tr = nullTracer From b26d9b95709b404ead5d2f3c858e8564634cced5 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Mon, 21 Oct 2019 17:26:45 +0200 Subject: [PATCH 8/9] review CLI launch documentation, added some examples in the help header --- .../exe/cardano-wallet-jormungandr.hs | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/jormungandr/exe/cardano-wallet-jormungandr.hs b/lib/jormungandr/exe/cardano-wallet-jormungandr.hs index 4e39536f362..125c1add71c 100644 --- a/lib/jormungandr/exe/cardano-wallet-jormungandr.hs +++ b/lib/jormungandr/exe/cardano-wallet-jormungandr.hs @@ -90,6 +90,7 @@ import Options.Applicative , argument , command , footer + , header , help , helper , info @@ -97,6 +98,7 @@ import Options.Applicative , many , metavar , progDesc + , progDescDoc ) import Options.Applicative.Types ( readerAsk, readerError ) @@ -106,6 +108,7 @@ import System.FilePath ( () ) import qualified Data.Text as T +import qualified Options.Applicative.Help.Pretty as D {------------------------------------------------------------------------------- Main entry point @@ -173,10 +176,28 @@ cmdLaunch :: FilePath -> Mod CommandFields (IO ()) cmdLaunch dataDir = command "launch" $ info (helper <*> cmd) $ mempty - <> progDesc "Launch and monitor a wallet server and its chain producers." + <> header "Launch and monitor a wallet server and its chain producers." + <> progDescDoc (Just $ D.empty + <> D.text "Examples:" + <> D.line + <> D.text "1) Minimal setup, relying on sensible defaults:" <> D.line + <> D.text " launch --genesis-block block0.bin" <> D.line + <> D.line + <> D.text "2) Launching a full node: " <> D.line + <> D.text " launch --genesis-block block0.bin -- --secret secret.yaml" <> D.line + <> D.line + <> D.text "3) Bootstrapping from trusted peers*:" <> D.line + <> D.text " launch --genesis-block-hash 4c05c5bb -- --config config.yaml" <> D.line + <> D.line + <> D.text "(*) assuming 'trusted_peers' is defined in 'config.yaml'" + ) <> footer - "Please note that launch will generate a configuration for Jörmungandr \ - \in a folder specified by '--state-dir'." + "Please note that launch will generate a configuration for \ + \Jörmungandr in a folder specified by '--state-dir'. You can still \ + \supply your own configuration file by using '--config' when \ + \passing extra arguments to Jörmungandr but be careful to \ + \a) NOT provide a 'rest' configuration and \ + \b) NOT provide a 'storage' configuration." where cmd = fmap exec $ LaunchArgs <$> hostPreferenceOption @@ -290,7 +311,7 @@ genesisHashOption = optionT $ mempty extraArguments :: Parser [String] extraArguments = many $ argument jmArg $ mempty <> metavar "[-- ARGUMENTS...]" - <> help "Extra arguments to be passed to jormungandr." + <> help "Extra arguments to be passed to Jörmungandr." where jmArg = do arg <- readerAsk @@ -305,7 +326,6 @@ extraArguments = many $ argument jmArg $ mempty | "--storage" `isPrefixOf` arg = Just $ suggestion "--storage" | otherwise = Nothing - suggestion arg = "The " <> arg <> " argument is used by " - <> "\"cardano-wallet-jormungandr launch\"." + suggestion arg = "The " <> arg <> " argument is used by the launch command." <> "\nIf you need this level of flexibility, run \"jormungandr\" " <> "separately and use \"cardano-wallet-jormungandr serve\"." From 94cab4a7bcee1e92c311083a2e479002c938c219 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Tue, 22 Oct 2019 11:27:10 +0200 Subject: [PATCH 9/9] review CLI LAUNCH scenarios and add negative test cases for extra arguments --- .../Jormungandr/Scenario/CLI/Launcher.hs | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/CLI/Launcher.hs b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/CLI/Launcher.hs index c02dd77e9b0..f63bf4507d5 100644 --- a/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/CLI/Launcher.hs +++ b/lib/jormungandr/test/integration/Test/Integration/Jormungandr/Scenario/CLI/Launcher.hs @@ -97,7 +97,6 @@ spec = do withCreateProcess process $ \_ (Just o) (Just e) ph -> do expectPathEventuallyExist d expectPathEventuallyExist (d <> "/chain") - expectPathEventuallyExist (d <> "/jormungandr-config.yaml") expectPathEventuallyExist (d <> "/wallets") `finally` do terminateProcess ph @@ -118,7 +117,6 @@ spec = do withCreateProcess process $ \_ (Just o) (Just e) ph -> do expectPathEventuallyExist dir expectPathEventuallyExist (dir <> "/chain") - expectPathEventuallyExist (dir <> "/jormungandr-config.yaml") expectPathEventuallyExist (dir <> "/wallets") `finally` do terminateProcess ph @@ -148,7 +146,32 @@ spec = do ] (Exit c, Stdout o, Stderr _) <- cardanoWalletCLI @t args c `shouldBe` ExitFailure 1 - o `shouldContain` ("As far as I can tell, this isn't a valid block file: " <> secret) + o `shouldContain` + ("As far as I can tell, this isn't a valid block file: " <> secret) + + it "LAUNCH - Conflicting --rest-listen in extra arguments" $ do + let args = + [ "launch" + , "--genesis-block", block0 + , "--" + , "--rest-listen", "127.0.0.1:8080" + ] + (Exit c, Stdout _, Stderr e) <- cardanoWalletCLI @t args + c `shouldBe` ExitFailure 1 + e `shouldContain` + "The --rest-listen argument is used by the launch command." + + it "LAUNCH - Conflicting --storage in extra arguments" $ do + let args = + [ "launch" + , "--genesis-block", block0 + , "--" + , "--storage", "/tmp/whatever" + ] + (Exit c, Stdout _, Stderr e) <- cardanoWalletCLI @t args + c `shouldBe` ExitFailure 1 + e `shouldContain` + "The --storage argument is used by the launch command." it "LAUNCH - Restoration workers restart" $ withTempDir $ \d -> do pendingWith