From 736993c39e9f434b14db6df45f98afdc5a038615 Mon Sep 17 00:00:00 2001 From: Noon van der Silk Date: Wed, 8 Jan 2025 14:52:35 +0000 Subject: [PATCH] Add defaults to publish-scripts parsing and use them --- hydra-node/src/Hydra/Options.hs | 13 +++++-- hydra-node/test/Hydra/OptionsSpec.hs | 53 ++++++++++++++-------------- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/hydra-node/src/Hydra/Options.hs b/hydra-node/src/Hydra/Options.hs index 8cff84c5d02..a03cda42d2f 100644 --- a/hydra-node/src/Hydra/Options.hs +++ b/hydra-node/src/Hydra/Options.hs @@ -147,6 +147,15 @@ data PublishOptions = PublishOptions } deriving stock (Show, Eq) +-- | Default options as they should also be provided by 'runOptionsParser'. +defaultPublishOptions :: PublishOptions +defaultPublishOptions = + PublishOptions + { publishNetworkId = Testnet (NetworkMagic 42) + , publishNodeSocket = "node.socket" + , publishSigningKey = "cardano.sk" + } + publishOptionsParser :: Parser PublishOptions publishOptionsParser = PublishOptions @@ -493,7 +502,7 @@ nodeSocketParser = strOption ( long "node-socket" <> metavar "FILE" - <> value "node.socket" + <> value (publishNodeSocket defaultPublishOptions) <> showDefault <> help "Filepath to local unix domain socket used to communicate with \ @@ -506,7 +515,7 @@ cardanoSigningKeyFileParser = ( long "cardano-signing-key" <> metavar "FILE" <> showDefault - <> value "cardano.sk" + <> value (publishSigningKey defaultPublishOptions) <> help "Cardano signing key of our hydra-node. This will be used to authorize \ \Hydra protocol transactions for heads the node takes part in and any \ diff --git a/hydra-node/test/Hydra/OptionsSpec.hs b/hydra-node/test/Hydra/OptionsSpec.hs index d001b9f27a6..10828273485 100644 --- a/hydra-node/test/Hydra/OptionsSpec.hs +++ b/hydra-node/test/Hydra/OptionsSpec.hs @@ -26,6 +26,7 @@ import Hydra.Options ( defaultDirectChainConfig, defaultLedgerConfig, defaultOfflineChainConfig, + defaultPublishOptions, defaultRunOptions, outputFile, parseHydraCommandFromArgs, @@ -284,34 +285,34 @@ spec = parallel $ } describe "publish-scripts sub-command" $ do - xit "does not parse without any options" $ - shouldNotParse - [ "publish-scripts" + it "parses without any options" $ + [ "publish-scripts" + ] + `shouldParse` Publish defaultPublishOptions + + it "parses with some missing option (1)" $ + mconcat + [ ["publish-scripts"] + , ["--node-socket", "foo"] + , ["--mainnet"] ] + `shouldParse` Publish defaultPublishOptions{publishNodeSocket = "foo", publishNetworkId = Mainnet} - xit "does not parse with some missing option (1)" $ - shouldNotParse $ - mconcat - [ ["publish-scripts"] - , ["--node-socket", "foo"] - , ["--mainnet"] - ] - - xit "does not parse with some missing option (2)" $ - shouldNotParse $ - mconcat - [ ["publish-scripts"] - , ["--testnet-magic", "42"] - , ["--cardano-signing-key", "foo"] - ] - - xit "does not parse with some missing option (3)" $ - shouldNotParse $ - mconcat - [ ["publish-scripts"] - , ["--node-socket", "foo"] - , ["--cardano-signing-key", "foo"] - ] + it "parses with some missing option (2)" $ + mconcat + [ ["publish-scripts"] + , ["--testnet-magic", "42"] + , ["--cardano-signing-key", "foo"] + ] + `shouldParse` Publish defaultPublishOptions{publishSigningKey = "foo", publishNetworkId = Testnet (NetworkMagic 42)} + + it "parses with some missing option (3)" $ + mconcat + [ ["publish-scripts"] + , ["--node-socket", "foo"] + , ["--cardano-signing-key", "foo"] + ] + `shouldParse` Publish defaultPublishOptions{publishNodeSocket = "foo", publishSigningKey = "foo"} it "should parse using testnet and all options" $ mconcat