Skip to content

Commit

Permalink
CLI unit-testing for all commands with at least one argument (#2352)
Browse files Browse the repository at this point in the history
* Adding unit tests for all Hermes commands with at least one argument.
* Instead of manually validating the flags, the validation is done by `clap` for commands `create channel`, `create connection`, `keys add` and `keys delete`.
* Minor changes to the guide.
* Updated the ADR 010 with the new `--yes` optional flag for the command `create channel`.

---

* Updated CLI commands to take flags everywhere and updated e2e tests accordingly

* Updated gm to use flags when calling Hermes

* Added missing flags to e2e test for 'query client state' command

* Fixed flag errors in e2e tests and removed conflicting short flag.

* Removed all short flags and updated CLI commands comments

* Removed forgotten short flags.

* Updated Hermes guide with flags instead of positional arguments

* Updated script and comment with new long flags for Hermes

* Completed 'tx raw upgrade-' commands guide page. Updated Testing client upgrade guide page

* Added changelog entry

* Added example unit-tests to the 'keys add' command

* Added value names to parameters and removed cli parsing unit-tests

* Cargo fmt changes

* Updated flags in order to reflect ADR 010

* Updated guide to reflect flag changes from ADR 010

* Updated gm script and e2e tests to match flag changes from ADR 010

* Fixed ADR 010 typo

* Added unit-testing CLI argument parsing

* Updated unit tests for CLI and improved help output

* Improved 'override_usage' for commands with multiple usages

* Updated Hermes guide. Removed changes for issue #2349, they will be added in a separate PR.

* Removed manual validation for 'keys add' and 'keys delete' flags.

* Added changelog entry

* Updated unit tests for command 'clear packets' to include new optional flags

* Cargo fmt

* Fixed 'keys add' in ADR 010 and added shell completion unit test for case with no flag

* Fix clippy warnings introduced in Rust 1.62

Co-authored-by: Romain Ruetschi <romain@informal.systems>
  • Loading branch information
ljoss17 and romac committed Jul 4, 2022
1 parent 16c356a commit 058cbe9
Show file tree
Hide file tree
Showing 46 changed files with 3,140 additions and 153 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add unit tests for all Hermes commands with at least one argument
([#2358](https://github.com/informalsystems/ibc-rs/issues/2358))
15 changes: 9 additions & 6 deletions docs/architecture/adr-010-unified-cli-arguments-hermes.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,17 @@ The following commands are implemented, with the binary name `hermes` often omit
### Create a channel

* `create channel --a-chain <A_CHAIN_ID> --a-connection <A_CONNECTION_ID> --a-port <A_PORT_ID> --b-port <B_PORT_ID>`
* Optional: `[--chan-version <VERSION>] [--order <ORDER>]`
* Optional: `[--channel-version <VERSION>] [--order <ORDER>]`

* `create channel --a-chain <A_CHAIN_ID> --b-chain <B_CHAIN_ID> --a-port <A_PORT_ID> --b-port <B_PORT_ID> --new-client-conn`
* Optional: `[--chan-version <VERSION>] [--order <ORDER>]`
* `create channel --a-chain <A_CHAIN_ID> --b-chain <B_CHAIN_ID> --a-port <A_PORT_ID> --b-port <B_PORT_ID> --new-client-connection`
* Optional: `[--channel-version <VERSION>] [--order <ORDER>] [--yes]`

### Commands for keys

* `keys add --chain <CHAIN_ID> --key-file <KEY_FILE> --mnemonic-file <MNEMONIC_FILE>`
* `keys add --chain <CHAIN_ID> --key-file <KEY_FILE>`
* Optional: `[--hd-path <HD_PATH>] [--key-name <KEY_NAME>]`

* `keys add --chain <CHAIN_ID> --mnemonic-file <MNEMONIC_FILE>`
* Optional: `[--hd-path <HD_PATH>] [--key-name <KEY_NAME>]`

* `keys balance --chain <CHAIN_ID>`
Expand Down Expand Up @@ -86,8 +89,8 @@ The following commands are implemented, with the binary name `hermes` often omit

### Clear packets

* `clear packets --chain <CHAIN_ID> --port <PORT_ID> --channel <CHANNEL_ID>
--key-name <KEY> --counterparty-key-name <KEY>`
* `clear packets [OPTIONS] --chain <CHAIN_ID> --port <PORT_ID> --channel <CHANNEL_ID>`
* Optional: `[--key-name <KEY>] [--counterparty-key-name <KEY>]`

### Queries

Expand Down
28 changes: 14 additions & 14 deletions guide/src/commands/keys/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,20 @@ DESCRIPTION:

FLAGS:
--chain <CHAIN_ID>
identifier of the chain
Identifier of the chain

--key-file <KEY_FILE>
path to the key file
Path to the key file

--mnemonic-file <MNEMONIC_FILE>
path to file containing mnemonic to restore the key from
Path to file containing mnemonic to restore the key from

OPTIONS:
--key-name <KEY_NAME>
name of the key (defaults to the `key_name` defined in the config)
Name of the key (defaults to the `key_name` defined in the config)

--hd-path <HD_PATH>
derivation path for this key [default: m/44'/118'/0'/0/0]
Derivation path for this key [default: m/44'/118'/0'/0/0]
```
#### Add a private key to a chain from a key file
Expand All @@ -102,17 +102,17 @@ DESCRIPTION:
FLAGS:
--chain <CHAIN_ID>
identifier of the chain
Identifier of the chain
--key-file <KEY_FILE>
path to the key file
Path to the key file
OPTIONS:
--key-name <KEY_NAME>
name of the key (defaults to the `key_name` defined in the config)
Name of the key (defaults to the `key_name` defined in the config)
--hd-path <HD_PATH>
derivation path for this key [default: m/44'/118'/0'/0/0]
Derivation path for this key [default: m/44'/118'/0'/0/0]
```

To add a private key file to a chain:
Expand Down Expand Up @@ -157,17 +157,17 @@ DESCRIPTION:

FLAGS:
--chain <CHAIN_ID>
identifier of the chain
Identifier of the chain

--mnemonic-file <MNEMONIC_FILE>
path to file containing mnemonic to restore the key from
Path to file containing mnemonic to restore the key from

OPTIONS:
--key-name <KEY_NAME>
name of the key (defaults to the `key_name` defined in the config)
Name of the key (defaults to the `key_name` defined in the config)

--hd-path <HD_PATH>
derivation path for this key [default: m/44'/118'/0'/0/0]
Derivation path for this key [default: m/44'/118'/0'/0/0]
```
To restore a key from its mnemonic:
Expand Down Expand Up @@ -336,4 +336,4 @@ If the command is successful a message with the following format will be display
},
"status": "success"
}
```
```
11 changes: 6 additions & 5 deletions guide/src/commands/path-setup/channels.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ USAGE:
hermes create channel [OPTIONS] --a-chain <A_CHAIN_ID> --a-port <A_PORT_ID> --b-port <B_PORT_ID>

DESCRIPTION:
Create a new channel between two chains using a pre-existing connection.
Create a new channel between two chains.

Alternatively, create a new client and a new connection underlying the new channel if a pre-existing
connection is not provided.
Can create a new channel using a pre-existing connection or alternatively, create a new client and a
new connection underlying the new channel if a pre-existing connection is not provided.

FLAGS:
--a-chain <A_CHAIN_ID> Identifier of the side `a` chain for the new channel
Expand All @@ -26,13 +26,14 @@ FLAGS:
OPTIONS:

--a-connection <A_CONNECTION_ID> Identifier of the connection on chain `a` to use in creating
the new channel.
the new channel
--b-chain <B_CHAIN_ID> Identifier of the side `b` chain for the new channel
--chan-version <VERSION> The version for the new channel
--new-client-connection Indicates that a new client and connection will be created
underlying the new channel
--order <ORDER> The channel ordering, valid options 'unordered' (default) and
'ordered' [default: ORDER_UNORDERED]
--yes Skip new_client_connection confirmation
```
## Examples
Expand Down Expand Up @@ -210,7 +211,7 @@ interactive prompt that pops up notifying you that a new client and a new
connection will be initialized as part of the process:
```shell
hermes create channel --a-chain ibc-0 --b-chain ibc-1 --a-port transfer --b-port transfer --order unordered --new-client-conn
hermes create channel --a-chain ibc-0 --b-chain ibc-1 --a-port transfer --b-port transfer --order unordered --new-client-connection
```
```json
Expand Down
6 changes: 3 additions & 3 deletions guide/src/commands/queries/channel.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ DESCRIPTION:

FLAGS:
--chain <CHAIN_ID>
identifier of the chain to query
Identifier of the chain to query

OPTIONS:
--verbose
enable verbose output, displaying the client and connection ids for each channel in the
Enable verbose output, displaying the client and connection ids for each channel in the
response
```
Expand Down Expand Up @@ -410,4 +410,4 @@ If the command is successful a message with the following format will be display
},
"status":"success"
}
```
```
16 changes: 8 additions & 8 deletions guide/src/commands/queries/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ DESCRIPTION:

FLAGS:
--host-chain <HOST_CHAIN_ID>
identifier of the chain to query
Identifier of the chain to query

OPTIONS:
--omit-chain-ids
omit printing the reference (or target) chain for each client
Omit printing the reference (or target) chain for each client

--reference-chain <REFERENCE_CHAIN_ID>
filter for clients which target a specific chain id (implies '--omit-chain-ids')
Filter for clients which target a specific chain id (implies '--omit-chain-ids')
```

__Example__
Expand Down Expand Up @@ -160,20 +160,20 @@ DESCRIPTION:

FLAGS:
--chain <CHAIN_ID>
identifier of the chain to query
Identifier of the chain to query

--client <CLIENT_ID>
identifier of the client to query
Identifier of the client to query

OPTIONS:
--consensus-height <CONSENSUS_HEIGHT>
height of the client's consensus state to query
Height of the client's consensus state to query
--height <HEIGHT>
the chain height context to be used, applicable only to a specific height
The chain height context to be used, applicable only to a specific height
--heights-only
show only consensus heights
Show only consensus heights
```
__Example__
Expand Down
1 change: 1 addition & 0 deletions guide/src/commands/queries/packet.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ SUBCOMMANDS:
pending Output a summary of pending packets in both directions
unreceived-acks Query unreceived acknowledgments
unreceived-packets Query unreceived packets
help Print this message or the help of the given subcommand(s)
```

## Table of Contents
Expand Down
2 changes: 1 addition & 1 deletion guide/src/commands/queries/tx.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ Success: [
},
),
]
```
```
22 changes: 11 additions & 11 deletions guide/src/commands/raw/packet.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,38 @@ DESCRIPTION:

FLAGS:
--amount <AMOUNT>
amount of coins (samoleans, by default) to send (e.g. `100000`)
Amount of coins (samoleans, by default) to send (e.g. `100000`)

--dst-chain <DST_CHAIN_ID>
identifier of the destination chain
Identifier of the destination chain

--src-chain <SRC_CHAIN_ID>
identifier of the source chain
Identifier of the source chain

--src-chan <SRC_CHANNEL_ID>
identifier of the source channel
Identifier of the source channel

--src-port <SRC_PORT_ID>
identifier of the source port
Identifier of the source port

OPTIONS:
--denom <DENOM>
denomination of the coins to send [default: samoleans]
Denomination of the coins to send [default: samoleans]

--key-name <KEY_NAME>
use the given signing key name (default: `key_name` config)
Use the given signing key name (default: `key_name` config)

--number-msgs <NUMBER_MSGS>
number of messages to send
Number of messages to send

--receiver <RECEIVER>
receiving account address on the destination chain
Receiving account address on the destination chain

--timeout-height-offset <TIMEOUT_HEIGHT_OFFSET>
timeout in number of blocks since current [default: 0]
Timeout in number of blocks since current [default: 0]

--timeout-seconds <TIMEOUT_SECONDS>
timeout in seconds since current [default: 0]
Timeout in seconds since current [default: 0]
```

__Example__
Expand Down
2 changes: 1 addition & 1 deletion guide/src/commands/raw/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,4 @@ hermes tx raw upgrade-chain --dst-chain ibc-0 --src-chain ibc-1 --src-client 07-

```
Success: transaction::Hash(779713508B6103E37FADE60483BEE964A90BD67E5F20037B2CC4AE0E90B707C3)
```
```
2 changes: 1 addition & 1 deletion guide/src/commands/upgrade/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,4 @@ It might be due to the chain not being at the height defined for the upgrade. Th
INFO ThreadId(01) [ibc-0 -> ibc-1:07-tendermint-0] upgrade Height: 0-82
```
Where in this case the chain is at height 82.
Where in this case the chain is at height 82.
12 changes: 8 additions & 4 deletions guide/src/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,32 @@ This can provide further specific guidance if we add additional parameters, e.g.
hermes help create channel
```

```
```shell
USAGE:
hermes create channel [OPTIONS] --a-chain <A_CHAIN_ID> --a-port <A_PORT_ID> --b-port <B_PORT_ID>

DESCRIPTION:
Create a new channel between two chains using a pre-existing connection. Alternatively, create a new
client and a new connection underlying the new channel if a pre-existing connection is not provided
Create a new channel between two chains.

Can create a new channel using a pre-existing connection or alternatively, create a new client and a
new connection underlying the new channel if a pre-existing connection is not provided.

FLAGS:
--a-chain <A_CHAIN_ID> Identifier of the side `a` chain for the new channel
--a-port <A_PORT_ID> Identifier of the side `a` port for the new channel
--b-port <B_PORT_ID> Identifier of the side `b` port for the new channel

OPTIONS:

--a-connection <A_CONNECTION_ID> Identifier of the connection on chain `a` to use in creating
the new channel.
the new channel
--b-chain <B_CHAIN_ID> Identifier of the side `b` chain for the new channel
--chan-version <VERSION> The version for the new channel
--new-client-connection Indicates that a new client and connection will be created
underlying the new channel
--order <ORDER> The channel ordering, valid options 'unordered' (default) and
'ordered' [default: ORDER_UNORDERED]
--yes Skip new_client_connection confirmation
```
Additionally, the `-h`/`--help` flags typical for CLI applications work on
Expand Down
6 changes: 3 additions & 3 deletions guide/src/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,19 @@ and any further necessary modifications to the shell's startup files.
### Bash

```sh
hermes completions bash > ~/.local/share/bash-completion/completions/hermes
hermes completions --shell bash > ~/.local/share/bash-completion/completions/hermes
```

On a MacOS installation with Homebrew `bash-completion` formula installed, use

```sh
hermes completions bash > $(brew --prefix)/etc/bash_completion.d/hermes.bash-completion
hermes completions --shell bash > $(brew --prefix)/etc/bash_completion.d/hermes.bash-completion
```

### Zsh

```sh
hermes completions zsh > ~/.zfunc/_hermes
hermes completions --shell zsh > ~/.zfunc/_hermes
```

To make the shell load the script on initialization, add the directory to `fpath`
Expand Down
2 changes: 1 addition & 1 deletion guide/src/tutorials/local-chains/raw/packet.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ Next we will test the packet timeouts.
```shell
hermes tx raw packet-recv --dst-chain ibc-1 --src-chain ibc-0 --src-port transfer --src-chan channel-0
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Perform client creation, connection and channel handshake to establish a new path between the `transfer` ports on `ibc-0` and `ibc-1` chains.

```shell
hermes create channel --a-chain ibc-0 --b-chain ibc-1 --a-port transfer --b-port transfer --new-client-conn
hermes create channel --a-chain ibc-0 --b-chain ibc-1 --a-port transfer --b-port transfer --new-client-connection
```

If all the handshakes are performed successfully you should see a message similar to the one below:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Follow the steps below to connect three chains together and relay packets betwee
making an exception. Execute the following command:

```shell
hermes create channel --a-chain ibc-0 --b-chain ibc-1 --a-port transfer --b-port transfer --new-client-conn
hermes create channel --a-chain ibc-0 --b-chain ibc-1 --a-port transfer --b-port transfer --new-client-connection
```

Then respond 'yes' to the prompt that pops up. Once the command has run to
Expand Down Expand Up @@ -166,7 +166,7 @@ Follow the steps below to connect three chains together and relay packets betwee
previous invocation we used to create a channel between `ibc-0` and `ibc-1`:

```shell
hermes create channel --a-chain ibc-1 --b-chain ibc-2 --a-port transfer --b-port transfer --new-client-conn
hermes create channel --a-chain ibc-1 --b-chain ibc-2 --a-port transfer --b-port transfer --new-client-connection
```

```json
Expand Down
Loading

0 comments on commit 058cbe9

Please sign in to comment.