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

x/upgrade: Refactor CLI to use protobuf query #6623

Merged
merged 30 commits into from
Jul 8, 2020
Merged

Conversation

amaury1093
Copy link
Contributor

@amaury1093 amaury1093 commented Jul 7, 2020

Description

ref: #5921

  • refactor CLI to use protobuf query
  • refactor gRPC test to use test suite

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

@codecov
Copy link

codecov bot commented Jul 7, 2020

Codecov Report

Merging #6623 into master will increase coverage by 0.02%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master    #6623      +/-   ##
==========================================
+ Coverage   57.50%   57.52%   +0.02%     
==========================================
  Files         500      500              
  Lines       30024    30013      -11     
==========================================
+ Hits        17264    17266       +2     
+ Misses      11515    11503      -12     
+ Partials     1245     1244       -1     

// GetPlanCmd returns the query upgrade plan command
func GetPlanCmd(storeName string, cdc *codec.Codec) *cobra.Command {
// GetCurrentPlanCmd returns the query upgrade plan command
func GetCurrentPlanCmd(clientCtx client.Context) *cobra.Command {
Copy link
Contributor Author

@amaury1093 amaury1093 Jul 7, 2020

Choose a reason for hiding this comment

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

note: just a rename to follow same convention everywhere in x/upgrade: *CurrentPlan* and *AppliedPlan*

}

// always output json as Header is unreable in toml ([]byte is a long list of numbers)
bz, err = cdc.MarshalJSONIndent(headers.BlockMetas[0], "", " ")
bz, err := clientCtx.Codec.MarshalJSONIndent(headers.BlockMetas[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.

didn't find BlockMetas in tm's proto files, so not using protobuf here

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

Hi @amaurymartiny, thanks for contributing! Since we're modifying the commands and some tests here, we may as well update x/upgrade to follow in-process integration tests (#6423). Otherwise, some of the work you have here would get wiped out in a few days.

Is this something you think you can tackle? x/bank has already been upgraded so you can follow that as an easy example.

@amaury1093
Copy link
Contributor Author

sounds good, I'll do that in this PR

x/upgrade/keeper/grpc_query_test.go Outdated Show resolved Hide resolved
x/upgrade/keeper/grpc_query_test.go Outdated Show resolved Hide resolved
@aaronc
Copy link
Member

aaronc commented Jul 7, 2020

Hi @amaurymartiny, thanks for contributing! Since we're modifying the commands and some tests here, we may as well update x/upgrade to follow in-process integration tests (#6423). Otherwise, some of the work you have here would get wiped out in a few days.

Is this something you think you can tackle? x/bank has already been upgraded so you can follow that as an easy example.

@alexanderbez currently there are no integration tests (AFAIK) for the upgrade module. I think it would be great if we did but this is actually pretty involved and would likely only make sense by building actual binaries (not the in-process test suite) and using cosmosd. The tests that are here are just unit tests I believe and for better or worse we may need to leave the upgrade CLI untested for now.

@alexanderbez
Copy link
Contributor

@aaronc regardless of what is tested, it still needs to be refactored. Namely,

  1. client.Context is no longer an argument to the command constructor
  2. Remove all queryClient := types.NewQueryClient(clientCtx.Init()) calls (or any New* Init* calls)

@amaury1093
Copy link
Contributor Author

@alexanderbez I'd love a pointer on how to move this PR forward.

  1. client.Context is no longer an argument to the command constructor

  2. Remove all queryClient := types.NewQueryClient(clientCtx.Init()) calls (or any New* Init* calls)

Had a look in x/bank, and it uses client.Context and defines queryClient; i was trying to do sthg similar here.

func GetQueryCmd(clientCtx client.Context) *cobra.Command {

The tests I'm refactoring here are keeper unit tests, I believe they are not relevant to #6423.

@alexanderbez
Copy link
Contributor

The tests I'm refactoring here are keeper unit tests, I believe they are not relevant to #6423.

Indeed, my mistake, it's not relevant. But the changes required I laid out in #6623 (comment).

As you can tell from x/bank, it no longer takes a client.Context argument. You'll need to do the same. Instead, it gets the context from clientCtx := client.GetClientContextFromCmd(cmd). This is all you need to do.

Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

LGTM @amaurymartiny. Minor comments

x/upgrade/module.go Outdated Show resolved Hide resolved
x/upgrade/client/cli/query.go Show resolved Hide resolved
@amaury1093 amaury1093 marked this pull request as draft July 7, 2020 18:25

return cmd
}

// NewCmdSubmitUpgradeProposal implements a command handler for submitting a software upgrade proposal transaction.
func NewCmdSubmitUpgradeProposal(clientCtx client.Context) *cobra.Command {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This still needs to be updated: see #6639 for reference

Copy link
Contributor Author

@amaury1093 amaury1093 Jul 8, 2020

Choose a reason for hiding this comment

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

I actually went down this path, but it requires a bigger refactor:

what I propose:

  • leave this PR scoped to x/upgrade, as initially intended
  • I'll take care of one follow-up PR to refactor all x/{distribution,params,upgrade} at once once those PRs are merged

@aaronc aaronc mentioned this pull request Jul 8, 2020
43 tasks
@fedekunze fedekunze added the A:automerge Automatically merge PR once all prerequisites pass. label Jul 8, 2020
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

LGTM! Left two minor comments.

x/upgrade/client/cli/query.go Outdated Show resolved Hide resolved
x/upgrade/client/cli/query.go Outdated Show resolved Hide resolved
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

ACK 🎉

@mergify mergify bot merged commit f8df05f into master Jul 8, 2020
@mergify mergify bot deleted the am-cli-upgrade branch July 8, 2020 22:00
@clevinson clevinson added this to the v0.40 [Stargate] milestone Jul 9, 2020
@clevinson clevinson linked an issue Jul 9, 2020 that may be closed by this pull request
43 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. C:x/upgrade
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Query Protobuf Migration
6 participants