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 missing queries CLI #1233

Merged
merged 24 commits into from
Mar 26, 2024
Merged

Add missing queries CLI #1233

merged 24 commits into from
Mar 26, 2024

Conversation

tuantran1702
Copy link
Contributor

@tuantran1702 tuantran1702 commented Mar 5, 2024

1. Summary

Fixes #1145

2.Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

3. Implementation details

4. How to test/use

5. Checklist

  • Update tests

6. Limitations (optional)

7. Future Work (optional)

Summary by CodeRabbit

  • New Features

    • Introduced new query commands for enhanced user interaction with withdrawal records, redelegation records, validators, and transaction statuses.
    • Added functionality for users to retrieve their specific withdrawal records within a zone.
  • Improvements

    • Improved the retrieval process of withdrawal and redelegation records to enhance performance and user experience.
  • Tests

    • Implemented comprehensive tests for new functionalities, ensuring reliability and robustness of the system.

Copy link
Contributor

coderabbitai bot commented Mar 5, 2024

Walkthrough

The changes revolve around enhancing the interchain staking functionality by refining and expanding the query capabilities. They include modifications to how withdrawal and redelegation records are retrieved and tested, alongside introducing new CLI commands for a comprehensive range of queries. This update aims to fill the gaps in CLI query functionalities, particularly for unbonding and claims, ensuring users have access to necessary information through command-line interfaces.

Changes

Files Change Summary
x/interchainstaking/keeper/grpc_query.go Modified withdrawal records retrieval and added user-specific query function.
x/interchainstaking/keeper/grpc_query_test.go Added tests for new user-specific withdrawal records query.
x/interchainstaking/keeper/redelegation_record.go Altered AllRedelegationRecords to not specify a zone.
x/interchainstaking/client/cli/query.go Introduced CLI commands for various queries including withdrawal, redelegation records, and transaction status.
x/interchainstaking/client/cli/cli_test.go Added tests for new CLI commands, ensuring coverage for withdrawal records, zone redelegation, and more.

Assessment against linked issues

Objective Addressed Explanation
Add CLI commands for all grpc queries related to unbonding and claims (#1145)

🐇✨

In the realm of code, where logic intertwines,

A rabbit hopped through, making enhancements fine.

With queries and tests, it danced and it twirled,

Bringing CLI commands into the world.

🌟🌌🐰

"To the cosmos and beyond," it cheerfully said,

Ensuring no command was left in dread.

With each line of code, it leaped and it soared,

A digital rabbit, forever adored.

🚀🐇💫

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

vercel bot commented Mar 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
quicksilver ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 26, 2024 8:26am

@tuantran1702 tuantran1702 changed the title add placeholder code Add missing queries CLI Mar 5, 2024
x/interchainstaking/client/cli/query.go Fixed Show fixed Hide fixed
x/interchainstaking/client/cli/query.go Fixed Show fixed Hide fixed
x/interchainstaking/client/cli/query.go Fixed Show fixed Hide fixed
x/interchainstaking/client/cli/query.go Fixed Show fixed Hide fixed
x/interchainstaking/client/cli/query.go Fixed Show fixed Hide fixed
x/interchainstaking/client/cli/query.go Fixed Show fixed Hide fixed
x/interchainstaking/client/cli/query.go Fixed Show fixed Hide fixed
x/interchainstaking/client/cli/query.go Fixed Show fixed Hide fixed
x/interchainstaking/client/cli/query.go Fixed Show fixed Hide fixed
Copy link

codecov bot commented Mar 5, 2024

Codecov Report

Attention: Patch coverage is 70.86957% with 67 lines in your changes are missing coverage. Please review.

Project coverage is 63.48%. Comparing base (02bd08d) to head (f1b7c11).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1233      +/-   ##
==========================================
+ Coverage   63.35%   63.48%   +0.13%     
==========================================
  Files         171      171              
  Lines       11313    11536     +223     
==========================================
+ Hits         7167     7324     +157     
- Misses       3420     3469      +49     
- Partials      726      743      +17     
Flag Coverage Δ
unittests 63.48% <70.86%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
x/interchainstaking/keeper/ibc_packet_handlers.go 64.92% <ø> (ø)
x/interchainstaking/keeper/redelegation_record.go 95.83% <ø> (ø)
x/interchainstaking/keeper/grpc_query.go 89.52% <75.00%> (-1.68%) ⬇️
x/interchainstaking/client/cli/query.go 65.60% <70.56%> (+11.60%) ⬆️

@tuantran1702
Copy link
Contributor Author

Hi @joe-bowman,

I noticed that ZoneWithdrawalRecord and UserWithdrawalRecord seem to have identical functionality.

Given this, I was wondering if you think it might be worth refactoring these functions before I start working on issue #1233.
What are your thoughts on this?

@tuantran1702 tuantran1702 marked this pull request as ready for review March 7, 2024 11:32
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9fae097 and 17e6edb.
Files selected for processing (3)
  • x/interchainstaking/client/cli/query.go (2 hunks)
  • x/interchainstaking/keeper/grpc_query.go (3 hunks)
  • x/interchainstaking/keeper/redelegation_record.go (1 hunks)
Additional comments: 4
x/interchainstaking/keeper/redelegation_record.go (1)
  • 69-69: The modification to the AllRedelegationRecords function aligns with the PR's objective of removing the zone specification, making the function more generic and potentially simplifying the codebase. This change seems appropriate and does not introduce any apparent issues.
x/interchainstaking/keeper/grpc_query.go (2)
  • 247-252: The changes to the ZoneWithdrawalRecords function, which now utilizes AllZoneWithdrawalRecords for retrieving withdrawal records, simplifies the codebase and aligns with the PR's objectives. Ensure that AllZoneWithdrawalRecords correctly handles zone specifications internally.
  • 265-265: The modification to the WithdrawalRecords function, which now directly utilizes AllWithdrawalRecords, simplifies the retrieval process and aligns with the PR's objectives of codebase simplification.
x/interchainstaking/client/cli/query.go (1)
  • 33-41: The addition of new query commands for withdrawal records, user withdrawal records, zone withdrawal records, unbonding records, receipts, transaction status, zone redelegation records, zone validators, and zone information enhances the CLI's capabilities and aligns with the PR's objectives. The commands are well-structured and follow the conventions used in the rest of the file.

@faddat
Copy link
Contributor

faddat commented Mar 8, 2024

I like the idea of combining the 2 lookalike functions, just please make sure they are exactly the same

@tuantran1702 tuantran1702 marked this pull request as ready for review March 11, 2024 02:23
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c7ad1fb and e0ae89b.
Files selected for processing (2)
  • x/interchainstaking/client/cli/cli_test.go (3 hunks)
  • x/interchainstaking/client/cli/query.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • x/interchainstaking/client/cli/cli_test.go
  • x/interchainstaking/client/cli/query.go

@@ -66,6 +67,8 @@ func (s *IntegrationTestSuite) SetupSuite() {
MessagesPerTx: 0,
Is_118: true,
}

// TODO: I think setting validators here isn't enough, we need to set them in the store by using the keeper
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct; we used to keep them in the zone struct but it was horribly inefficient loading 500 vals every time we wanted to fetch the denom from a zone for example.

@joe-bowman
Copy link
Contributor

Hi @joe-bowman,

I noticed that ZoneWithdrawalRecord and UserWithdrawalRecord seem to have identical functionality.

Given this, I was wondering if you think it might be worth refactoring these functions before I start working on issue #1233. What are your thoughts on this?

I don't think this is correct. ZoneWithdrawalRecords also scopes by chainId (perhaps ought to be called UserZoneWithdrawlRecords) whereas UserWithdrawalRecords doesn't. Would be good to see where these are used though?

@tuantran1702
Copy link
Contributor Author

I don't think this is correct. ZoneWithdrawalRecords also scopes by chainId (perhaps ought to be called UserZoneWithdrawlRecords) whereas UserWithdrawalRecords doesn't. Would be good to see where these are used though?

Yeah but still the name is kind of misleading. These aren't used any where beside grpc tests, so I think it's safe to refactor.

x/interchainstaking/keeper/grpc_query.go Dismissed Show dismissed Hide dismissed
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e0ae89b and 6a201f5.
Files selected for processing (2)
  • x/interchainstaking/keeper/grpc_query.go (3 hunks)
  • x/interchainstaking/keeper/grpc_query_test.go (1 hunks)
Check Runs (1)
devskim success (4)
  • x/interchainstaking/keeper/grpc_query.go: 271-271: Suspicious comment
  • x/interchainstaking/keeper/grpc_query.go: 324-324: Suspicious comment
Additional comments: 2
x/interchainstaking/keeper/grpc_query.go (2)
  • 247-252: The change from retrieving a specific zone to using AllZoneWithdrawalRecords for the entire zone in ZoneWithdrawalRecords function simplifies the logic and potentially improves performance by reducing the need for multiple calls. However, ensure that this change aligns with the intended use cases and that all callers of this function are aware of the change in behavior.
  • 265-267: Changing the parameter in AllWithdrawalRecords from req.ChainId to ctx aligns with the standard practice of passing context objects in Go for maintaining request-scoped values, deadlines, and cancellation signals. This change is appropriate and improves the function's flexibility and adherence to Go's context passing conventions.

x/interchainstaking/keeper/grpc_query_test.go Outdated Show resolved Hide resolved
x/interchainstaking/keeper/grpc_query.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6a201f5 and adee560.
Files selected for processing (1)
  • x/interchainstaking/keeper/grpc_query.go (2 hunks)
Additional comments: 2
x/interchainstaking/keeper/grpc_query.go (2)
  • 247-252: The change from retrieving a specific zone to using AllZoneWithdrawalRecords in ZoneWithdrawalRecords function simplifies the logic and potentially improves performance by avoiding unnecessary checks for zone existence. However, ensure that this change aligns with the intended functionality and that all callers of this function are aware of the change in behavior.
  • 265-267: The change in WithdrawalRecords to use AllWithdrawalRecords(ctx) instead of filtering by req.ChainId simplifies the function and potentially broadens its use case. Ensure that this aligns with the intended use cases and that any necessary filtering by chain ID is handled elsewhere if needed.

x/interchainstaking/keeper/grpc_query.go Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between adee560 and 89a83ad.
Files selected for processing (2)
  • x/interchainstaking/keeper/grpc_query.go (2 hunks)
  • x/interchainstaking/keeper/grpc_query_test.go (1 hunks)
Check Runs (1)
test quicksilver (amd64, linux) null (5)
  • x/interchainstaking/keeper/grpc_query_test.go: [failure] 1456-1456:
    cannot use 10000000 (untyped int constant) as "cosmossdk.io/math".Int value in struct literal
  • x/interchainstaking/keeper/grpc_query_test.go: [failure] 1460-1460:
    cannot use 20000000 (untyped int constant) as "cosmossdk.io/math".Int value in struct literal
  • x/interchainstaking/keeper/grpc_query_test.go: [failure] 1494-1494:
    cannot use 10000000 (untyped int constant) as "cosmossdk.io/math".Int value in struct literal
  • x/interchainstaking/keeper/grpc_query_test.go: [failure] 1498-1498:
    cannot use 20000000 (untyped int constant) as "cosmossdk.io/math".Int value in struct literal
Additional comments: 2
x/interchainstaking/keeper/grpc_query.go (2)
  • 244-249: The change in ZoneWithdrawalRecords to use AllZoneWithdrawalRecords for data retrieval simplifies the function and potentially improves maintainability by centralizing the logic for withdrawal record retrieval. However, ensure that AllZoneWithdrawalRecords efficiently handles the data retrieval, especially considering large datasets, to avoid performance issues.
  • 262-265: The modification in WithdrawalRecords to use AllWithdrawalRecords instead of filtering by req.ChainId broadens the scope of data retrieval. This change should be carefully evaluated to ensure it aligns with the intended use cases and does not inadvertently expose more data than expected to the client.

distributions := []*types.Distribution{
{
Valoper: icsKeeper.GetValidators(ctx, suite.chainB.ChainID)[0].ValoperAddress,
Amount: 10000000,
Copy link
Contributor

@coderabbitai coderabbitai bot Mar 26, 2024

Choose a reason for hiding this comment

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

The integer constants used for the Amount field in types.Distribution structs need to be converted to math.Int type to match the expected type. Here's how you can fix it:

- Amount:  10000000,
+ Amount:  math.NewInt(10000000),

And similarly for the other instances.

Also applies to: 1460-1460, 1494-1494, 1498-1498


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
Amount: 10000000,
Amount: math.NewInt(10000000),

Copy link
Contributor

Choose a reason for hiding this comment

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

@tropicaldog - this is correct as of main. Amount is Distribution changed to math.Int in #1319

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Contributor

Choose a reason for hiding this comment

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

Ignore this; it's outdated. Appears fixed in the latest commit

x/interchainstaking/keeper/grpc_query.go Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 89a83ad and f1b7c11.
Files selected for processing (3)
  • x/interchainstaking/client/cli/cli_test.go (6 hunks)
  • x/interchainstaking/keeper/grpc_query_test.go (1 hunks)
  • x/interchainstaking/keeper/ibc_packet_handlers.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • x/interchainstaking/keeper/ibc_packet_handlers.go
Files skipped from review as they are similar to previous changes (1)
  • x/interchainstaking/keeper/grpc_query_test.go
Additional comments: 2
x/interchainstaking/client/cli/cli_test.go (2)
  • 23-23: The constant testDelegator is well-defined and follows Go naming conventions.
  • 230-250: The test case labeled "valid" in TestGetDelegatorIntentCmd is well-structured and tests the expected behavior. Ensure that the test data reflects realistic scenarios for more comprehensive testing.

x/interchainstaking/client/cli/cli_test.go Show resolved Hide resolved
x/interchainstaking/client/cli/cli_test.go Show resolved Hide resolved
x/interchainstaking/client/cli/cli_test.go Show resolved Hide resolved
Copy link
Contributor

@joe-bowman joe-bowman left a comment

Choose a reason for hiding this comment

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

lgtm

@joe-bowman joe-bowman enabled auto-merge (squash) March 26, 2024 10:19
@joe-bowman joe-bowman disabled auto-merge March 26, 2024 10:22
@joe-bowman joe-bowman merged commit f3b2d15 into main Mar 26, 2024
25 of 26 checks passed
@joe-bowman joe-bowman deleted the tuan/add-query-cli branch March 26, 2024 10:22
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 missing queries to CLI
3 participants