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: move 07-tendermint client state testing to use light client module entry points #6074

Conversation

charleenfei
Copy link
Contributor

@charleenfei charleenfei commented Apr 2, 2024

Description

partially closes: #6001

addresses the 07-tendermint client state testing functions, uses expErr instead of expPass.


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

    • Improved error handling in ClientState validation and delay period verification.
  • New Features

    • Added a new error code for invalid trust levels in light client operations.
  • Refactor

    • Enhanced test suite for light clients with new test functions and scenarios, focusing on client status, timestamp retrieval, and membership verification.
  • Tests

    • Introduced comprehensive tests for various functionalities including client initialization and membership verification.
  • Documentation

    • Updated error messages for better clarity and context.

Copy link
Contributor

coderabbitai bot commented Apr 2, 2024

Walkthrough

The changes involve enhancing error handling, refining test structures, and introducing a new error for invalid trust levels across several files in the Tendermint light client module. The modifications focus on improving validation methods, error messaging, and test coverage for client state and light client functionalities. This includes restructuring test cases, updating error handling mechanisms, and adding new test functions to ensure comprehensive validation and verification processes.

Changes

File(s) Change Summary
client_state.go, light_client_module.go Enhanced error handling with more context and descriptive messages.
client_state_test.go, light_client_module_test.go Significant test refactoring, including new test functions and test case reorganization.
errors.go Addition of ErrInvalidTrustLevel error.
tendermint_test.go New variable declaration for upgrade paths testing.

Assessment against linked issues

Objective Addressed Explanation
Refactor tests to use light client module entry points (#6001)
Use expError error pattern in tests instead of expPass bool (#6001)
Migrate unit tests for increased code coverage (#6001)
Enhance error handling and validation logic in tests (#6001)

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.

@charleenfei charleenfei changed the title test: move Tendermint client state testing to use light client module entry points test: move 07-tendermint client state testing to use light client module entry points Apr 2, 2024
@@ -123,7 +123,7 @@ func (cs ClientState) Validate() error {
}

if err := light.ValidateTrustLevel(cs.TrustLevel.ToTendermint()); err != nil {
return err
return errorsmod.Wrapf(ErrInvalidTrustLevel, "%s", err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added this error wrapping for debugging ux

Copy link
Contributor

Choose a reason for hiding this comment

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

Just a nit, but I think in other places we do something just like...

Suggested change
return errorsmod.Wrapf(ErrInvalidTrustLevel, "%s", err)
return errorsmod.Wrap(ErrInvalidTrustLevel, err.Error())

@@ -50,7 +52,8 @@ func (l LightClientModule) Initialize(ctx sdk.Context, clientID string, clientSt

var consensusState ConsensusState
if err := l.keeper.Codec().Unmarshal(consensusStateBz, &consensusState); err != nil {
return err
return fmt.Errorf("failed to unmarshal consensus state bytes into consensus state: %w", err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same here

charleenfei and others added 5 commits April 2, 2024 11:51
…ient-module-entry-points' of github.com:cosmos/ibc-go into charly/issue#6001-move-client-state-testing-to-light-client-module-entry-points
@charleenfei charleenfei marked this pull request as ready for review April 2, 2024 11:43
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 527ce1d and ac8271d.
Files selected for processing (6)
  • modules/light-clients/07-tendermint/client_state.go (2 hunks)
  • modules/light-clients/07-tendermint/client_state_test.go (2 hunks)
  • modules/light-clients/07-tendermint/errors.go (1 hunks)
  • modules/light-clients/07-tendermint/light_client_module.go (3 hunks)
  • modules/light-clients/07-tendermint/light_client_module_test.go (2 hunks)
  • modules/light-clients/07-tendermint/tendermint_test.go (1 hunks)
Additional Context Used
Path-based Instructions (6)
modules/light-clients/07-tendermint/errors.go (1)

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

modules/light-clients/07-tendermint/tendermint_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"

modules/light-clients/07-tendermint/client_state_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"

modules/light-clients/07-tendermint/light_client_module.go (1)

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

modules/light-clients/07-tendermint/client_state.go (1)

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

modules/light-clients/07-tendermint/light_client_module_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"

Additional comments not posted (11)
modules/light-clients/07-tendermint/errors.go (1)

22-22: The addition of ErrInvalidTrustLevel with code 15 is clear and follows the pattern established in the file for defining errors. This should enhance error handling by providing a more specific error for invalid trust levels.

modules/light-clients/07-tendermint/tendermint_test.go (1)

35-35: The addition of invalidUpgradePath with the specific value []string{"upgrade", ""} is a good enhancement to the test suite, allowing for testing scenarios with invalid upgrade paths.

modules/light-clients/07-tendermint/client_state_test.go (1)

23-120: The refactoring of test cases in TestValidate to use the expErr error pattern instead of expPass bool is a positive change, enhancing the clarity and robustness of error handling in tests. Each test case is well-structured, covering a wide range of validation scenarios for the ClientState.

modules/light-clients/07-tendermint/light_client_module.go (2)

4-5: The import of the fmt package is correctly placed and is necessary for the subsequent use of fmt.Errorf for error wrapping.


46-46: Enhancing error messages in the Initialize function using fmt.Errorf to wrap errors with additional context is a good practice. It improves the debugging experience by providing more descriptive error messages.

Also applies to: 55-55

modules/light-clients/07-tendermint/client_state.go (1)

126-126: Wrapping the error with additional context in the Validate method when trust level validation fails using errorsmod.Wrapf is a good enhancement. It improves error messages, making them more informative and easier to debug.

modules/light-clients/07-tendermint/light_client_module_test.go (5)

30-99: The test cases in TestStatus are well-structured and cover various scenarios. However, consider adding a brief comment above each test case to explain the scenario being tested for better readability and maintainability.


101-173: In TestGetTimestampAtHeight, the test case "failure: consensus state not found for height" modifies the height variable directly, which could lead to unintended side effects in other test cases due to shared state. Consider isolating test case state or resetting it after each test case.


175-262: In TestInitialize, the error handling checks using ErrorContains are good for specific error messages. However, for errors like fmt.Errorf("failed to unmarshal client state bytes into client state"), consider defining these errors in the module's error file for consistency and easier maintenance.


519-784: In TestVerifyMembership, the use of delayTimePeriod and delayBlockPeriod as global variables for the test suite could lead to unintended side effects if tests are run in parallel or out of order. Consider passing these as parameters to the malleate function or resetting their values before each test case.


786-1010: Similar to TestVerifyMembership, TestVerifyNonMembership also uses global variables for delayTimePeriod and delayBlockPeriod. This approach can lead to flaky tests if the execution order changes or if tests are run in parallel. It's advisable to encapsulate test case state within each test case or reset these variables before each test.

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 ac8271d and edf7a68.
Files selected for processing (1)
  • modules/light-clients/07-tendermint/light_client_module_test.go (2 hunks)
Additional Context Used
Path-based Instructions (1)
modules/light-clients/07-tendermint/light_client_module_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"

Additional comments not posted (5)
modules/light-clients/07-tendermint/light_client_module_test.go (5)

30-99: The test function TestStatus is well-structured and covers various scenarios for the client status. However, consider adding a brief comment above each test case within the testCases slice to explain the scenario being tested for better readability and maintainability.


101-173: The test function TestGetTimestampAtHeight effectively covers both success and failure scenarios. Ensure that the error messages and conditions being tested are up-to-date with the current implementation to maintain accuracy in test coverage.


175-262: In TestInitialize, the error handling and various initialization scenarios are tested. It's crucial to verify that all new error conditions introduced in the PR are covered by these tests. Additionally, consider adding comments to explain complex test setups for future maintainability.


519-784: The TestVerifyMembership function tests various scenarios for verifying membership. It's important to ensure that the test cases cover all new paths and error conditions introduced in the PR. Also, consider simplifying complex test setups or extracting repeated setup code into helper functions for clarity.


786-1010: The TestVerifyNonMembership function provides comprehensive coverage for non-membership verification scenarios. Similar to TestVerifyMembership, ensure all new error conditions and paths are covered. Additionally, review the use of hardcoded values and consider if they can be replaced with constants or variables for easier maintenance.

@crodriguezvega crodriguezvega added the priority PRs that need prompt reviews label Apr 3, 2024
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.

looking at cov locally, lgtm. I'm guessing plan is for follow up for some others?

@charleenfei
Copy link
Contributor Author

looking at cov locally, lgtm. I'm guessing plan is for follow up for some others?

hmm good call on the code cov. I took a look and it looks like the methods: UpdateStateOnMisbehaviour, UpdateState, CheckForMisbehaviour, VerifyClientMessage are not tested from the light client module, but from the client state. As the LCM module is not really doing any extra logic besides fetching the client state and then using the client state methods, I would err on leaving the tests on the client state in update.go -- but I could add some tests in a followup PR just to see if the CS is fetched? wdyt?

charleenfei and others added 3 commits April 9, 2024 14:28
…ient-module-entry-points' of github.com:cosmos/ibc-go into charly/issue#6001-move-client-state-testing-to-light-client-module-entry-points
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.

Looks good to me. Thanks for taking this task, @charleenfei.

@@ -123,7 +123,7 @@ func (cs ClientState) Validate() error {
}

if err := light.ValidateTrustLevel(cs.TrustLevel.ToTendermint()); err != nil {
return err
return errorsmod.Wrapf(ErrInvalidTrustLevel, "%s", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a nit, but I think in other places we do something just like...

Suggested change
return errorsmod.Wrapf(ErrInvalidTrustLevel, "%s", err)
return errorsmod.Wrap(ErrInvalidTrustLevel, err.Error())

@@ -41,7 +43,7 @@ func (l *LightClientModule) RegisterStoreProvider(storeProvider exported.ClientS
func (l LightClientModule) Initialize(ctx sdk.Context, clientID string, clientStateBz, consensusStateBz []byte) error {
var clientState ClientState
if err := l.keeper.Codec().Unmarshal(clientStateBz, &clientState); err != nil {
return err
return fmt.Errorf("failed to unmarshal client state bytes into client state: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I might change this in a follow-up PR, because at the moment we are not consistent with the error we return in these situations for other light clients (in some places we do return err but in other places we do errorsmod.Wrap(clienttypes.ErrInvalidClient, err.Error())...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we mostly return this kind of nonspecific error for unmarshalling/proof verification right now. i guess consistency makes sense but i think for testing/debugging purposes this error also works!

charleenfei and others added 3 commits April 10, 2024 13:09
…ient-module-entry-points' of github.com:cosmos/ibc-go into charly/issue#6001-move-client-state-testing-to-light-client-module-entry-points
Copy link

sonarcloud bot commented Apr 10, 2024

Quality Gate Passed Quality Gate passed for 'ibc-go'

Issues
5 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link
Contributor

@chatton chatton left a comment

Choose a reason for hiding this comment

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

LGTM thank you @charleenfei !

Happy to have additional tests in a follow up.

@charleenfei charleenfei enabled auto-merge (squash) April 11, 2024 10:11
@charleenfei charleenfei merged commit 5ba9146 into main Apr 11, 2024
72 of 74 checks passed
@charleenfei charleenfei deleted the charly/issue#6001-move-client-state-testing-to-light-client-module-entry-points branch April 11, 2024 10:16
bznein pushed a commit to bznein/ibc-go that referenced this pull request Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority PRs that need prompt reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move client state testing to light client module entry points
4 participants