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

chore: Address linter findings in testing/ #6150

Merged
merged 6 commits into from
Apr 15, 2024
Merged

Conversation

bznein
Copy link
Contributor

@bznein bznein commented Apr 12, 2024

Description

Addresses all linting issues that would be found intesting/ by upgrading golanci-lint version (see linked issue)

ref: #6086


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to GitHub issue with discussion and accepted design, OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced error handling and type assertion checks in client creation and updating processes.
    • Updated import paths and module initialization to ensure compatibility and correct type handling.
    • Made modifications to handle type assertions and error checking in chain.go and endpoint.go.
  • Refactor

    • Removed specific version references in module imports to streamline and future-proof codebase.
    • Introducing additional error handling using require.True and checking for type assertions using ok variables.
    • Changes in the initialization of app.ICAAuthModule to handle type conversion.

Copy link
Contributor

coderabbitai bot commented Apr 12, 2024

Walkthrough

The changes encompass improving error handling, enhancing type assertion checks, and adjusting import paths and initialization processes across various testing files to bolster the resilience and adaptability of the testing framework.

Changes

Files Change Summary
testing/chain.go, testing/endpoint.go Introduced error handling and type assertion checks in functions related to client operations and chain upgrades.
testing/simapp/app.go Updated import paths and adjusted app.ICAAuthModule initialization for type conversion.
testing/simapp/upgrades/upgrades.go Removed version reference in import path for the migration module, indicating restructuring of the module.

Possibly related issues


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.

transfer "github.com/cosmos/ibc-go/v8/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
"github.com/cosmos/ibc-go/v8/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper" //nolint
Copy link
Contributor Author

@bznein bznein Apr 12, 2024

Choose a reason for hiding this comment

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

This is an interesting one that left me stumped!

If I remove the type alias, goimports will remove the import saying it is unused (?!) and it won't build)
If I replace it with _, the code will not build because ibctransferkeeper is not found
If I don't do anything, the linter will complain ¯\_(ツ)_/¯

So I would be very happy if anyone would like to help me understand what is going on :)

Copy link
Contributor

Choose a reason for hiding this comment

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

hm, with these imports it works fine locally:

	"github.com/cosmos/ibc-go/v8/modules/apps/transfer"
	ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"

you mean goimports would straight up remove the first import if this is the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, this is weird. I tried to repro the issue (which happened at line 121) but... it's not happening anymore. No idea what was happening, but thank you!

Copy link
Contributor

Choose a reason for hiding this comment

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

the code gods works in mysterious ways 🕯️

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

@@ -15,7 +15,7 @@ import (
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"

capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
v6 "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/migrations/v6"
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/migrations/v6"
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The verification process has revealed that the old import path github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/migrations/v6 is still being used in two files: testing/simapp/upgrades/upgrades.go and modules/apps/27-interchain-accounts/controller/migrations/v6/migrations_test.go. This indicates that the import path update has not been fully propagated throughout the codebase, which could lead to inconsistencies or import errors.

Given this finding, it is recommended to update all references to the old import path across the entire codebase to ensure consistency and prevent potential issues related to outdated imports.

Analysis chain

The import path for the migration module related to interchain accounts has been updated to remove the specific version reference v6. This change likely aims to simplify the import structure or prepare for future upgrades. Ensure that this change is reflected across all files that might use this module to avoid import errors.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for any files that might still be using the old import path.
rg --type go 'github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/migrations/v6'

Length of output: 403

Comment on lines +98 to +99
height, ok := endpoint.Counterparty.Chain.LatestCommittedHeader.GetHeight().(clienttypes.Height)
require.True(endpoint.Chain.TB, ok)
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 type assertion failures.

- require.True(endpoint.Chain.TB, ok)
+ require.True(endpoint.Chain.TB, ok, "failed to assert type as clienttypes.Height")

Adding a descriptive error message will help in debugging if the type assertion fails.


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
height, ok := endpoint.Counterparty.Chain.LatestCommittedHeader.GetHeight().(clienttypes.Height)
require.True(endpoint.Chain.TB, ok)
height, ok := endpoint.Counterparty.Chain.LatestCommittedHeader.GetHeight().(clienttypes.Height)
require.True(endpoint.Chain.TB, ok, "failed to assert type as clienttypes.Height")

Comment on lines +142 to +143
trustedHeight, ok := endpoint.GetClientLatestHeight().(clienttypes.Height)
require.True(endpoint.Chain.TB, ok)
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 type assertion failures.

- require.True(endpoint.Chain.TB, ok)
+ require.True(endpoint.Chain.TB, ok, "failed to assert type as clienttypes.Height")

Adding a descriptive error message will help in debugging if the type assertion fails.


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
trustedHeight, ok := endpoint.GetClientLatestHeight().(clienttypes.Height)
require.True(endpoint.Chain.TB, ok)
trustedHeight, ok := endpoint.GetClientLatestHeight().(clienttypes.Height)
require.True(endpoint.Chain.TB, ok, "failed to assert type as clienttypes.Height")

Comment on lines +173 to +174
tmClientState, ok := clientState.(*ibctm.ClientState)
require.True(endpoint.Chain.TB, ok)
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 type assertion failures.

- require.True(endpoint.Chain.TB, ok)
+ require.True(endpoint.Chain.TB, ok, "failed to assert type as *ibctm.ClientState")

Adding a descriptive error message will help in debugging if the type assertion fails.


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
tmClientState, ok := clientState.(*ibctm.ClientState)
require.True(endpoint.Chain.TB, ok)
tmClientState, ok := clientState.(*ibctm.ClientState)
require.True(endpoint.Chain.TB, ok, "failed to assert type as *ibctm.ClientState")

Comment on lines +526 to +530
var ok bool
app.ICAAuthModule, ok = icaControllerStack.(ibcmock.IBCModule)
if !ok {
panic(fmt.Errorf("cannot convert %T into %T", icaControllerStack, app.ICAAuthModule))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Type assertion for app.ICAAuthModule is correctly implemented with appropriate error handling. Consider adding a unit test to ensure that the type assertion does not fail during normal operations.

Would you like me to help with writing the unit test for this type assertion?

Comment on lines +312 to +314
var ok bool
consensusHeight, ok = endpoint.Counterparty.GetClientLatestHeight().(clienttypes.Height)
require.True(endpoint.Chain.TB, ok)
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 type assertion failures.

- require.True(endpoint.Chain.TB, ok)
+ require.True(endpoint.Chain.TB, ok, "failed to assert type as clienttypes.Height")

Adding a descriptive error message will help in debugging if the type assertion fails.


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
var ok bool
consensusHeight, ok = endpoint.Counterparty.GetClientLatestHeight().(clienttypes.Height)
require.True(endpoint.Chain.TB, ok)
var ok bool
consensusHeight, ok = endpoint.Counterparty.GetClientLatestHeight().(clienttypes.Height)
require.True(endpoint.Chain.TB, ok, "failed to assert type as clienttypes.Height")

Copy link
Contributor

@DimitrisJim DimitrisJim left a comment

Choose a reason for hiding this comment

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

finally getting there, thanks! 🙏

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

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

Thank you for fixing all these linter errors. This has really been your ibc-go baptism of fire! 🔥

@crodriguezvega crodriguezvega merged commit ca33574 into cosmos:main Apr 15, 2024
74 of 75 checks passed
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