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

refactor(x/feegrant)!: audit QA v0.52 #21377

Merged
merged 6 commits into from
Aug 26, 2024
Merged

Conversation

JulianToledano
Copy link
Contributor

@JulianToledano JulianToledano commented Aug 21, 2024

Description

Ref:
#20955


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Simplified simulation functions for granting and revoking allowances by removing unnecessary parameters.
    • Enhanced documentation for error handling in the fee allowance functions.
  • Bug Fixes

    • Clarified error responses when allowances do not exist.
  • Refactor

    • Streamlined test cases structure for better readability and maintenance.
    • Improved handling of fee allowances and message mappings for efficiency.
  • Documentation

    • Updated comments and documentation for clarity and consistency.

Copy link
Contributor

coderabbitai bot commented Aug 21, 2024

Walkthrough

Walkthrough

The changes across the x/feegrant module involve a series of refactorings aimed at simplifying function signatures, enhancing error handling, and improving test case structures. Notably, the requirement for codec parameters has been removed from several simulation functions, indicating a shift in interface design. Additionally, there are improvements in documentation clarity, variable initialization, and overall readability throughout various test files.

Changes

Files Grouped Change Summary
tests/sims/feegrant/operations_test.go, x/feegrant/CHANGELOG.md, x/feegrant/module/module.go, x/feegrant/simulation/operations.go Removal of ProtoCodec from function signatures for SimulateMsgGrantAllowance, SimulateMsgRevokeAllowance, and WeightedOperations, indicating a refactor in the simulation logic.
x/feegrant/basic_fee.go, x/feegrant/filtered_fee.go Updates to method parameters to indicate unused variables with underscores, enhancing code clarity.
x/feegrant/basic_fee_test.go, x/feegrant/filtered_fee_test.go Simplification of variable initialization and loop structures in tests for better readability.
x/feegrant/client/cli/tx_test.go, x/feegrant/fees.go Minor textual corrections in comments for clarity, without functional impact.
x/feegrant/keeper/keeper.go, x/feegrant/keeper/keeper_test.go Changes in error handling and test case simplifications, improving readability and understanding of feegrant mechanisms.
x/feegrant/keeper/msg_server_test.go Restructured test cases with named fields for better readability and organization.
x/feegrant/migrations/v2/store.go, x/feegrant/mock_test.go Improvements in error handling and simplification of method signatures by removing unused parameter names.
x/feegrant/filtered_fee.go Changes in return types for message allowance mappings, optimizing data structure usage.

Sequence Diagram(s)

sequenceDiagram
    participant App as Application
    participant Feegrant as Feegrant Module
    participant Simulation as Simulation Functions

    App->>Feegrant: Request Grant Allowance
    Feegrant->>Simulation: Simulate Grant Allowance (no codec)
    Simulation-->>Feegrant: Return Grant Result
    Feegrant-->>App: Allowance Granted

    App->>Feegrant: Request Revoke Allowance
    Feegrant->>Simulation: Simulate Revoke Allowance (no codec)
    Simulation-->>Feegrant: Return Revoke Result
    Feegrant-->>App: Allowance Revoked
Loading

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 testing code 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 testing code 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 testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@JulianToledano JulianToledano mentioned this pull request Aug 21, 2024
28 tasks
@JulianToledano JulianToledano added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Aug 21, 2024
@github-actions github-actions bot added the C:CLI label Aug 22, 2024
@JulianToledano JulianToledano marked this pull request as ready for review August 22, 2024 11:35
@JulianToledano JulianToledano requested a review from a team as a code owner August 22, 2024 11:35
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.

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (1)
x/feegrant/keeper/msg_server_test.go (1)

Issue with Pruning Logic in TestPruneAllowances

The test function TestPruneAllowances confirms that only 75 out of 76 allowances are pruned, leaving one allowance remaining. This indicates a potential issue with the pruning logic in the PruneAllowances method.

  • File: x/feegrant/keeper/msg_server_test.go
  • Lines: 362-374

The test setup and assertions correctly identify this discrepancy, suggesting a need to review the PruneAllowances method for potential bugs or edge cases.

Analysis chain

Line range hint 299-355: Verify pruning logic in TestPruneAllowances.

The comment indicates that only 75 out of 76 allowances are pruned, which might suggest an issue in the logic.

Ensure that the test results align with the expected behavior.
Run the following script to verify the logic:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify pruning logic in TestPruneAllowances.

# Test: Search for the logic related to pruning allowances. Expect: Correct handling of expired allowances.
rg --type go -A 10 $'func (suite *KeeperTestSuite) TestPruneAllowances()' | grep -E 'prune|count'

Length of output: 98


Script:

#!/bin/bash
# Description: Capture the entire implementation of TestPruneAllowances to analyze the pruning logic.

# Extract the full function implementation for TestPruneAllowances
ast-grep --lang go --pattern 'func (suite *KeeperTestSuite) TestPruneAllowances() { $$$ }'

Length of output: 4530

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fb7775a and 6843126.

Files selected for processing (16)
  • tests/sims/feegrant/operations_test.go (4 hunks)
  • x/feegrant/CHANGELOG.md (1 hunks)
  • x/feegrant/basic_fee.go (1 hunks)
  • x/feegrant/basic_fee_test.go (1 hunks)
  • x/feegrant/client/cli/tx_test.go (1 hunks)
  • x/feegrant/fees.go (1 hunks)
  • x/feegrant/filtered_fee.go (4 hunks)
  • x/feegrant/filtered_fee_test.go (1 hunks)
  • x/feegrant/keeper/keeper.go (2 hunks)
  • x/feegrant/keeper/keeper_test.go (6 hunks)
  • x/feegrant/keeper/msg_server_test.go (12 hunks)
  • x/feegrant/migrations/v2/store.go (2 hunks)
  • x/feegrant/mock_test.go (1 hunks)
  • x/feegrant/module/abci_test.go (1 hunks)
  • x/feegrant/module/module.go (1 hunks)
  • x/feegrant/simulation/operations.go (4 hunks)
Files skipped from review due to trivial changes (9)
  • tests/sims/feegrant/operations_test.go
  • x/feegrant/basic_fee.go
  • x/feegrant/basic_fee_test.go
  • x/feegrant/client/cli/tx_test.go
  • x/feegrant/fees.go
  • x/feegrant/filtered_fee_test.go
  • x/feegrant/keeper/keeper_test.go
  • x/feegrant/migrations/v2/store.go
  • x/feegrant/mock_test.go
Additional context used
Path-based instructions (7)
x/feegrant/module/abci_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/feegrant/CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

x/feegrant/filtered_fee.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/feegrant/module/module.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/feegrant/simulation/operations.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/feegrant/keeper/keeper.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/feegrant/keeper/msg_server_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

LanguageTool
x/feegrant/CHANGELOG.md

[uncategorized] ~35-~35: This verb does not appear to agree with the subject. Consider using a different form.
Context: ... SimulateMsgRevokeAllowance no longer require a ProtoCodec parameter. * `Weighted...

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)

Markdownlint
x/feegrant/CHANGELOG.md

35-35: Expected: 4; Actual: 2
Unordered list indentation

(MD007, ul-indent)


36-36: Expected: 4; Actual: 2
Unordered list indentation

(MD007, ul-indent)

Additional comments not posted (11)
x/feegrant/module/abci_test.go (2)

92-99: LGTM! Improved test structure.

The consolidation of queryRequest and the rearrangement of operations enhance readability and maintainability.


96-111: Verify test coverage.

Ensure that the test covers all scenarios, including edge cases for allowance pruning.

Run the following script to check for additional test functions related to feegrant pruning:

Verification successful

Test Coverage Verified for Feegrant Pruning

The TestFeegrantPruning function adequately covers the scenarios for feegrant pruning, including the handling of expired allowances. The test verifies the expected behavior by checking the number of allowances before and after pruning operations.

  • The test includes allowances with expiration and spend limits.
  • It ensures that expired allowances are pruned correctly.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for additional test functions related to feegrant pruning.

# Test: Search for test functions in the module. Expect: Comprehensive coverage.
rg --type go -A 5 'func TestFeegrantPruning'

Length of output: 577


Script:

#!/bin/bash
# Extract the full implementation of the TestFeegrantPruning function to verify its coverage.
ast-grep --lang go --pattern 'func TestFeegrantPruning($$$) { $$$ }'

Length of output: 6004

x/feegrant/filtered_fee.go (3)

66-72: LGTM! Improved clarity in SetAllowance.

The separation of error handling from the assignment operation enhances clarity.


Line range hint 100-111: LGTM! Optimized data structure in allowedMsgsToMap.

The change to map[string]struct{} is a common practice to save memory.


131-131: Verify logic correctness in allMsgTypesAllowed.

Ensure that the change in map lookup logic maintains the intended functionality.

Run the following script to check for test functions covering allMsgTypesAllowed:

Verification successful

Logic Correctness Verified in allMsgTypesAllowed: The logic change in the map lookup within allMsgTypesAllowed is likely covered by existing tests for AllowedMsgAllowance. These tests are found in x/feegrant/filtered_fee_test.go and should ensure that the intended functionality is maintained.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for test functions covering `allMsgTypesAllowed`.

# Test: Search for test functions in the module. Expect: Comprehensive coverage.
rg --type go -A 5 'allMsgTypesAllowed'

Length of output: 840


Script:

#!/bin/bash
# Description: Search for test functions related to `AllowedMsgAllowance` to find indirect tests for `allMsgTypesAllowed`.

# Test: Search for test functions in the module. Expect: Comprehensive coverage.
rg --type go -A 5 'AllowedMsgAllowance'

Length of output: 43384

x/feegrant/module/module.go (1)

173-174: Verify the correctness of parameter removal in WeightedOperations.

The removal of am.registry and simState.Cdc simplifies the function call. Ensure that these parameters are no longer required by the simulation.WeightedOperations function.

Run the following script to confirm the function signature and usage:

Verification successful

Verified: Parameter removal in WeightedOperations is correct.

The parameters am.registry and simState.Cdc are not required by the WeightedOperations function in x/feegrant/simulation/operations.go. The function signature confirms that these parameters have been correctly removed.

  • The function signature includes appParams, txConfig, ak, bk, and k, matching the updated call.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the function signature and usage of `simulation.WeightedOperations`.

# Test: Search for the function definition and usage. Expect: No requirement for `registry` and `Cdc`.
ast-grep --lang go --pattern 'func WeightedOperations($_, $_, $_, $_, $_) simulation.WeightedOperations'

Length of output: 4048

x/feegrant/simulation/operations.go (1)

55-59: Verify the removal of codec parameters in SimulateMsgGrantAllowance and SimulateMsgRevokeAllowance.

The removal of the codec parameter simplifies the function calls. Ensure that these functions do not require the codec for their operations.

Run the following script to confirm the function signatures and usage:

Verification successful

Codec parameters successfully removed from function calls.

The functions SimulateMsgGrantAllowance and SimulateMsgRevokeAllowance no longer require codec parameters, simplifying their usage. The codec is not used in their operations.

  • SimulateMsgGrantAllowance and SimulateMsgRevokeAllowance do not include codec parameters in their signatures.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the function signatures and usage of `SimulateMsgGrantAllowance` and `SimulateMsgRevokeAllowance`.

# Test: Search for the function definitions and usage. Expect: No requirement for codec parameters.
ast-grep --lang go --pattern 'func SimulateMsgGrantAllowance($_, $_, $_, $_) simtypes.Operation'
ast-grep --lang go --pattern 'func SimulateMsgRevokeAllowance($_, $_, $_, $_) simtypes.Operation'

Length of output: 9563

x/feegrant/keeper/keeper.go (2)

193-193: Clarify the documentation for GetAllowance.

The updated documentation now correctly indicates that collections.ErrNotFound is returned when no allowance exists. Ensure that this behavior is consistently implemented and documented across the codebase.


233-242: Refactor UseGrantedFees for improved clarity.

The refactor separates the revocation logic from the event emission logic, enhancing readability. Ensure that the functionality remains correct and consistent with the intended behavior.

x/feegrant/keeper/msg_server_test.go (2)

Line range hint 32-44: Improved readability with structured test cases.

The refactoring to use structured test cases with named fields enhances clarity and maintainability.

Ensure that all edge cases are covered in the tests.

Run the following script to verify the test coverage:

Also applies to: 47-59, 62-89, 92-106, 109-123, 126-140, 143-160, 163-182, 185-202


228-235: Improved readability with structured test cases.

The refactoring to use structured test cases with named fields enhances clarity and maintainability.

Ensure that all edge cases are covered in the tests.

Run the following script to verify the test coverage:

Also applies to: 238-245, 248-255, 258-287, 290-297

Verification successful

Comprehensive test coverage verified for TestRevokeAllowance.

The TestRevokeAllowance function includes structured test cases that cover various scenarios, ensuring thorough testing of the functionality. The original review comment's suggestion to verify test coverage is satisfied.

  • Test cases include scenarios for invalid granter, invalid grantee, fee allowance not found, successful revocation, and checking fee allowance revoked.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify test coverage for TestRevokeAllowance.

# Test: Search for all test cases in TestRevokeAllowance. Expect: Comprehensive coverage.
rg --type go -A 5 $'func (suite *KeeperTestSuite) TestRevokeAllowance()' | grep -E 'name:'

Length of output: 89


Script:

#!/bin/bash
# Check if the TestRevokeAllowance function exists in the codebase and gather its structure.
ast-grep --lang go --pattern 'func (suite *KeeperTestSuite) TestRevokeAllowance() { $$$ }'

Length of output: 6575

x/feegrant/CHANGELOG.md Show resolved Hide resolved
x/feegrant/CHANGELOG.md Show resolved Hide resolved
@@ -28,7 +28,6 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codecaddress "github.com/cosmos/cosmos-sdk/codec/address"
Copy link
Member

Choose a reason for hiding this comment

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

nice!!

Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

nice cleanup!!

@JulianToledano JulianToledano changed the title refactor(x/feegrant): audit QA v0.52 refactor(x/feegrant)!: audit QA v0.52 Aug 22, 2024
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

nice changes! worried about one behavior change.

x/feegrant/keeper/keeper.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.

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6843126 and 23ebbbc.

Files selected for processing (1)
  • x/feegrant/keeper/keeper.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/feegrant/keeper/keeper.go

@julienrbrt julienrbrt added this pull request to the merge queue Aug 26, 2024
Merged via the queue into main with commit 59e0a3d Aug 26, 2024
77 checks passed
@julienrbrt julienrbrt deleted the julian/feegrant-v0.52-audit branch August 26, 2024 07:55
mergify bot pushed a commit that referenced this pull request Aug 26, 2024
julienrbrt pushed a commit that referenced this pull request Aug 26, 2024
Co-authored-by: Julián Toledano <JulianToledano@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release C:CLI C:Simulations C:x/feegrant
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants