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

tests: move tests from client state to light client module for 08-wasm. #6052

Merged
merged 10 commits into from
Apr 3, 2024

Conversation

DimitrisJim
Copy link
Contributor

@DimitrisJim DimitrisJim commented Mar 22, 2024

Description

partially addresses #6001


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

  • Tests
    • Enhanced testing for light client modules, focusing on status checks, timestamp retrieval, client initialization, proof verification, and recovery processes.
    • Refactored tests for better structure, data accuracy, and error handling.
    • Reordered imports in test file to enhance organization.

Copy link
Contributor

coderabbitai bot commented Mar 22, 2024

Important

Auto Review Skipped

Auto reviews are disabled on base/target branches other than the default branch. Please add the base/target branch pattern to the list of additional branches to be reviewed in the settings.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Walkthrough

The updates involve reordering imports, modifying test functions, and improving validations within the 08-wasm module. These changes aim to enhance the testing framework and functionality related to light client operations, focusing on code coverage improvements and refactoring for better test case handling.

Changes

Files Change Summary
.../light-clients/08-wasm/types/client_state_test.go Reordered imports and adjusted test functions for TestValidate and TestInitialize, enhancing test cases and validations.

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

@DimitrisJim DimitrisJim force-pushed the jim/issue6001-08wasm branch 2 times, most recently from 9d4d25d to b3a608d Compare March 22, 2024 13:19
Comment on lines -290 to -296
{
"failure: clientStore prefix does not include clientID",
func() {
clientStore = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), ibctesting.InvalidID)
},
types.ErrVMError,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed during move, it should now be impossible for the clientStore prefix to not include client id (we look up the store using the client id in the light client method). Correct me if I'm missing something!

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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 5514d56 and b3a608d.
Files selected for processing (2)
  • modules/light-clients/08-wasm/light_client_module_test.go (3 hunks)
  • modules/light-clients/08-wasm/types/client_state_test.go (2 hunks)
Additional comments: 9
modules/light-clients/08-wasm/types/client_state_test.go (2)
  • 10-11: Consider grouping imports to enhance readability. Standard library imports should be grouped together, followed by third-party packages, and then internal package imports.
  • 64-66: > 📝 NOTE

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

The test cases for TestStatus are well-structured and cover a variety of scenarios including active, frozen, expired, unknown, and unauthorized client statuses. Ensure that the mock callbacks are correctly simulating the expected behavior for each case.

modules/light-clients/08-wasm/light_client_module_test.go (7)
  • 35-104: The TestStatus function provides comprehensive test coverage for different client statuses. It's important to ensure that the mock callbacks accurately represent the behavior of the wasm module for each status.
  • 106-194: The TestGetTimestampAtHeight function tests the timestamp retrieval at a specific height. Ensure that the mock callbacks return the expected timestamp and handle errors as intended. Also, verify that the test cases cover both successful and failure scenarios adequately.
  • 196-318: The TestInitialize function tests the initialization of the client. It's crucial to ensure that the test cases cover various scenarios including success, failure due to invalid consensus state, failure due to unregistered checksum, and VM errors. Pay special attention to the mock callbacks and their return values to ensure they simulate the expected behavior.
  • 320-467: The TestVerifyMembership function tests the membership verification logic. Ensure that the test setup, mock callbacks, and assertions correctly simulate and verify the membership proof verification process. It's also important to cover scenarios where the contract returns errors or invalid proofs.
  • 469-626: The TestVerifyNonMembership function tests the non-membership verification logic. Similar to the membership verification tests, ensure that the test setup, mock callbacks, and assertions accurately represent the non-membership proof verification process, including handling errors and invalid proofs.
  • 660-673: > 📝 NOTE

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

The TestRecoverClient function tests the client recovery process. Ensure that the test cases cover scenarios such as malformed substitute client ID, substitute client ID without the expected prefix, and missing client states. The test setup should accurately simulate the conditions for each scenario.

  • 774-780: > 📝 NOTE

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

The TestVerifyUpgradeAndUpdateState function tests the upgrade and update state verification logic. Ensure that the test cases comprehensively cover scenarios including success, missing client state, invalid upgraded client or consensus state, and height checks. The mock callbacks should accurately simulate the expected behavior for each scenario.

@crodriguezvega crodriguezvega added the priority PRs that need prompt reviews label Mar 25, 2024
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! looks like there's some excess commented code we can remove but nice job refactoring to use the new new module routing!

modules/light-clients/08-wasm/light_client_module_test.go Outdated Show resolved Hide resolved
modules/light-clients/08-wasm/light_client_module_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@charleenfei charleenfei left a comment

Choose a reason for hiding this comment

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

thanks @DimitrisJim !

@DimitrisJim
Copy link
Contributor Author

DimitrisJim commented Mar 25, 2024

After some back and forth and a message in slack, decided to go ahead and move all client state tests to light_client_test. If we go about removing most of the methods on client state, this will be a needed step.

Opened a branch 08-wasm-refactor to hack on instead of pushing to main, I feel like this will be bigger than I initially expected 😅

sorry for the hassle @charleenfei and @chatton 😞

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.

Review Status

Actionable comments generated: 1

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 572d8e8 and 5104b81.
Files selected for processing (2)
  • modules/light-clients/08-wasm/light_client_module_test.go (2 hunks)
  • modules/light-clients/08-wasm/types/client_state_test.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • modules/light-clients/08-wasm/light_client_module_test.go
Additional comments: 2
modules/light-clients/08-wasm/types/client_state_test.go (2)
  • 303-360: The modifications to the TestValidate function, including the addition of new test cases, enhance the test coverage and robustness. These changes are well-structured and improve the validation of client state data and checksums.
  • 4-12: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [262-292]

The enhancements to the TestInitialize function, including the addition of new test cases and improved error handling, contribute positively to the clarity and comprehensiveness of the testing framework. These changes are well-aligned with the objectives of the PR.

modules/light-clients/08-wasm/types/client_state_test.go Outdated Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 5104b81 and 35b55fc.
Files selected for processing (1)
  • modules/light-clients/08-wasm/types/client_state_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • modules/light-clients/08-wasm/types/client_state_test.go

@DimitrisJim DimitrisJim changed the base branch from main to 08-wasm-refactor March 25, 2024 22:34
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.

Review Status

Actionable comments generated: 4

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 35b55fc and 482c97e.
Files selected for processing (2)
  • modules/light-clients/08-wasm/light_client_module_test.go (2 hunks)
  • modules/light-clients/08-wasm/types/client_state_test.go (2 hunks)
Files not summarized due to errors (1)
  • modules/light-clients/08-wasm/light_client_module_test.go: Error: Message exceeds token limit
Files skipped from review as they are similar to previous changes (1)
  • modules/light-clients/08-wasm/types/client_state_test.go
Additional comments: 8
modules/light-clients/08-wasm/light_client_module_test.go (8)
  • 245-367: In TestInitialize, the test case "success: validate contract address" performs a comprehensive check, including the validation of the contract address and the correct instantiation of client and consensus states. This is a good practice as it ensures the initialization logic is correctly implemented. However, consider adding more negative test cases to cover scenarios where initialization might fail due to invalid inputs or system states.

Consider adding test cases for scenarios where initialization fails due to invalid client state, consensus state, or other system constraints.

  • 370-515: The TestVerifyMembership function tests various scenarios for verifying membership using a wasm light client. It's comprehensive and covers a range of success and failure scenarios. However, there's a potential improvement in how test setup is done. Repeated setup code can be refactored into helper functions to improve readability and maintainability.

Consider refactoring repeated setup code into helper functions to reduce duplication and improve test readability.

  • 518-682: Similar to TestVerifyMembership, TestVerifyNonMembership covers a wide range of scenarios. The comments made for TestVerifyMembership regarding unique test case names and refactoring setup code apply here as well.

Ensure test case names are unique and consider refactoring setup code for better readability.

  • 685-791: TestVerifyClientMessage effectively tests the verification of client messages. It includes both positive and negative scenarios, which is good for ensuring robustness. However, the test case "failure: invalid client message" might benefit from a more detailed assertion to ensure the correct error type is returned.

Add more detailed assertions to ensure the correct error type is returned in failure scenarios.

  • 1100-1256: TestUpdateState tests the state update functionality. The test cases are comprehensive, covering both success and failure scenarios. However, the test case "failure: invalid ClientMessage type" uses a panic with a formatted error message. It's generally better to use structured errors for more predictable error handling.

Consider using structured errors instead of formatted strings for error messages to improve error handling predictability.

  • 1258-1403: TestUpdateStateOnMisbehaviour effectively tests the update state on misbehaviour functionality. The test cases are comprehensive, but similar to previous comments, ensure that test setup code is not unnecessarily repeated and consider using helper functions.

Refactor repeated setup code into helper functions for improved test code maintainability.

  • 1405-1557: TestRecoverClient tests the client recovery functionality. It's important to ensure that all edge cases are covered, including error scenarios from the wasm VM and contract. The test cases provided cover a good range of scenarios, but ensure that the test setup and assertions are as clear and concise as possible.

Ensure test setup and assertions are clear and concise, covering all edge cases for client recovery functionality.

  • 1558-1601: TestLatestHeight tests the retrieval of the latest height for a wasm light client. The test cases are straightforward and cover the basic scenario and a failure case. Consider adding more test cases to cover additional edge cases or error scenarios that might occur in practice.

Consider adding more test cases to cover additional edge cases or error scenarios for the latest height retrieval functionality.

modules/light-clients/08-wasm/light_client_module_test.go Outdated Show resolved Hide resolved
modules/light-clients/08-wasm/light_client_module_test.go Outdated Show resolved Hide resolved
modules/light-clients/08-wasm/light_client_module_test.go Outdated Show resolved Hide resolved
modules/light-clients/08-wasm/light_client_module_test.go Outdated Show resolved Hide resolved
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.

Fantastic work moving all these tests, @DimitrisJim. Let me know if you want a hand working on some of the TODOs you have.

modules/light-clients/08-wasm/light_client_module_test.go Outdated Show resolved Hide resolved
Comment on lines +852 to +859
{
"failure: upgraded consensus state is not wasm consensus state",
func() {
// set upgraded consensus state to solomachine consensus state
upgradedConsState = &solomachine.ConsensusState{}
},
clienttypes.ErrInvalidConsensus,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Will you manage to fix this one? I tried something like upgradedConsState = &solomachine.ConsensusState{Diversifier: "diversifier", Timestamp: 10000000} but looks like the unmarshaling doesn't return an error, it just unmarshals to an empty 08-wasm consensus state...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this is a tricky one yea? 08-wasm's consensus state is actually just a wrapper around a blob of bytes. Whatever random consensus state we pass to it will just dump its contents in there. I feel like there should be a way to cause this bugger to fail but havent found it yet.

More than comfy to tackle this one afterwards though!

},
/* TODO(jim): We don't pass a client state directly now so we need to modify how this is tested.
{
"failure: invalid substitute client state",
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this could be tested if we pass a substituteClientID for a non-08-wasm client, and then the casting here would fail...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, we check that substitute client identifier contains an 08-wasm prefix here:

if substituteClientType != types.Wasm {

We can follow up on this one after more refactoring is done.

Copy link

sonarcloud bot commented Apr 3, 2024

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

Issues
0 New issues
0 Accepted issues

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

See analysis details on SonarCloud

@DimitrisJim
Copy link
Contributor Author

merging, we can address any follow ups afterwards targeting the 08-wasm-refactor branch.

@DimitrisJim DimitrisJim merged commit 76ec2c9 into 08-wasm-refactor Apr 3, 2024
78 checks passed
@DimitrisJim DimitrisJim deleted the jim/issue6001-08wasm branch April 3, 2024 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
02-client 08-wasm priority PRs that need prompt reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants