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

test: add panic cases in tests for UpgradeOpen #5550

Merged
merged 29 commits into from
Apr 19, 2024

Conversation

neitdung
Copy link
Contributor

@neitdung neitdung commented Jan 8, 2024

Description

  • Add panic test cases for OnChanUpgradeOpen and OnChanUpgradeRestore
  • Reuse mock middleware as the app which doesn't implement the UpgradeableModule interface from #5406

closes: #5471

Commit Message / Changelog Entry

test: add panic cases in tests when channel upgrade open or restore 

see the guidelines for commit messages. (view raw markdown for examples)


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/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

Summary by CodeRabbit

  • Tests
    • Enhanced testing for channel upgrades in interchain accounts, including new scenarios for error handling.
    • Added import for cosmossdk.io/errors.
    • Added expPanic field to test cases in TestOnChanUpgradeOpen function.
    • Updated the logic in TestOnChanUpgradeOpen to handle expected errors and panics based on test cases.

@codecov-commenter
Copy link

codecov-commenter commented Jan 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (dbc11b5) 81.61% compared to head (f9b4306) 81.64%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5550      +/-   ##
==========================================
+ Coverage   81.61%   81.64%   +0.02%     
==========================================
  Files         199      199              
  Lines       15146    15146              
==========================================
+ Hits        12362    12366       +4     
+ Misses       2319     2317       -2     
+ Partials      465      463       -2     

see 1 file with indirect coverage changes

@DimitrisJim
Copy link
Contributor

thanks! base branched targeted should now be main and not 04-channel-upgrades. Do you want to switch the branch over to that one? If you want, we could also help out with that (might get messy when the switch is done)

@neitdung neitdung changed the base branch from 04-channel-upgrades to main January 9, 2024 10:11
@neitdung neitdung requested a review from srdtrk as a code owner January 9, 2024 10:11
@neitdung
Copy link
Contributor Author

neitdung commented Jan 9, 2024

Thank you @DimitrisJim. I think creating new branch from main and making the same changes at ibc_middleware_test.go file is easier for us to do and review.

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.

thanks! left some initial comments, overall looking good!

@DimitrisJim DimitrisJim added the channel-upgradability Channel upgradability feature label Jan 15, 2024
@crodriguezvega crodriguezvega changed the title test: add panic cases in tests for UpgradeOpen/UpgradeRestore test: add panic cases in tests for UpgradeOpen Jan 24, 2024
Copy link
Contributor

coderabbitai bot commented Apr 14, 2024

Walkthrough

The recent update focuses on enhancing the test coverage for the UpgradeOpen/UpgradeRestore functions in the IBC middleware by introducing scenarios that trigger panics. This is achieved by adding new test cases and modifying existing ones to handle expected errors and panics, ensuring the robustness of the application during protocol upgrades.

Changes

File Path Change Summary
.../27-interchain-accounts/controller/ibc_middleware_test.go Added import, expPanic field, new test cases for error scenarios, updated logic for error handling

Assessment against linked issues

Objective Addressed Explanation
Exercise panic cases in tests for UpgradeOpen/UpgradeRestore (#5471)
Implement mock middleware to trigger panics for unimplemented interfaces (#5471) The summary does not confirm the use of mock middleware as described in the issue.

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.

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

Comment on lines 1027 to 1036
"failure: upgrade route not found",
func() {},
errorsmod.Wrap(porttypes.ErrInvalidRoute, "upgrade route not found to module in application callstack"),
},
{
"failure: connection not found",
func() {
path.EndpointA.ChannelID = "invalid-channel"
},
errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", TestPortID, "invalid-channel"),
Copy link
Contributor

Choose a reason for hiding this comment

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

The test case "failure: connection not found" uses hardcoded values in the error message. Consider using dynamic values from the test setup to ensure the error message is accurate and maintainable if test parameters change.

- errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", TestPortID, "invalid-channel"),
+ errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID),

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
"failure: upgrade route not found",
func() {},
errorsmod.Wrap(porttypes.ErrInvalidRoute, "upgrade route not found to module in application callstack"),
},
{
"failure: connection not found",
func() {
path.EndpointA.ChannelID = "invalid-channel"
},
errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", TestPortID, "invalid-channel"),
"failure: upgrade route not found",
func() {},
errorsmod.Wrap(porttypes.ErrInvalidRoute, "upgrade route not found to module in application callstack"),
},
{
"failure: connection not found",
func() {
path.EndpointA.ChannelID = "invalid-channel"
},
errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID),

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.

sorry for the delay! This LGTM, thanks for working on it!

@mergify mergify bot merged commit 247068b into cosmos:main Apr 19, 2024
75 of 76 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge channel-upgradability Channel upgradability feature
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Excercise panic cases in tests for UpgradeOpen/UpgradeRestore
5 participants