Skip to content

Commit

Permalink
Add defaults to publish-scripts parsing and use them
Browse files Browse the repository at this point in the history
  • Loading branch information
noonio committed Jan 8, 2025
1 parent ea8b03d commit 8fd0f27
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 28 deletions.
13 changes: 11 additions & 2 deletions hydra-node/src/Hydra/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down
53 changes: 27 additions & 26 deletions hydra-node/test/Hydra/OptionsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Hydra.Options (
defaultDirectChainConfig,
defaultLedgerConfig,
defaultOfflineChainConfig,
defaultPublishOptions,
defaultRunOptions,
outputFile,
parseHydraCommandFromArgs,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8fd0f27

Please sign in to comment.