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(02-client): adding tests for GetLatestHeight and refactor tests for GetTimestamptAtHeight #6002

Merged
merged 3 commits into from
Mar 18, 2024

Conversation

damiannolan
Copy link
Contributor

@damiannolan damiannolan commented Mar 14, 2024

Description

Follow up testing PR from #5806

  • Fix correctly wrap error in GetTimestampAtHeight
  • Adds tests for clientKeeper GetLatestHeight
  • Refactor tests for clientKeeper GetTimetstampAtHeight

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 messaging in certain scenarios to help with troubleshooting.
  • Tests
    • Enhanced testing for time-related functionalities to ensure reliability.

Copy link
Contributor

coderabbitai bot commented Mar 14, 2024

Walkthrough

This update focuses on refining error handling in the GetTimestampAtHeight function by wrapping the original error for better traceability and enhancing the testing suite for the 02-client module. It introduces a new test for fetching the latest height, expands the GetTimestampAtHeight test with more scenarios, and improves error handling tests, ensuring robustness and reliability in client-related functionalities.

Changes

Files Change Summary
.../02-client/keeper/keeper.go Modified error handling in GetTimestampAtHeight to wrap the original error.
.../02-client/keeper/keeper_test.go Added TestGetLatestHeight, expanded TestGetTimestampAtHeight, and introduced various test cases for client types and states.

Related issues

  • Refactor 02-client keeper to use testing pkg #4013: The changes in this PR could potentially address the objective of removing pre-testing package fields in the keeper test suite, as it introduces new test cases and expands existing ones, aligning with the goal of leveraging the testing package for improved robustness.

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-tests 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 tests 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 tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@damiannolan damiannolan marked this pull request as ready for review March 14, 2024 19:58
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 56b8170 and 447a8f4.
Files selected for processing (2)
  • modules/core/02-client/keeper/keeper.go (1 hunks)
  • modules/core/02-client/keeper/keeper_test.go (1 hunks)
Additional comments: 3
modules/core/02-client/keeper/keeper.go (1)
  • 504-504: The error wrapping in GetTimestampAtHeight now provides more context by including the clientID, which aligns with the PR's objective to enhance error handling. This change improves the clarity and traceability of errors, especially in scenarios where the ParseClientIdentifier function fails. It's a good practice to include such contextual information in error messages to facilitate easier debugging and issue resolution.
modules/core/02-client/keeper/keeper_test.go (2)
  • 458-511: The TestGetLatestHeight function tests various scenarios for retrieving the latest height from an IBC client. However, there are a few areas that could be improved for clarity and robustness:
  • The test case "invalid client type" might benefit from a more detailed setup or comment explaining why the client ID is considered invalid. This would help future maintainers understand the test's intent more quickly.
  • For the test case "client type is not allowed", it's good practice to reset any global or shared state after the test runs to avoid side effects on other tests. Consider adding a teardown step to reset the ClientKeeper's params to their original values.
  • It's recommended to add a test case to explicitly check for a scenario where the client exists but has no consensus states, as this is a realistic scenario that should be verified.

Consider adding more detailed comments or setup steps to clarify the intent of test cases, especially for "invalid client type". Also, ensure that modifications to shared state (like params) are reset after each test to prevent unintended side effects.

  • 512-581: The TestGetTimestampAtHeight function has been modified to include additional test cases and logic for error handling. Here are some suggestions for improvement:
  • Similar to TestGetLatestHeight, ensure that any changes to global or shared state are properly reset after each test case to prevent side effects.
  • The test case "consensus state not found" is a good addition. Consider adding a brief comment explaining the setup, especially how the height variable is manipulated to ensure the consensus state is not found.
  • For better readability, consider using a table-driven approach for defining test cases if not already done. This approach can make it easier to add new test cases in the future and improve the readability of the test code.

Ensure that modifications to shared state are reset after each test. Consider adding more detailed comments for complex test setups and exploring a table-driven approach for defining test cases to improve readability and maintainability.

@DimitrisJim DimitrisJim linked an issue Mar 15, 2024 that may be closed by this pull request
3 tasks
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.

lgtm, clean as a whistle!

Copy link

@damiannolan damiannolan enabled auto-merge (squash) March 18, 2024 09:04
@damiannolan damiannolan disabled auto-merge March 18, 2024 09:04
@damiannolan damiannolan merged commit d327c07 into main Mar 18, 2024
83 checks passed
@damiannolan damiannolan deleted the damian/add-latest-height-test branch March 18, 2024 09:04
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.

Add error assertion for test on GetTimestampAtHeight
3 participants