Skip to content

refactor(x/accounts): Skip Importing Unregistered Genesis Account Types#20022

Closed
meetrick wants to merge 12 commits into
cosmos:mainfrom
meetrick:20240412
Closed

refactor(x/accounts): Skip Importing Unregistered Genesis Account Types#20022
meetrick wants to merge 12 commits into
cosmos:mainfrom
meetrick:20240412

Conversation

@meetrick

@meetrick meetrick commented Apr 12, 2024

Copy link
Copy Markdown
Contributor

Description

Skip Importing Unregistered Genesis Account Types in x/accounts/genesis.go

Replace: #19924


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

  • Bug Fixes

    • Enhanced account import validation to ensure only registered account types are imported, improving error handling by returning an error instead of just logging a warning for unrecognized account types.
  • Tests

    • Implemented a new test to verify the improved error handling during account imports when encountering unregistered account types.

Signed-off-by: Hwangjae Lee <meetrick@gmail.com>
@meetrick meetrick requested a review from a team April 12, 2024 07:44
@coderabbitai

coderabbitai Bot commented Apr 12, 2024

Copy link
Copy Markdown
Contributor
Walkthrough

Walkthrough

The update in the x/accounts module enhances the state import process by ensuring that only registered account types are imported. Previously, unregistered account types were simply logged and skipped; now, an error is generated if an unregistered account type is encountered. This change is supported by a new unit test that verifies the correct error handling when attempting to import an unregistered account type.

Changes

File Change Summary
x/accounts/genesis.go Added a check in the ImportState method to ensure only registered account types are imported, triggering an error for unregistered types.
x/accounts/genesis_test.go Introduced TestImportAccountError to validate error handling for importing an unregistered account type.

Recent Review Details

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 2c943e0 and 4a724f1.
Files selected for processing (1)
  • x/accounts/genesis_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/accounts/genesis_test.go

Warning

Following problems were encountered

  • Git: Failed to clone repository. Please contact CodeRabbit support.

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/schema.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.

Signed-off-by: Hwangjae Lee <meetrick@gmail.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Comment thread x/accounts/genesis.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Comment thread x/accounts/CHANGELOG.md Outdated
Comment thread x/accounts/CHANGELOG.md Outdated
@meetrick

Copy link
Copy Markdown
Contributor Author

@julienrbrt Could you review this PR?

Signed-off-by: Hwangjae Lee <meetrick@gmail.com>
Comment thread x/accounts/CHANGELOG.md
Comment thread x/accounts/genesis.go Outdated

@julienrbrt julienrbrt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm! pending a test case.

Comment thread x/accounts/genesis.go
@@ -80,7 +80,13 @@ func (k Keeper) ImportState(ctx context.Context, genState *v1.GenesisState) erro
}

func (k Keeper) importAccount(ctx context.Context, acc *v1.GenesisAccount) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we add a test case for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think we can add the following test case code to genesis_test.go, and we need to think about it more.

func TestImportAccountError(t *testing.T) {
	// Initialize the keeper and context for testing
	k, ctx := newKeeper(t, func(deps implementation.Dependencies) (string, implementation.Account, error) {
		acc, err := NewTestAccount(deps)
		return "test", acc, err
	})

	// Set up a mock query router
	k.queryRouter = mockQuery(func(ctx context.Context, req, resp implementation.ProtoMsg) error { return nil })

	// Define a mock GenesisAccount with a non-existent account type
	acc := &v1.GenesisAccount{
		Address:       "test-address",
		AccountType:   "non-existent-type",
		AccountNumber: 1,
		State:         nil,
	}

	// Attempt to import the mock GenesisAccount into the state
	err := k.importAccount(ctx, acc)

	// Assert that an error is returned
	require.Error(t, err)

	// Assert that the error message contains the expected substring
	require.Contains(t, err.Error(), "account type non-existent-type not found in the registered accounts")
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I updated test case

@meetrick

meetrick commented Apr 16, 2024

Copy link
Copy Markdown
Contributor Author

@julienrbrt The test failure occurs due to the PR below. I need to modify the source code

base ❯ go test -run TestImportAccountError
# cosmossdk.io/x/accounts [cosmossdk.io/x/accounts.test]
./genesis_test.go:61:4: k.queryRouter undefined (type Keeper has no field or method queryRouter)
./genesis_test.go:61:18: undefined: mockQuery
./genesis_test.go:61:37: undefined: context
FAIL	cosmossdk.io/x/accounts [build failed]

Signed-off-by: Hwangjae Lee <meetrick@gmail.com>
@meetrick

Copy link
Copy Markdown
Contributor Author

@julienrbrt The source code seems fine, but I'm experiencing failures in the test cases. Can you advise me? Should I create a new PR?

@julienrbrt

Copy link
Copy Markdown
Contributor

FYI, you don't need to create each time a new PR. It gets very hard to review as context is missing in each new PR you make.

@meetrick meetrick deleted the 20240412 branch September 26, 2024 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants