Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add host cli to generate ica packet data #2297

Merged

Conversation

chatton
Copy link
Contributor

@chatton chatton commented Sep 15, 2022

Description

This PR creates a new cli command which generates ics27 packet data. I opted to display the packet data to stdout rather than writing to a file as I believe this is more flexible. In order to create a file we simply need

simd tx host generate-packet-data ...  > packet-data.json

Note: this is a tx command although it is a bit of an outlier as no tx is being broadcast. There is no good place that I can find to put this unique type of cli command so I stuck with the tx subcommand.

closes: #2243


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@lgtm-com
Copy link

lgtm-com bot commented Sep 15, 2022

This pull request introduces 1 alert when merging 1f12260 into 80ea89a - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable

@codecov-commenter
Copy link

codecov-commenter commented Sep 15, 2022

Codecov Report

Merging #2297 (7411b53) into main (b97729d) will decrease coverage by 0.94%.
The diff coverage is 51.11%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2297      +/-   ##
==========================================
- Coverage   79.54%   78.59%   -0.95%     
==========================================
  Files         175      178       +3     
  Lines       12069    12323     +254     
==========================================
+ Hits         9600     9685      +85     
- Misses       2045     2206     +161     
- Partials      424      432       +8     
Impacted Files Coverage Δ
...27-interchain-accounts/controller/keeper/events.go 0.00% <ø> (ø)
...nterchain-accounts/controller/keeper/grpc_query.go 100.00% <ø> (ø)
...nterchain-accounts/controller/keeper/msg_server.go 100.00% <ø> (ø)
...27-interchain-accounts/controller/keeper/params.go 100.00% <ø> (ø)
.../27-interchain-accounts/controller/keeper/relay.go 74.46% <ø> (+1.13%) ⬆️
...ps/27-interchain-accounts/controller/types/msgs.go 92.30% <ø> (ø)
...ps/27-interchain-accounts/genesis/types/genesis.go 0.00% <ø> (ø)
...apps/27-interchain-accounts/host/client/cli/cli.go 0.00% <0.00%> (ø)
...ps/27-interchain-accounts/host/client/cli/query.go 0.00% <ø> (ø)
...les/apps/27-interchain-accounts/host/ibc_module.go 95.00% <ø> (ø)
... and 123 more

Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work! Great test by the way!

@chatton
Copy link
Contributor Author

chatton commented Sep 23, 2022

@colin-axner thanks for the great suggestion! I adapted the link you sent and added support for both a single message in bytes, as well as a json array of messages in bytes. Tests were added for the new multi message scenario.

Copy link
Contributor

@charleenfei charleenfei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! good dev ux improvement.

Copy link
Member

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really awesome job on the tests. They're super clean and easy to reason about.
LGTM! 🚀

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done, @chatton!

Short: "Generates ICA packet data.",
Long: `generate-packet-data accepts a message string and serializes it
into packet data which is outputted to stdout. It can be used in conjunction with send-tx"
which submits pre-built packet data containing messages to be executed on the host chain.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to add an example here? Maybe we can just use the regular bank transfer message used in the example in the ica-demo repo?

'{
    "@type":"/cosmos.bank.v1beta1.MsgSend",
    "from_address":"cosmos15ccshhmp0gsx29qpqq6g4zmltnnvgmyu9ueuadh9y2nc5zj0szls5gtddz",
    "to_address":"cosmos10h9stc5v6ntgeygf5xf945njqq5h32r53uquvw",
    "amount": [
        {
            "denom": "stake",
            "amount": "1000"
        }
    ]
}'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great suggestions, I'll add this as an example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crodriguezvega I added this example and also a multi message example.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @chatton!

assertionFn func(t *testing.T, msgs []sdk.Msg)
}{
{
name: "multi message",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name: "multi message",
name: "packet data generation succeeds (MsgDelegate & MsgSend)",

banktypes.RegisterInterfaces(registry)
},
assertionFn: func(t *testing.T, msgs []sdk.Msg) {
assertMsgDelegate(t, msgs, 0)
Copy link
Contributor

@crodriguezvega crodriguezvega Sep 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a nit, but instead of passing the slice of messages and the index, couldn't you just pass msgs[0]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes you're right, this can simplify things a little bit!

func NewTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "host",
Short: "interchain-accounts host subcommands",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Short: "interchain-accounts host subcommands",
Short: "IBC interchain accounts host transaction subcommands",

See this PR.

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I left a couple of new nits! Other than that, great work!

modules/apps/27-interchain-accounts/host/client/cli/cli.go Outdated Show resolved Hide resolved
into packet data which is outputted to stdout. It can be used in conjunction with send-tx"
which submits pre-built packet data containing messages to be executed on the host chain.
`,
Example: `<binary> tx interchain-accounts host generate-packet-data '{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use version.AppName instead of <binary> like in here?

Short: "Generates ICA packet data.",
Long: `generate-packet-data accepts a message string and serializes it
into packet data which is outputted to stdout. It can be used in conjunction with send-tx"
which submits pre-built packet data containing messages to be executed on the host chain.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @chatton!

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work!

@chatton chatton enabled auto-merge (squash) September 28, 2022 10:39
@chatton chatton merged commit 8f0e7d5 into main Sep 28, 2022
@chatton chatton deleted the cian/issue#2243-add-a-ics27-host-cli-to-generate-ica-packet-data branch September 28, 2022 10:45
mergify bot pushed a commit that referenced this pull request Sep 28, 2022
(cherry picked from commit 8f0e7d5)

# Conflicts:
#	CHANGELOG.md
colin-axner added a commit that referenced this pull request Sep 28, 2022
* Add  host cli to generate ica packet data (#2297)

(cherry picked from commit 8f0e7d5)

# Conflicts:
#	CHANGELOG.md

* fix conflict

Co-authored-by: Cian Hatton <cian@interchain.io>
Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a ics27 host cli to generate ica packet data
6 participants