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/bank)!: remove Address.String() #19954

Merged
merged 6 commits into from
Apr 5, 2024

Conversation

JulianToledano
Copy link
Contributor

@JulianToledano JulianToledano commented Apr 4, 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 error handling and address conversion in various components for improved reliability and consistency.
  • Bug Fixes

    • Addressed issues with address handling by converting addresses to strings across multiple tests and functionalities, ensuring proper address management.
    • Fixed error handling in initGenFiles function and SanitizeGenesisBalances, enhancing the robustness of genesis file initialization and balance sanitization.
  • Refactor

    • Simplified address handling by replacing direct address objects with string conversions in tests and core functionalities, promoting code readability and maintainability.
    • Updated function calls and test cases to use string-based address handling, aligning with the new address management strategy.
  • Tests

    • Revised integration and unit tests to accommodate changes in address handling and error management, ensuring comprehensive testing coverage.
  • Documentation

    • Updated CHANGELOG.md to reflect the removal of Address.String() method and related adjustments for a clearer understanding of the changes.
  • Chores

    • Minor adjustments and code clean-ups related to address conversion and error handling to maintain code quality and adherence to best practices.

Copy link
Contributor

coderabbitai bot commented Apr 4, 2024

Walkthrough

Walkthrough

The changes involve significant improvements in address handling across various files, emphasizing the transition from direct address objects to string representations. These enhancements include introducing error handling for address conversions, utilizing AddressCodec for transformations, and updating function signatures to accept string types instead of `sdk.AccAddress. The adjustments aim to standardize address management, enhance error handling practices, and align with recommended approaches for address representation.

Changes

Files Change Summary
simapp/simd/cmd/testnet.go, x/bank/keeper/genesis.go Added error handling for balance sanitization; used AddressCodec for address conversions.
tests/integration/..., x/bank/keeper/..., x/authz/keeper/..., x/bank/types/... Replaced direct address objects with string representations; utilized AddressCodec for conversions.
x/authz/client/cli/tx.go, x/authz/keeper/msg_server_test.go, x/authz/module/abci_test.go, x/authz/msgs_test.go, x/authz/simulation/... Modified function calls to include AddressCodec parameter; updated address handling to use strings.
x/bank/simulation/..., x/bank/client/cli/tx.go, x/bank/keeper/msg_server_test.go Enhanced simulation and message creation logic with address string conversions and error handling.
x/bank/CHANGELOG.md, x/bank/types/send_authorization.go, x/bank/types/send_authorization_test.go Documented changes related to address handling, including removal of Address.String() method and related adjustments.

Possibly related issues

  • EPIC: remove global bech32 #13140: The extensive changes in address handling align closely with the objectives outlined in this issue, focusing on eliminating global bech32 prefix usage, transitioning away from direct bech32 calls, and enhancing address handling practices throughout the codebase.

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.

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.
  • Please see the configuration documentation for more information.
  • 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

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.

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: 35

Review Status

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between edd1c71 and 9fb6831.
Files selected for processing (37)
  • simapp/simd/cmd/testnet.go (1 hunks)
  • tests/integration/bank/app_test.go (9 hunks)
  • tests/integration/bank/bench_test.go (3 hunks)
  • tests/integration/bank/keeper/deterministic_test.go (6 hunks)
  • tests/sims/authz/operations_test.go (2 hunks)
  • types/query/pagination_test.go (19 hunks)
  • x/accounts/defaults/lockup/lockup.go (1 hunks)
  • x/authz/client/cli/tx.go (1 hunks)
  • x/authz/keeper/keeper_test.go (3 hunks)
  • x/authz/keeper/msg_server_test.go (10 hunks)
  • x/authz/migrations/v2/store_test.go (1 hunks)
  • x/authz/module/abci_test.go (1 hunks)
  • x/authz/msgs_test.go (1 hunks)
  • x/authz/simulation/decoder_test.go (1 hunks)
  • x/authz/simulation/genesis.go (1 hunks)
  • x/authz/simulation/operations.go (3 hunks)
  • x/bank/CHANGELOG.md (1 hunks)
  • x/bank/client/cli/tx.go (2 hunks)
  • x/bank/keeper/collections_test.go (1 hunks)
  • x/bank/keeper/genesis.go (2 hunks)
  • x/bank/keeper/genesis_test.go (3 hunks)
  • x/bank/keeper/grpc_query.go (1 hunks)
  • x/bank/keeper/grpc_query_test.go (9 hunks)
  • x/bank/keeper/keeper_test.go (22 hunks)
  • x/bank/keeper/msg_server_test.go (22 hunks)
  • x/bank/simulation/genesis.go (2 hunks)
  • x/bank/simulation/operations.go (6 hunks)
  • x/bank/simulation/proposals.go (1 hunks)
  • x/bank/simulation/proposals_test.go (2 hunks)
  • x/bank/types/balance.go (4 hunks)
  • x/bank/types/balance_test.go (4 hunks)
  • x/bank/types/inputs_outputs.go (2 hunks)
  • x/bank/types/msgs_test.go (4 hunks)
  • x/bank/types/querier.go (2 hunks)
  • x/bank/types/send_authorization.go (3 hunks)
  • x/bank/types/send_authorization_test.go (9 hunks)
  • x/genutil/genaccounts.go (1 hunks)
Additional Context Used
Path-based Instructions (37)
x/bank/simulation/proposals.go (1)

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

x/bank/simulation/proposals_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/authz/simulation/decoder_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/bank/types/inputs_outputs.go (1)

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

x/bank/keeper/genesis.go (1)

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

x/bank/types/querier.go (1)

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

x/authz/simulation/genesis.go (1)

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

x/bank/CHANGELOG.md (1)

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

x/bank/types/send_authorization.go (1)

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

x/bank/types/balance.go (1)

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

x/bank/keeper/collections_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/bank/client/cli/tx.go (1)

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

x/authz/migrations/v2/store_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/authz/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/bank/simulation/genesis.go (1)

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

x/bank/types/send_authorization_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"

tests/integration/bank/bench_test.go (3)

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


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


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

x/genutil/genaccounts.go (1)

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

x/bank/keeper/genesis_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/bank/types/msgs_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/bank/types/balance_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/authz/msgs_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"

tests/sims/authz/operations_test.go (3)

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


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


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

x/authz/client/cli/tx.go (1)

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

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

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

x/bank/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"

x/bank/keeper/grpc_query.go (1)

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

x/authz/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"

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

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

tests/integration/bank/app_test.go (3)

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


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


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

types/query/pagination_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"

tests/integration/bank/keeper/deterministic_test.go (3)

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


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


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

x/authz/keeper/keeper_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/accounts/defaults/lockup/lockup.go (1)

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

simapp/simd/cmd/testnet.go (1)

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

x/bank/keeper/grpc_query_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/bank/keeper/keeper_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"

Learnings (4)
x/bank/types/balance.go (1)
User: testinginprod"
PR: cosmos/cosmos-sdk#18542
File: x/bank/types/balance.go:64-77
Timestamp: 2023-11-22T14:48:50.376Z
Learning: - The `SanitizeGenesisBalances` function in `x/bank/types/balance.go` of the Cosmos SDK should panic when encountering duplicate account addresses in the genesis state.
- A test case is required to verify the behavior of `SanitizeGenesisBalances` when duplicates are present.
x/bank/simulation/genesis.go (1)
User: testinginprod"
PR: cosmos/cosmos-sdk#18542
File: x/bank/types/balance.go:64-77
Timestamp: 2023-11-22T14:48:50.376Z
Learning: - The `SanitizeGenesisBalances` function in `x/bank/types/balance.go` of the Cosmos SDK should panic when encountering duplicate account addresses in the genesis state.
- A test case is required to verify the behavior of `SanitizeGenesisBalances` when duplicates are present.
x/genutil/genaccounts.go (1)
User: testinginprod"
PR: cosmos/cosmos-sdk#18542
File: x/bank/types/balance.go:64-77
Timestamp: 2023-11-22T14:48:50.376Z
Learning: - The `SanitizeGenesisBalances` function in `x/bank/types/balance.go` of the Cosmos SDK should panic when encountering duplicate account addresses in the genesis state.
- A test case is required to verify the behavior of `SanitizeGenesisBalances` when duplicates are present.
x/bank/types/balance_test.go (1)
User: testinginprod"
PR: cosmos/cosmos-sdk#18542
File: x/bank/types/balance.go:64-77
Timestamp: 2023-11-22T14:48:50.376Z
Learning: - The `SanitizeGenesisBalances` function in `x/bank/types/balance.go` of the Cosmos SDK should panic when encountering duplicate account addresses in the genesis state.
- A test case is required to verify the behavior of `SanitizeGenesisBalances` when duplicates are present.
Additional comments not posted (80)
x/bank/simulation/proposals_test.go (1)

18-19: Initialize ac with a more robust approach or ensure that codectestutil.CodecOptions{}.GetAddressCodec() is the best method for obtaining the address codec in this context.

x/authz/simulation/decoder_test.go (1)

30-30: Consider validating the result of codectestutil.CodecOptions{}.GetAddressCodec() before using it to ensure it meets the expected criteria.

x/bank/types/inputs_outputs.go (2)

54-56: Ensure that the address string passed to NewInput is validated or sanitized before use to prevent potential security issues.


79-81: Ensure that the address string passed to NewOutput is validated or sanitized before use to prevent potential security issues.

x/bank/keeper/genesis.go (2)

16-17: Direct assignment of err from k.SetParams is a good practice for error handling. Ensure that all similar instances in the codebase follow this pattern for consistency.


26-29: Properly handling errors from types.SanitizeGenesisBalances is crucial. Ensure that the error messages are clear and informative for easier debugging.

x/bank/types/querier.go (3)

16-17: Ensure that the address string passed to NewQueryBalanceRequest is validated or sanitized before use to prevent potential security issues.


21-22: Ensure that the address string passed to NewQueryAllBalancesRequest is validated or sanitized before use to prevent potential security issues.


27-28: Ensure that the address string passed to NewQuerySpendableBalancesRequest is validated or sanitized before use to prevent potential security issues.

x/authz/simulation/genesis.go (1)

43-45: Passing addressCodec to generateRandomGrant is a good practice for consistency in address handling. Ensure that the codec is used correctly within the function.

x/bank/CHANGELOG.md (1)

38-42: Ensure that the changelog entries are clear and accurately reflect the changes made in the PR. Specifically, verify that all function signature changes and the addition of address codec arguments are correctly documented.

x/bank/types/send_authorization.go (1)

19-21: Consider renaming the addressCodec parameter to more accurately reflect its purpose, such as addrCodec, to maintain consistency with common naming conventions in the Cosmos SDK.

x/bank/types/balance.go (1)

69-78: > 📝 NOTE

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

Ensure that the SanitizeGenesisBalances function properly handles duplicate account addresses by returning an error instead of panicking. This aligns with the best practice of avoiding panic in library code and allows calling code to handle errors gracefully.

- panic(fmt.Sprintf("genesis state has a duplicate account: %q aka %x", balances[i].Address, addr))
+ return nil, fmt.Errorf("genesis state has a duplicate account: %q aka %x", balances[i].Address, addr)
Skipped due to learnings
User: testinginprod"
PR: cosmos/cosmos-sdk#18542
File: x/bank/types/balance.go:64-77
Timestamp: 2023-11-22T14:48:50.376Z
Learning: - The `SanitizeGenesisBalances` function in `x/bank/types/balance.go` of the Cosmos SDK should panic when encountering duplicate account addresses in the genesis state.
- A test case is required to verify the behavior of `SanitizeGenesisBalances` when duplicates are present.
x/bank/client/cli/tx.go (1)

84-89: Verify the necessity of converting arg to bytes and then back to string in the NewMultiSendTxCmd function. If arg is already in the correct format, this conversion might be redundant.

x/authz/migrations/v2/store_test.go (1)

45-45: Ensure that the addressCodec used in the NewSendAuthorization call is properly initialized and represents a realistic scenario for the test. Consider using a mock or a standard codec implementation that reflects the actual usage.

x/authz/module/abci_test.go (1)

57-57: Ensure that the addressCodec used in the NewSendAuthorization call is properly initialized and represents a realistic scenario for the test. Consider using a mock or a standard codec implementation that reflects the actual usage.

x/bank/types/send_authorization_test.go (1)

29-33: Ensure that the addressCodec used in the NewSendAuthorization call is properly initialized and represents a realistic scenario for the test. Consider using a mock or a standard codec implementation that reflects the actual usage.

x/genutil/genaccounts.go (1)

134-136: Properly handle errors from banktypes.SanitizeGenesisBalances by returning the error to the caller.

-	bankGenState.Balances, err = banktypes.SanitizeGenesisBalances(bankGenState.Balances, addressCodec)
-	if err != nil {
-		return fmt.Errorf("failed to sanitize genesis balance: %w", err)
-	}

This change correctly introduces error handling for the sanitization process, ensuring that any issues encountered during this step are not silently ignored.

x/authz/msgs_test.go (1)

72-72: The addition of codectestutil.CodecOptions{}.GetValidatorCodec() as an argument in NewSendAuthorization is consistent with the need for a codec in the authorization setup. This change ensures that the test setup aligns with the updated requirements for authorization creation.

tests/sims/authz/operations_test.go (2)

172-172: Ensure suite.accountKeeper.AddressCodec() is properly initialized and consistently used throughout the test suite for address handling.


203-203: Ensure suite.accountKeeper.AddressCodec() is properly initialized and consistently used throughout the test suite for address handling.

x/authz/client/cli/tx.go (1)

162-162: Ensure clientCtx.AddressCodec is properly initialized and consistently used across CLI commands for address handling.

Verification successful

The review comment is verified. The script output confirms that clientCtx.AddressCodec is properly initialized and consistently used across CLI commands for address handling within x/authz/client/cli/tx.go.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the initialization of AddressCodec in the CLI setup
rg "AddressCodec" x/authz/client/cli/tx.go
# Ensure consistent use of AddressCodec for address handling in CLI commands
rg "AddressCodec" x/authz/client/cli/tx.go

Length of output: 2085

x/authz/simulation/operations.go (2)

125-125: Ensure the generateRandomAuthorization function's new addressCodec parameter is properly documented.
Adding documentation for the addressCodec parameter in the generateRandomAuthorization function will help maintainers and developers understand its purpose and usage.


162-164: Validate the addressCodec parameter in generateRandomAuthorization.
Before using the addressCodec parameter within the generateRandomAuthorization function, ensure it is validated to prevent potential issues if a nil or invalid codec is passed. This is a precautionary measure to enhance the robustness of the code.

x/authz/keeper/msg_server_test.go (1)

399-399: Ensure the NewGrant function's new addressCodec parameter is properly documented.
Adding documentation for the addressCodec parameter in the NewGrant function will help maintainers and developers understand its purpose and usage. This is crucial for ensuring that the refactor's intent and the parameter's role are clear.

tests/integration/bank/app_test.go (4)

195-199: Validate the use of string addresses in MsgMultiSend creation aligns with the updated address handling approach.


211-215: Validate the use of string addresses in MsgMultiSend creation within test cases, ensuring consistency with the new address handling strategy.


223-229: Confirm that the conversion of module account addresses to strings and their use in MsgMultiSend is correctly implemented and aligns with the refactor objectives.


237-241: Ensure that the test case "multiple inputs not allowed" correctly reflects the updated logic and address handling after the refactor.

types/query/pagination_test.go (10)

129-129: Validate the use of string addresses in QueryAllBalancesRequest aligns with the updated address handling approach.


138-138: Confirm that the conversion of addresses to strings and their use in QueryAllBalancesRequest is correctly implemented and aligns with the refactor objectives.


147-147: Ensure that the test case "paginate with custom limit and countTotal true" correctly reflects the updated logic and address handling after the refactor.


156-156: Validate the use of string addresses in QueryAllBalancesRequest within test cases, ensuring consistency with the new address handling strategy.


165-165: Confirm that the conversion of addresses to strings and their use in QueryAllBalancesRequest for pagination with custom limit, key, and countTotal false is correctly implemented.


174-174: Ensure that the test case "paginate for last page" correctly reflects the updated logic and address handling after the refactor.


184-184: Validate the use of string addresses in QueryAllBalancesRequest for pagination with offset and limit aligns with the updated address handling approach.


194-194: Confirm that the conversion of addresses to strings and their use in QueryAllBalancesRequest for pagination with offset and limit is correctly implemented.


203-203: Ensure error handling is consistent and informative when both offset and key are provided in QueryAllBalancesRequest, which is an invalid request scenario.


210-210: Validate the handling of pagination with offset greater than total results in QueryAllBalancesRequest, ensuring it aligns with expectations.

tests/integration/bank/keeper/deterministic_test.go (1)

172-172: Consider caching the addressCodec instance for reuse across tests to improve performance.

x/authz/keeper/keeper_test.go (2)

150-150: The update to include AddressCodec in the SendAuthorization creation aligns well with the PR's objectives of standardizing address handling. Good job on this change.


178-178: Including AddressCodec in the SendAuthorization creation here is consistent with the PR's goal of enhancing address handling. This is a positive step towards standardizing how addresses are managed.

x/accounts/defaults/lockup/lockup.go (1)

463-463: The update to call NewQueryBalanceRequest without the sdk.AccAddress type conversion for the sender parameter simplifies the code and aligns with the PR's goal of standardizing address handling. This is a positive change.

x/bank/keeper/grpc_query_test.go (14)

14-14: Import codectestutil to facilitate address to string conversion in tests.
This import is necessary for the updated test cases that now require address to string conversion using the codectestutil package, aligning with the PR's objective to handle addresses as strings.


24-26: Convert the address to a string using codectestutil for query requests.
This conversion is part of the refactor to handle addresses as strings, ensuring that the test cases are updated to reflect the changes in how addresses are managed within the SDK.


45-45: Use the string representation of the address in the NewQueryBalanceRequest.
This change is consistent with the PR's objective to standardize address handling by using strings instead of direct address objects.


51-51: Pass an empty string as the address in NewQueryBalanceRequest to test error handling for empty address strings.
This test case validates the SDK's error handling when an empty string is passed as an address, aligning with the changes to use string representations of addresses.


63-63: Query balance with a valid address string but missing denom to test error handling.
This test case checks the SDK's behavior when a denom is not provided, ensuring that the error handling works as expected with the new string-based address handling.


69-69: Query balance with a valid address string and denom, expecting an empty result.
This test case ensures that querying with a valid address string and denom works as expected, even when the result is empty, demonstrating the SDK's ability to handle string-based addresses.


77-77: Query balance with a valid address string and denom, expecting a specific result.
This test case confirms that querying with a valid address string and denom returns the correct balance, aligning with the PR's goal to standardize address handling as strings.


110-112: Convert the address to a string using codectestutil for querying all balances.
This conversion is necessary for the test case that queries all balances using the string representation of the address, reflecting the PR's changes to address handling.


118-118: Query all balances with a valid address string and pagination request.
This change updates the test case to use a string representation of the address, ensuring it aligns with the SDK's new approach to address handling.


147-147: Query the second page of all balances using a valid address string and updated pagination request.
This test case demonstrates the SDK's ability to handle paginated queries for all balances using string-based addresses, in line with the PR's objectives.


161-161: Query the third page of all balances with a valid address string, testing the SDK's pagination handling with string-based addresses.
This test case further validates the SDK's support for paginated queries using string representations of addresses, consistent with the PR's changes.


173-173: Query the third page of all balances with address string and resolve IBC denom, testing the SDK's handling of IBC denoms with string-based addresses.
This test case checks the SDK's ability to resolve IBC denoms in paginated queries using string representations of addresses, aligning with the PR's goals.


183-184: Convert the address to a string using codectestutil for querying spendable balances.
This conversion is part of the update to handle addresses as strings in test cases, ensuring consistency with the PR's changes to address management.


198-198: Query spendable balances with a valid address string and pagination request.
This test case updates the query for spendable balances to use a string representation of the address, reflecting the SDK's new approach to address handling.

x/bank/keeper/keeper_test.go (23)

137-142: Ensure the address codec is properly initialized and used for address conversions.


153-154: Verify that the map initialization with addr: true is correctly used and serves the intended purpose within the test setup.

Verification successful

The map initialization with addr: true is used in the construction of a NewBaseKeeper object in both collections_test.go and keeper_test.go, suggesting it serves a specific purpose related to the test setup, likely concerning permissions or access control. The consistent use across different test files and the context provided by the surrounding code indicate that the initialization is correctly used and serves the intended purpose within the test setup.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check for usage of the initialized map in tests to ensure it's utilized as intended.
grep -R "map\[string]bool{addr: true}" .

Length of output: 171



Script:

#!/bin/bash
# Examine the usage context of the map initialization in collections_test.go and keeper_test.go
grep -C 5 "map\[string]bool{addr: true}" ./x/bank/keeper/collections_test.go
grep -C 5 "map\[string]bool{addr: true}" ./x/bank/keeper/keeper_test.go

Length of output: 597


319-322: Ensure error handling is properly implemented for address conversion failures in TestGetAuthority.


326-327: Confirm that the test cases in TestGetAuthority accurately reflect the intended functionality and cover all necessary scenarios.


643-647: In TestInputOutputNewAccount, ensure that address conversion is correctly handled and that errors are properly managed.


650-653: Check that the Input and Output structs are correctly populated with string addresses and that the test logic aligns with the expected behavior.


670-676: In TestInputOutputCoins, verify that address conversion is correctly handled and that errors are properly managed.


678-682: Ensure that the Input and Output structs in TestInputOutputCoins are correctly populated and that the test accurately reflects the intended functionality.


782-791: In TestInputOutputCoinsWithRestrictions, ensure that address conversion is correctly handled and that errors are properly managed.


810-810: Verify that the Output struct is correctly populated with string addresses in TestInputOutputCoinsWithRestrictions.


822-822: Ensure that the Output struct is correctly populated with string addresses in the passthrough restriction test case.


842-842: Check that the Output struct is correctly populated with string addresses in the new to restriction test case.


862-862: In the error restriction test case, ensure that the Output struct is correctly populated with string addresses.


884-885: Verify that the Output structs are correctly populated with string addresses in the passthrough restriction two outputs test case.


913-914: Check that the Output structs are correctly populated with string addresses in the error restriction two outputs test case.


943-944: Ensure that the Output structs are correctly populated with string addresses in the new to restriction two outputs test case.


1364-1368: In TestMsgSendEvents, verify that address conversion is correctly handled and that errors are properly managed.


1381-1385: Check that the event attributes are correctly populated with string addresses in TestMsgSendEvents.


1406-1412: In TestMsgMultiSendEvents, ensure that address conversion is correctly handled and that errors are properly managed.


1459-1465: > 📝 NOTE

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

Verify that the event attributes in TestMsgMultiSendEvents are correctly populated with string addresses.


1896-1899: In TestBalanceTrackingEvents, ensure that address conversion is correctly handled when processing events.


1904-1906: Check that address conversion is correctly handled in TestBalanceTrackingEvents when processing received coin events.


1922-1925: Ensure that address conversion is correctly handled in TestBalanceTrackingEvents when iterating account balances.

Comment on lines +153 to +155
addrStr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr)
assert.NilError(t, err)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper error handling for the address-to-string conversion.

- assert.NilError(t, err)
+ if err != nil {
+     t.Fatalf("Failed to convert address to string: %v", err)
+ }

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
addrStr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr)
assert.NilError(t, err)
addrStr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr)
if err != nil {
t.Fatalf("Failed to convert address to string: %v", err)
}

Comment on lines +161 to +163
addr1Str, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr1)
assert.NilError(t, err)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper error handling for the address-to-string conversion.

- assert.NilError(t, err)
+ if err != nil {
+     t.Fatalf("Failed to convert address to string: %v", err)
+ }

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
addr1Str, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr1)
assert.NilError(t, err)
addr1Str, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr1)
if err != nil {
t.Fatalf("Failed to convert address to string: %v", err)
}

Comment on lines +179 to +181
addrStr, err := addressCodec.BytesToString(addr)
assert.NilError(t, err)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper error handling for the address-to-string conversion.

- assert.NilError(t, err)
+ if err != nil {
+     t.Fatalf("Failed to convert address to string: %v", err)
+ }

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
addrStr, err := addressCodec.BytesToString(addr)
assert.NilError(t, err)
addrStr, err := addressCodec.BytesToString(addr)
if err != nil {
t.Fatalf("Failed to convert address to string: %v", err)
}

Comment on lines +201 to +203
addr1Str, err := addressCodec.BytesToString(addr1)
assert.NilError(t, err)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper error handling for the address-to-string conversion.

- assert.NilError(t, err)
+ if err != nil {
+     t.Fatalf("Failed to convert address to string: %v", err)
+ }

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
addr1Str, err := addressCodec.BytesToString(addr1)
assert.NilError(t, err)
addr1Str, err := addressCodec.BytesToString(addr1)
if err != nil {
t.Fatalf("Failed to convert address to string: %v", err)
}

Comment on lines +215 to +216
addrStr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr)
assert.NilError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper error handling for the address-to-string conversion.

- assert.NilError(t, err)
+ if err != nil {
+     t.Fatalf("Failed to convert address to string: %v", err)
+ }

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
addrStr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr)
assert.NilError(t, err)
addrStr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr)
if err != nil {
t.Fatalf("Failed to convert address to string: %v", err)
}

Comment on lines +118 to +123
ac := testutil.CodecOptions{}.GetAddressCodec()
addr1, err := ac.BytesToString([]byte("input"))
require.NoError(t, err)
addr2, err := ac.BytesToString([]byte("output"))
require.NoError(t, err)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure error handling is consistent by checking for errors immediately after function calls that can fail.

-	addr2, err := ac.BytesToString([]byte("output"))
+	addr2, err := ac.BytesToString([]byte("output"))
+	require.NoError(t, err)

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
ac := testutil.CodecOptions{}.GetAddressCodec()
addr1, err := ac.BytesToString([]byte("input"))
require.NoError(t, err)
addr2, err := ac.BytesToString([]byte("output"))
require.NoError(t, err)
ac := testutil.CodecOptions{}.GetAddressCodec()
addr1, err := ac.BytesToString([]byte("input"))
require.NoError(t, err)
addr2, err := ac.BytesToString([]byte("output"))
require.NoError(t, err)
require.NoError(t, err)

Comment on lines +154 to +155
addrStr, err := ac.BytesToString(addr)
require.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure error handling is consistent by checking for errors immediately after function calls that can fail.

-	addrStr, err := ac.BytesToString(addr)
+	addrStr, err := ac.BytesToString(addr)
+	require.NoError(t, err)

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
addrStr, err := ac.BytesToString(addr)
require.NoError(t, err)
addrStr, err := ac.BytesToString(addr)
require.NoError(t, err)

Comment on lines +190 to +191
addrStr, err := ac.BytesToString(addr)
require.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure error handling is consistent by checking for errors immediately after function calls that can fail.

-	addrStr, err := ac.BytesToString(addr)
+	addrStr, err := ac.BytesToString(addr)
+	require.NoError(t, err)

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
addrStr, err := ac.BytesToString(addr)
require.NoError(t, err)
addrStr, err := ac.BytesToString(addr)
require.NoError(t, err)

Comment on lines +209 to +210
addrStr, err := ac.BytesToString(addr)
require.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure error handling is consistent by checking for errors immediately after function calls that can fail.

-	addrStr, err := ac.BytesToString(addr)
+	addrStr, err := ac.BytesToString(addr)
+	require.NoError(t, err)

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
addrStr, err := ac.BytesToString(addr)
require.NoError(t, err)
addrStr, err := ac.BytesToString(addr)
require.NoError(t, err)

Comment on lines +257 to +258
addrStr, err := ac.BytesToString(addr)
require.NoError(b, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure error handling is consistent by checking for errors immediately after function calls that can fail.

-	addrStr, err := ac.BytesToString(addr)
+	addrStr, err := ac.BytesToString(addr)
+	require.NoError(b, err)

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
addrStr, err := ac.BytesToString(addr)
require.NoError(b, err)
addrStr, err := ac.BytesToString(addr)
require.NoError(b, err)

x/bank/CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Marko <marko@baricevic.me>
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: 1

Review Status

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 9fb6831 and d56da32.
Files selected for processing (1)
  • x/bank/CHANGELOG.md (1 hunks)
Additional Context Used
Path-based Instructions (1)
x/bank/CHANGELOG.md (1)

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

Comment on lines +38 to +42
* [#19954](https://github.com/cosmos/cosmos-sdk/pull/19954) Removal of the Address.String() method and related changes:
* Changed `NewInput`, `NewOutput`, `NewQueryBalanceRequest`, `NewQueryAllBalancesRequest`, `NewQuerySpendableBalancesRequest` to accept a string instead of an `AccAddress`.
* Added an address codec as an argument to `NewSendAuthorization`.
* Added an address codec as an argument to `SanitizeGenesisBalances` which also returns an error.
* (simulation) `RandomGenesisBalances` also returns an error.
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding more descriptive details about the impact of these changes for better clarity.

* [#19954](https://github.com/cosmos/cosmos-sdk/pull/19954) Removal of the Address.String() method and related changes:
+    * This change impacts various functions and methods across the SDK, requiring updates to how addresses are handled and converted. Specifically:
    * Changed `NewInput`, `NewOutput`, `NewQueryBalanceRequest`, `NewQueryAllBalancesRequest`, `NewQuerySpendableBalancesRequest` to accept a string instead of an `AccAddress`.
    * Added an address codec as an argument to `NewSendAuthorization`.
    * Added an address codec as an argument to `SanitizeGenesisBalances` which also returns an error.
    * (simulation) `RandomGenesisBalances` also returns an error.

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
* [#19954](https://github.com/cosmos/cosmos-sdk/pull/19954) Removal of the Address.String() method and related changes:
* Changed `NewInput`, `NewOutput`, `NewQueryBalanceRequest`, `NewQueryAllBalancesRequest`, `NewQuerySpendableBalancesRequest` to accept a string instead of an `AccAddress`.
* Added an address codec as an argument to `NewSendAuthorization`.
* Added an address codec as an argument to `SanitizeGenesisBalances` which also returns an error.
* (simulation) `RandomGenesisBalances` also returns an error.
* [#19954](https://github.com/cosmos/cosmos-sdk/pull/19954) Removal of the Address.String() method and related changes:
* This change impacts various functions and methods across the SDK, requiring updates to how addresses are handled and converted. Specifically:
* Changed `NewInput`, `NewOutput`, `NewQueryBalanceRequest`, `NewQueryAllBalancesRequest`, `NewQuerySpendableBalancesRequest` to accept a string instead of an `AccAddress`.
* Added an address codec as an argument to `NewSendAuthorization`.
* Added an address codec as an argument to `SanitizeGenesisBalances` which also returns an error.
* (simulation) `RandomGenesisBalances` also returns an error.

@@ -83,9 +87,14 @@ func RandomizedGenState(simState *module.SimulationState) {
totalSupply := simState.InitialStake.Mul(sdkmath.NewInt((numAccs + simState.NumBonded)))
supply := sdk.NewCoins(sdk.NewCoin(simState.BondDenom, totalSupply))

balancer, err := RandomGenesisBalances(simState)
Copy link
Member

Choose a reason for hiding this comment

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

nit: balancer should be balances?

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 Status

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between d56da32 and 2ed8a63.
Files selected for processing (1)
  • x/bank/simulation/genesis.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/bank/simulation/genesis.go

@tac0turtle tac0turtle added this pull request to the merge queue Apr 5, 2024
Merged via the queue into main with commit c753458 Apr 5, 2024
61 of 64 checks passed
@tac0turtle tac0turtle deleted the julian/bank-accString-removal branch April 5, 2024 13:13
alpe added a commit to alpe/cosmos-sdk that referenced this pull request Apr 8, 2024
* main: (45 commits)
  build(deps): Bump github.com/decred/dcrd/dcrec/secp256k1/v4 from 4.2.0 to 4.3.0 (cosmos#19913)
  build(deps): Bump google.golang.org/grpc from 1.62.1 to 1.63.0 (cosmos#19929)
  test(types/address): add additional unit tests for address.LengthPrefix and a… (cosmos#19964)
  refactor(x/bank)!: remove Address.String() (cosmos#19954)
  build(deps): Bump github.com/prometheus/common from 0.51.1 to 0.52.2 (cosmos#19930)
  fix(x/epochs): Fix init genesis (cosmos#19958)
  feat(core,runtime): transaction service (exec mode) (cosmos#19953)
  fix(x/authz): non utf-8 characters in logs (cosmos#19923)
  build(deps): Bump golang.org/x/crypto from 0.21.0 to 0.22.0 (cosmos#19960)
  chore: fix spelling errors (cosmos#19957)
  fix(x/tx): don't shadow Amino marshalling error messages (cosmos#19955)
  refactor(types): loosen module.AppModule interface (cosmos#19951)
  feat(core): add `TxValidator` interface (cosmos#19950)
  build(deps): Bump cosmossdk.io/store from 1.0.2 to 1.1.0 in /x/epochs (cosmos#19947)
  feat(x/epochs): upstream osmosis epoch module (cosmos#19697)
  build(deps): Bump bufbuild/buf-setup-action from 1.30.0 to 1.30.1 (cosmos#19928)
  refactor(x/genutil)!: remove Address.String() (cosmos#19926)
  docs(x/mint): Fix inconsistency in mint docs  (cosmos#19915)
  build(deps): Bump github.com/regen-network/gocuke from 1.1.0 to 1.1.1 in /orm (cosmos#19920)
  feat: Integrate grpc configuration into client.toml (cosmos#19905)
  ...
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.

None yet

3 participants