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/authz)!: remove Accounts.String() #19783

Merged
merged 19 commits into from
Mar 20, 2024

Conversation

JulianToledano
Copy link
Contributor

@JulianToledano JulianToledano commented Mar 19, 2024

Description

ref:
#13140
#7448


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
  • 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.

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

  • New Features
    • Enhanced address handling and conversion across various components for improved reliability.
  • Bug Fixes
    • Fixed error handling in grant authorization processes.
    • Adjusted argument and return types in key functions to ensure consistency and error management.
  • Refactor
    • Updated the use of application services within NewKeeper.
    • Modified retrieval, conversion, and validation of addresses in CLI and keeper functionalities.
  • Tests
    • Added and updated test cases to cover the new error handling and address conversion logic.

Copy link
Contributor

coderabbitai bot commented Mar 19, 2024

Walkthrough

Walkthrough

The recent updates focus on enhancing the authz module by refining address handling, modifying function signatures, and improving error management. These changes include transitioning from direct address usage to string conversions via AddressCodec, adjusting parameter types for various functions, and introducing error returns in functions where they were previously absent. These modifications aim to enhance the robustness and flexibility of the module, enabling better interaction with addresses and improved error handling.

Changes

Files Change Summaries
x/authz/.../genesis.go, module/module.go Updated ExportGenesis to return an error. Adjusted error handling in IterateGrants.
x/authz/.../keeper.go, keeper_test.go, ... Address conversion using AddressCodec. Modified IterateGrants and error handling.
x/authz/client/cli/tx.go, tx_test.go Altered address handling and validation. Updated MsgGrant creation.
x/authz/msgs.go, msgs_test.go Changed parameter types from sdk.AccAddress to string for granter and grantee.
x/authz/simulation/... Adjusted address handling and conversion in simulations.
x/authz/CHANGELOG.md Summarized module changes including method adjustments, argument type changes, and error handling.

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
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.yml

Commits Files that changed from the base of the PR and between 65ab253 and 434dc6f.
Files selected for processing (15)
  • x/authz/CHANGELOG.md (1 hunks)
  • x/authz/client/cli/tx.go (3 hunks)
  • x/authz/client/cli/tx_test.go (22 hunks)
  • x/authz/keeper/genesis.go (1 hunks)
  • x/authz/keeper/genesis_test.go (1 hunks)
  • x/authz/keeper/grpc_query_test.go (16 hunks)
  • x/authz/keeper/keeper.go (3 hunks)
  • x/authz/keeper/keeper_test.go (8 hunks)
  • x/authz/keeper/msg_server_test.go (23 hunks)
  • x/authz/module/abci_test.go (2 hunks)
  • x/authz/module/module.go (1 hunks)
  • x/authz/msgs.go (3 hunks)
  • x/authz/msgs_test.go (1 hunks)
  • x/authz/simulation/genesis.go (4 hunks)
  • x/authz/simulation/operations.go (5 hunks)
Additional comments: 63
x/authz/keeper/genesis.go (2)
  • 41-67: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [12-33]

The changes in InitGenesis correctly handle address conversion and error propagation. Good use of AddressCodec().StringToBytes for converting address strings to bytes.

  • 44-66: The changes in ExportGenesis correctly handle address conversion from bytes to strings and error propagation. Proper use of AddressCodec().BytesToString for address conversion.
x/authz/simulation/genesis.go (2)
  • 27-37: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [20-34]

The changes in genGrant correctly handle address conversion from bytes to strings using the passed address.Codec. Proper use of BytesToString for address conversion.

  • 65-65: The changes in RandomizedGenState correctly pass simState.AddressCodec to genGrant, ensuring consistent address conversion.
x/authz/msgs.go (3)
  • 23-26: The changes to NewMsgGrant correctly update granter and grantee to use string types for addresses, aligning with the broader refactor.
  • 74-77: The changes to NewMsgRevoke correctly update granter and grantee to use string types for addresses.
  • 71-86: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [83-95]

The changes to NewMsgExec correctly update grantee to use a string type for the address.

x/authz/keeper/genesis_test.go (1)
  • 84-97: The changes in TestImportExportGenesis correctly handle errors returned by ExportGenesis and InitGenesis, ensuring proper testing of genesis state import and export operations.
x/authz/module/abci_test.go (1)
  • 71-78: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [74-91]

The changes in TestExpiredGrantsQueue correctly use the address codec to convert addresses to strings for error messages and query parameters, aligning with the broader refactor.

x/authz/module/module.go (1)
  • 137-140: The changes in ExportGenesis correctly handle errors returned by am.keeper.ExportGenesis(ctx), improving error handling in the module's genesis export process.
x/authz/msgs_test.go (1)
  • 75-75: The changes in TestAminoJSON correctly update the method used for address conversion to valAddressCodec.StringToBytes, ensuring consistency in address handling.
x/authz/keeper/grpc_query_test.go (3)
  • 24-27: The conversion of addresses from bytes to string using BytesToString is correctly implemented. However, ensure that the AddressCodec is properly mocked or initialized in the test setup to avoid potential nil pointer dereferences during tests.
  • 47-47: The changes to use string representations for Granter and Grantee in various requests align with the PR's objective to standardize address handling. This approach simplifies the handling of addresses across the module. Ensure that all corresponding functions and methods that consume these addresses are updated to work with string types instead of sdk.AccAddress.

Also applies to: 57-58, 69-70, 82-83, 103-104, 140-141, 164-164, 175-175, 185-185, 213-214, 239-239, 248-248, 259-259, 268-268

  • 305-308: The conversion of an address to a string for inclusion in the AllowList of a SendAuthorization is correctly implemented. This change is consistent with the overall goal of standardizing address handling. Just ensure that the AllowList is properly utilized in all relevant authorization checks.
x/authz/client/cli/tx.go (3)
  • 70-73: The conversion of the grantee address from bytes to string using BytesToString within NewCmdExecAuthorization is correctly implemented. This change is necessary for the updated handling of addresses. Ensure that error handling is consistent and informative throughout the conversion process.
  • 112-114: The validation logic for grantee and granter addresses within NewCmdGrantAuthorization has been updated to use the AddressCodec for conversion and comparison. This is a good practice as it ensures that the addresses are in a valid format before proceeding with the authorization grant. Additionally, the check to ensure that grantee and granter are different addresses is crucial for avoiding self-grants, which could lead to unintended permissions escalation.

Also applies to: 117-124

  • 241-241: The creation of MsgGrant within NewCmdGrantAuthorization correctly uses the updated parameters, including the converted grantee and granter addresses. This change aligns with the PR's objective to standardize address handling. Ensure that the MsgGrant constructor's error handling is robust to catch any issues with the provided arguments.
x/authz/simulation/operations.go (3)
  • 126-133: The conversion of granter and grantee addresses from bytes to string within SimulateMsgGrant is correctly implemented. This change is necessary for the updated handling of addresses in simulations. Ensure that the simulation framework and any related components are properly updated to handle string addresses.
  • 216-223: The conversion of granter and grantee addresses from bytes to string within SimulateMsgRevoke is correctly implemented. This standardizes address handling in line with the PR's objectives. Ensure that all related simulation components are updated accordingly.
  • 326-326: The use of string addresses in SimulateMsgExec for the creation of MsgExec is consistent with the changes across the module. This approach simplifies the handling of addresses in simulations. Ensure that the MsgExec handling and execution logic are fully compatible with string addresses.
x/authz/keeper/msg_server_test.go (29)
  • 39-42: The conversion of sdk.AccAddress to string using BytesToString is correctly implemented for both granter and grantee. This aligns with the PR's objective to standardize address handling.
  • 56-57: Using string representations for Granter and Grantee in authz.MsgGrant is consistent with the changes made across the module for address handling. This ensures that the tests reflect the updated logic in the main codebase.
  • 71-71: Correctly using the string representation for Grantee in the test case "invalid granter" ensures that the test accurately reflects the expected behavior with the updated address handling.
  • 84-84: The use of string representation for Granter in the "invalid grantee" test case is consistent with the module's updated address handling approach. This change is necessary for the tests to remain valid and effective.
  • 96-97: The test case for "invalid grant" correctly uses string representations for both Granter and Grantee. This consistency is crucial for ensuring that the tests accurately reflect the changes made in the module.
  • 113-114: In the "invalid grant, past time" test case, using string representations for addresses aligns with the module's updated logic. This ensures that the tests are in sync with the main codebase's approach to address handling.
  • 134-140: The test case for "grantee account does not exist on chain: valid grant" correctly converts a new account address to a string representation. This demonstrates the flexibility and correctness of the updated address handling in test scenarios.
  • 151-152: Using string representations for Granter and Grantee in the "valid grant" test case is appropriate and aligns with the module's updated address handling logic. This ensures that the tests accurately reflect the changes.
  • 163-173: The test case "valid grant, same grantee, granter pair but different msgType" correctly uses string representations for addresses. This consistency across test cases is crucial for validating the updated logic in the module.
  • 184-185: In the "valid grant with allow list" test case, using string representations for addresses ensures that the test is aligned with the module's updated address handling approach. This change is necessary for the tests to remain relevant.
  • 196-197: The "valid grant with nil expiration time" test case correctly uses string representations for addresses. This consistency across test cases is important for ensuring that the tests accurately reflect the updated module logic.
  • 221-224: The conversion of sdk.AccAddress to string using BytesToString for both granter and grantee in the TestRevoke function is correctly implemented. This aligns with the PR's objective to standardize address handling in tests.
  • 236-237: Using string representations for Granter and Grantee in the authz.MsgRevoke struct within the "identical grantee and granter" test case is consistent with the changes made across the module. This ensures that the tests reflect the updated logic.
  • 249-249: Correctly using the string representation for Grantee in the "invalid granter" test case of the TestRevoke function ensures that the test accurately reflects the expected behavior with the updated address handling.
  • 260-260: The use of string representation for Granter in the "invalid grantee" test case of the TestRevoke function is consistent with the module's updated address handling approach. This change is necessary for the tests to remain valid and effective.
  • 272-273: In the "no msg given" test case of the TestRevoke function, using string representations for addresses aligns with the module's updated logic. This ensures that the tests are in sync with the main codebase's approach to address handling.
  • 286-287: Using string representations for Granter and Grantee in the "valid grant" test case of the TestRevoke function is appropriate and aligns with the module's updated address handling logic. This ensures that the tests accurately reflect the changes.
  • 296-297: The "no existing grant to revoke" test case in the TestRevoke function correctly uses string representations for both Granter and Grantee. This consistency is crucial for ensuring that the tests accurately reflect the changes made in the module.
  • 323-326: The conversion of sdk.AccAddress to string using BytesToString for both granter and grantee in the TestExec function is correctly implemented. This aligns with the PR's objective to standardize address handling in tests.
  • 330-331: In the TestExec function, using string representations for FromAddress and ToAddress in the banktypes.MsgSend struct is consistent with the changes made across the module. This ensures that the tests reflect the updated logic.
  • 344-344: The "invalid grantee (empty)" test case in the TestExec function correctly uses an empty string for the grantee address. This test case is important for ensuring that the updated logic properly handles edge cases.
  • 352-352: Using the string representation for the grantee address in the "non existing grant" test case of the TestExec function aligns with the module's updated address handling approach. This ensures that the test remains relevant and effective.
  • 360-360: In the "no message case" test case of the TestExec function, using the string representation for the grantee address is consistent with the updated logic in the module. This change is necessary for the tests to accurately reflect the main codebase's approach.
  • 369-369: The "valid case" test case in the TestExec function correctly uses string representations for addresses. This consistency across test cases is crucial for validating the updated logic in the module.
  • 391-394: The conversion of sdk.AccAddress to string using BytesToString for addresses in the TestPruneExpiredGrants function is correctly implemented. This aligns with the PR's objective to standardize address handling in tests.
  • 403-404: In the TestPruneExpiredGrants function, using string representations for Granter and Grantee in the authz.MsgGrant struct is consistent with the changes made across the module. This ensures that the tests reflect the updated logic.
  • 410-411: Correctly using the string representation for addresses in the second authz.MsgGrant struct within the TestPruneExpiredGrants function ensures that the test accurately reflects the expected behavior with the updated address handling.
  • 417-419: The iteration over grants in the TestPruneExpiredGrants function correctly counts the total grants without any changes to the logic. This part of the test remains unaffected by the address handling updates and is correctly implemented.
  • 428-434: The pruning of expired grants in the TestPruneExpiredGrants function is correctly implemented. The test accurately reflects the updated logic in the module, ensuring that expired grants are properly handled.
x/authz/keeper/keeper.go (3)
  • 200-208: The conversion of sdk.AccAddress to string using BytesToString for both granter and grantee in the SaveGrant function is correctly implemented. This aligns with the PR's objective to standardize address handling and ensures that events are emitted with the correct address format.
  • 238-245: In the DeleteGrant function, converting sdk.AccAddress to string for both granter and grantee before emitting the EventRevoke is correctly done. This change is necessary for the events to reflect the updated address handling logic.
  • 302-319: The update to the IterateGrants function signature to include an error in the return type of the handler function is a good practice. It allows for better error handling and propagation, aligning with the PR's objective to enhance error reporting in the module.
x/authz/keeper/keeper_test.go (4)
  • 158-161: The IterateGrants function now correctly handles errors, which is a significant improvement in error handling. However, it's important to ensure that all callers of this function properly handle the returned error to avoid ignoring potential issues during iteration.
  • 172-177: Converting addresses from bytes to strings using s.accountKeeper.AddressCodec().BytesToString is a good practice for consistency and readability. Ensure that error handling is consistently applied wherever address conversions are performed to prevent runtime panics.
  • 190-194: Using string representations for addresses in message creation is consistent with the changes made throughout the module. This approach simplifies address handling and aligns with the broader refactor. Ensure that all message creation and handling throughout the tests and module correctly use the string representation.
  • 322-327: The conversion of addresses to strings before using them in message creation is correctly implemented here. This change enhances consistency in how addresses are handled across the module. It's crucial to ensure that all parts of the codebase that interact with addresses follow this pattern to maintain consistency.
x/authz/client/cli/tx_test.go (7)
  • 83-84: Converting the validator address to a string using s.baseCtx.AddressCodec.BytesToString is consistent with the module's changes. This ensures that addresses are handled uniformly across the module. It's important to apply this conversion consistently and handle any potential errors.
  • 98-99: The conversion of grantee addresses to strings before using them in authorization commands is correctly implemented. This change aligns with the broader refactor of address handling within the module. Consistent error handling for address conversions is crucial to avoid runtime issues.
  • 119-120: Correctly converting grantee addresses to strings for use in authorization commands is a good practice. This consistency in address handling simplifies the code and aligns with the module's refactor. Ensure that error handling for address conversions is consistently applied.
  • 138-139: The conversion of grantee addresses to strings before using them in authorization commands is correctly implemented here. This approach enhances consistency in address handling across the module. It's important to ensure that error handling for address conversions is consistently applied to prevent issues.
  • 181-187: Using string representations for addresses in the MsgSend message creation is consistent with the changes made throughout the module. This simplifies address handling and aligns with the broader refactor. Ensure that all message creation and handling throughout the tests and module correctly use the string representation.
  • 197-200: Converting addresses to strings using s.clientCtx.ValidatorAddressCodec.BytesToString and s.baseCtx.AddressCodec.BytesToString is a good practice for consistency and readability. Ensure that error handling is consistently applied wherever address conversions are performed to prevent runtime panics.
  • 203-204: The conversion of grantee addresses to strings before using them in test cases is correctly implemented. This change aligns with the broader refactor of address handling within the module. Consistent error handling for address conversions is crucial to avoid runtime issues.

x/authz/CHANGELOG.md 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: 8

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 434dc6f and 819adba.
Files selected for processing (1)
  • x/authz/CHANGELOG.md (1 hunks)

x/authz/CHANGELOG.md Show resolved Hide resolved
x/authz/CHANGELOG.md Show resolved Hide resolved
x/authz/CHANGELOG.md Show resolved Hide resolved
x/authz/CHANGELOG.md Show resolved Hide resolved
x/authz/CHANGELOG.md Show resolved Hide resolved
x/authz/CHANGELOG.md Show resolved Hide resolved
x/authz/CHANGELOG.md Show resolved Hide resolved
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, thank you

@facundomedica facundomedica added this pull request to the merge queue Mar 20, 2024
Merged via the queue into main with commit fa19df1 Mar 20, 2024
60 of 63 checks passed
@facundomedica facundomedica deleted the julian/authz-accstring-removal branch March 20, 2024 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants