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: refactor solomachine tests to use light client module as entrypoint. #6038

Merged
merged 15 commits into from
Apr 3, 2024

Conversation

DimitrisJim
Copy link
Contributor

@DimitrisJim DimitrisJim commented Mar 21, 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
    • Added and updated test functions for the Solo Machine module to enhance coverage on status checks, timestamp retrieval, membership verification, non-membership verification, state updates, and height retrieval.
    • Renamed test functions to adhere to a consistent naming convention.
    • Enhanced error handling in the VerifySignature function for improved clarity and context.
    • Refactored and restructured test functions related to client state validation, membership verification, and timestamp handling for better logic and control flow.
  • Refactor
    • Updated naming conventions for solomachine instances and test functions for consistency and clarity.

Copy link
Contributor

coderabbitai bot commented Mar 21, 2024

Walkthrough

Walkthrough

This update focuses on enhancing the Solo Machine light client module within the IBC protocol, primarily through the introduction of new test functions and renaming existing ones for consistency. It improves error handling and refactors client state testing, aiming to increase code coverage and streamline verification processes related to client status, membership, and state updates.

Changes

File Path Change Summary
.../06-solomachine/light_client_module_test.go Added new test functions for verifying Solo Machine module functionality.
.../06-solomachine/misbehaviour_test.go Renamed TestMisbehaviourValidateBasic to Test_MisbehaviourValidateBasic.
.../06-solomachine/proposal_handle_test.go Renamed TestCheckSubstituteAndUpdateState to Test_Check_SubstituteAndUpdateState.
.../06-solomachine/update_test.go Renamed and updated functions for consistency and to follow naming convention Test_<FunctionName>.
.../06-solomachine/solomachine_test.go Updated names of solomachine instances created during setup.
.../06-solomachine/proof.go Enhanced error handling in VerifySignature function.
.../06-solomachine/client_state_test.go Refactored and restructured test functions related to client state validation and verification processes.

Possibly related issues

  • Move client state testing to light client module entry points #6001: The refactoring and addition of new tests in the Solo Machine module could contribute to the goal of moving client state testing to light client module entry points, addressing some objectives of this issue.
  • Add go.mod for 06-solomachine #4213: While the changes do not directly provide 06-solomachine with its own go.mod file or eliminate dependencies, the focus on enhancing testing could indirectly support the broader goal of improving modularity and reducing dependencies.
  • Refactor 02-client keeper to use testing pkg #4013: Although the changes are specific to the Solo Machine module and not the 02-client module mentioned in the issue, the emphasis on refactoring tests and improving code quality aligns with the objectives of enhancing testing practices across the IBC protocol.

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
Copy link
Contributor Author

opening as draft to get a first run of tests. Will update testing funcs to use expErr and then open for review.

@@ -26,7 +26,7 @@ func VerifySignature(pubKey cryptotypes.PubKey, signBytes []byte, sigData signin
if err := pubKey.VerifyMultisignature(func(signing.SignMode) ([]byte, error) {
return signBytes, nil
}, data); err != nil {
return err
return errorsmod.Wrapf(ErrSignatureVerificationFailed, 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.

Unsure why this didn't do this before but made sense to add. Bumped into it due to tests running for solomachine's configured with a single pubkey and a multi one, adding error checking in the tests lead to a discrepancy here.

@DimitrisJim DimitrisJim changed the title tests: refactor tests to use light client module as entrypoint. tests: refactor solomachine tests to use light client module as entrypoint. Mar 21, 2024
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 06fd8eb and 5a9a52f.
Files selected for processing (3)
  • modules/light-clients/06-solomachine/client_state_test.go (4 hunks)
  • modules/light-clients/06-solomachine/light_client_module_test.go (1 hunks)
  • modules/light-clients/06-solomachine/proof.go (1 hunks)
Additional comments: 3
modules/light-clients/06-solomachine/proof.go (1)
  • 29-29: The error wrapping in VerifySignature enhances error context, which is good practice. However, consider adding more specific context to the error message to aid in debugging. For example, including details about the multisignature verification failure could be helpful.
modules/light-clients/06-solomachine/client_state_test.go (1)
  • 3-13: > 📝 NOTE

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

The modifications to the test functions in client_state_test.go significantly improve test coverage for various verification scenarios. Ensure that each test case has a descriptive name that clearly indicates what is being tested. Additionally, keep the setup and assertions focused and concise to maintain test clarity and effectiveness.

modules/light-clients/06-solomachine/light_client_module_test.go (1)
  • 1-794: The additions and modifications to the test functions in light_client_module_test.go enhance the test suite's coverage and robustness. Ensure that the tests are well-structured and isolated, with clear, descriptive names for each test case. Additionally, verify that the assertions accurately reflect the expected outcomes for each scenario.

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 5a9a52f and 0817f12.
Files selected for processing (2)
  • modules/light-clients/06-solomachine/light_client_module_test.go (2 hunks)
  • modules/light-clients/06-solomachine/solomachine_test.go (1 hunks)
Additional comments: 7
modules/light-clients/06-solomachine/solomachine_test.go (1)
  • 48-49: The identifiers for the Solo Machine instances have been updated to "06-solomachine-1" and "06-solomachine-2". This change improves the clarity of the test setup by making the identifiers more descriptive. However, ensure that these new identifiers are consistently used throughout all tests and related documentation to avoid confusion.
modules/light-clients/06-solomachine/light_client_module_test.go (6)
  • 24-45: The TestStatus function tests the status of a Solo Machine client before and after freezing it. This test is well-structured and covers an important aspect of client behavior. It's good practice to also include a test case for an uninitialized or incorrectly initialized client to ensure the function behaves as expected in error scenarios.
  • 47-92: The TestGetTimestampAtHeight function introduces test cases for retrieving timestamps at specific heights. The setup and execution of test cases are clear and well-structured. However, consider adding a test case for heights that have not been reached yet or are invalid to ensure robust error handling.
  • 94-572: The TestVerifyMembership function tests various scenarios for verifying membership. The test cases are comprehensive, covering success and failure scenarios. It's advisable to ensure that all error messages are clear and informative, especially in complex scenarios like malformed proofs or invalid path types. This helps in debugging and maintaining the tests.
  • 574-792: The TestVerifyNonMembership function, similar to TestVerifyMembership, tests the verification of non-membership with comprehensive scenarios. Ensure consistency in error handling and messaging across these tests for better maintainability and clarity.
  • 1-796: > 📝 NOTE

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

The TestRecoverClient function tests the recovery of a Solo Machine client. This test is crucial for ensuring the robustness of client recovery mechanisms. It's important to include a variety of scenarios, including those where recovery should not be possible, to fully test the boundaries of this functionality.

  • 890-896: > 📝 NOTE

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

The TestVerifyUpgradeAndUpdateState function attempts to verify the upgrade and update state but expects an error. This test is a good start, but it would be beneficial to expand it with more detailed scenarios, including successful upgrade paths and edge cases that might occur during the upgrade process.

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 0817f12 and 60746f4.
Files selected for processing (2)
  • modules/light-clients/06-solomachine/client_state_test.go (4 hunks)
  • modules/light-clients/06-solomachine/light_client_module_test.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • modules/light-clients/06-solomachine/light_client_module_test.go
Additional comments: 2
modules/light-clients/06-solomachine/client_state_test.go (2)
  • 14-14: The code generally adheres to the Uber Golang style guide. However, consider using table-driven tests more effectively by defining the test cases outside the loop over SoloMachines. This approach can improve readability and maintainability.
  • 14-14: The TestSignBytesMarshalling function is clear and tests an important aspect of marshalling behavior. Consider adding comments to explain why it's important that signBzNil and signBzEmptyArray produce the same output, as this could help future maintainers understand the test's purpose.

@DimitrisJim
Copy link
Contributor Author

DimitrisJim commented Mar 25, 2024

I'll add functions for misbehaviour, update/upgrade etc and copy the test cases from there in the light client module, as is done for the 08-wasm PR. I think we'll probably fold more solomachine methods and then tests won't really need updating.

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 60746f4 and fda0fdc.
Files selected for processing (4)
  • modules/light-clients/06-solomachine/light_client_module_test.go (5 hunks)
  • modules/light-clients/06-solomachine/misbehaviour_test.go (1 hunks)
  • modules/light-clients/06-solomachine/proposal_handle_test.go (1 hunks)
  • modules/light-clients/06-solomachine/update_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • modules/light-clients/06-solomachine/update_test.go
Additional comments: 9
modules/light-clients/06-solomachine/proposal_handle_test.go (1)
  • 12-12: The function name Test_Check_SubstituteAndUpdateState uses underscores, which is unconventional in Go. Consider using CamelCase for test function names to align with Go naming conventions. However, if this naming scheme is a project-specific decision for readability or other reasons, it can be considered acceptable.
modules/light-clients/06-solomachine/misbehaviour_test.go (1)
  • 15-15: The function name Test_MisbehaviourValidateBasic uses underscores, which is unconventional in Go. Consider using CamelCase for test function names to align with Go naming conventions. However, if this naming scheme is a project-specific decision for readability or other reasons, it can be considered acceptable.
modules/light-clients/06-solomachine/light_client_module_test.go (7)
  • 26-26: The function TestStatus correctly tests various scenarios related to the status of a solo machine client. It's good practice to reset the test environment at the beginning of each test case using suite.SetupTest() to ensure test isolation.
  • 81-81: The function TestGetTimestampAtHeight effectively tests the retrieval of timestamps at specific heights. Consider adding more test cases to cover edge cases, such as heights that have not been reached yet.
  • 204-204: The function TestVerifyMembership is comprehensive and covers a wide range of scenarios for verifying membership. It's good to see the use of table-driven tests for clarity. Ensure that the test data used (e.g., counterpartyClientIdentifier, ibctesting.FirstConnectionID) is correctly set up and represents realistic scenarios.
  • 686-686: The function TestVerifyNonMembership thoroughly tests the non-membership verification logic. Similar to TestVerifyMembership, ensure that the test setup accurately reflects realistic scenarios and that all necessary preconditions are met before running the tests.
  • 1005-1005: The function TestUpdateState demonstrates how to test state updates in the solo machine client. It's important to ensure that the test cases cover all possible state transitions, including error scenarios and edge cases. Consider adding comments to explain the rationale behind each test case, especially for complex scenarios.
  • 1092-1092: The function TestVerifyUpgradeAndUpdateState attempts to test the upgrade and update state functionality. However, it only tests for an error scenario. It would be beneficial to add more test cases that cover successful upgrade scenarios and verify the state of the client post-upgrade.
  • 1101-1101: The function TestLatestHeight correctly tests the retrieval of the latest height for a solo machine client. It's a good practice to test both successful retrieval and error scenarios, such as when the client state cannot be found. Ensure that the test setup accurately reflects the state of the blockchain at various heights.

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 fda0fdc and 19cd092.
Files selected for processing (2)
  • modules/light-clients/06-solomachine/light_client_module_test.go (4 hunks)
  • modules/light-clients/06-solomachine/update_test.go (5 hunks)
Files not summarized due to errors (1)
  • modules/light-clients/06-solomachine/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/06-solomachine/update_test.go
Additional comments: 12
modules/light-clients/06-solomachine/light_client_module_test.go (12)
  • 27-80: The test function TestStatus effectively covers different scenarios for the status of a SoloMachine client, including active, frozen, and unknown states. It's well-structured and follows best practices for table-driven tests in Go. However, it's recommended to add a brief comment above each test case struct to explain the purpose of the malleate function and expected outcomes for clarity and maintainability.
  • 82-124: The function TestGetTimestampAtHeight is well-implemented, testing both successful retrieval of a timestamp and handling of a client not found error. To enhance the test's robustness, consider adding more edge cases, such as querying a height that doesn't exist or a height with a default timestamp value. This would ensure the function behaves correctly under all circumstances.
  • 178-188: > 📝 NOTE

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

In TestInitialize, the test cases are comprehensive, covering various scenarios for both consensus state and client state validation. However, there's a potential improvement in error handling. Specifically, when testing for expected errors, using suite.Require().ErrorIs instead of suite.Require().ErrorContains would ensure that the exact error type is returned, not just an error containing a specific message. This change would make the tests more precise and reliable.

- suite.Require().ErrorContains(err, tc.expErr.Error())
+ suite.Require().ErrorIs(err, tc.expErr)
  • 205-687: The TestVerifyMembership function thoroughly tests various scenarios for verifying membership with the SoloMachine light client. It's commendable that the test covers a wide range of cases, including success scenarios for different state verifications and various error conditions. To further improve, consider abstracting the repetitive setup logic (e.g., creating signature documents, marshaling data) into helper functions. This would reduce code duplication and enhance readability.
  • 687-906: Similar to TestVerifyMembership, TestVerifyNonMembership provides a comprehensive suite of tests for non-membership verification. The recommendation to abstract repetitive setup logic into helper functions applies here as well. Additionally, ensure consistency in error handling as mentioned previously, by using suite.Require().ErrorIs for stronger assertion of expected errors.
  • 908-1004: TestRecoverClient effectively tests the client recovery functionality, including scenarios where the substitute client ID is malformed or does not match the expected client type. It's recommended to add a comment explaining the rationale behind each malleate function, especially for cases that might not be immediately obvious, such as why changing the substitute client ID to a wasm client ID should result in an ErrInvalidClientType.
  • 1006-1090: The TestUpdateState function tests the state update functionality of the SoloMachine light client. The test cases are well-structured and cover a range of scenarios. However, the test case named "invalid type misbehaviour" seems to expect a panic with a specific error message. Given that panicking in production code is generally discouraged, it would be beneficial to verify if the code being tested should indeed panic under these conditions or if there's a more graceful way to handle such errors.
Verification successful

The grep command output confirms that the code in question does indeed use panic in response to an unsupported ClientMessage, specifically in the update.go file. This directly aligns with the concern raised in the review comment about the use of panic in production code for handling invalid client messages. Therefore, the review comment is validated by the evidence found in the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify if the code correctly handles invalid client messages without panicking
grep -R "panic" modules/light-clients/06-solomachine/*.go

Length of output: 1927

* 1092-1164: `TestCheckForMisbehaviour` provides a good set of tests for checking misbehaviour detection. It's important to ensure that the test cases cover all possible misbehaviour scenarios comprehensively. Additionally, consider adding comments to explain the setup and expected outcomes in complex test cases, enhancing readability and maintainability. * 1166-1226: In `TestUpdateStateOnMisbehaviour`, the tests are focused and cover the essential scenarios. It's recommended to ensure that the test for "cannot find subject client state" accurately reflects the behavior of the system when the client state is indeed missing. This might involve verifying that the correct error is returned or that the system behaves as expected in the absence of the client state.
Verification successful

The grep output confirms that the test suite, specifically TestUpdateStateOnMisbehaviour, interacts with the client state retrieval mechanism (GetClientState) and includes a test case designed to simulate and verify the system's behavior when the client state is missing. This test case manipulates the clientID to an unused value to simulate the absence of the client state and expects a specific error, which aligns with the intended system behavior. Therefore, the review comment's concern is addressed by the existing test implementation.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Ensure that the system behaves correctly when the client state is missing
grep -R "GetClientState" modules/light-clients/06-solomachine/*.go

Length of output: 2197

* 1228-1401: `TestVerifyClientMessageHeader` and `TestVerifyClientMessageMisbehaviour` are crucial for ensuring the integrity of client messages. These tests are comprehensive, but there's room for improvement in error handling and clarity. Specifically, ensure that the tests accurately reflect the expected behavior for each scenario, especially in cases where the outcome might depend on subtle aspects of the system's state or configuration. Adding detailed comments to complex test cases would also improve understandability. * 1649-1658: The `TestVerifyUpgradeAndUpdateState` function tests the upgrade verification and state update functionality. It's important to ensure that this test covers all relevant scenarios, including successful upgrades and various error conditions. If the current implementation is expected to always return an error (as suggested by the assertion), clarify the intended use case and conditions under which this functionality would be used. * 1659-1702: `TestLatestHeight` provides a straightforward test for retrieving the latest height of the client. The test cases are simple and cover the basic scenarios. To enhance the test's coverage, consider adding scenarios that involve updating the client's state to a new height and then verifying that `LatestHeight` returns the updated height. This would ensure the function behaves correctly after state changes.

@DimitrisJim
Copy link
Contributor Author

Changed functions to check for errors, cleaned up some additional cruft (we should be able to remove suite.store soon ref stored) and generally tried to clean these up as much as possible for time being.

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 19cd092 and c58bf3d.
Files selected for processing (1)
  • modules/light-clients/06-solomachine/light_client_module_test.go (5 hunks)
Files not summarized due to errors (1)
  • modules/light-clients/06-solomachine/light_client_module_test.go: Error: Message exceeds token limit
Additional comments: 12
modules/light-clients/06-solomachine/light_client_module_test.go (12)
  • 27-78: The test cases for TestStatus are well-structured and cover various scenarios including active, frozen, and unknown client states. However, it's important to ensure that the setup for each test case does not inadvertently affect other tests due to shared state. Using suite.SetupTest() within each test case can help isolate them.
  • 80-126: In TestGetTimestampAtHeight, consider adding more edge cases, such as querying a height that doesn't exist or a height that is greater than the current sequence. This can help ensure the robustness of the timestamp retrieval logic.
  • 138-174: > 📝 NOTE

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

For TestInitialize, it's crucial to validate the error messages for each failure case to ensure they are informative and specific to the failure scenario. This aids in debugging and maintainability. Additionally, consider testing the initialization with various consensus state types to ensure compatibility.

  • 207-685: TestVerifyMembership thoroughly tests the verification of membership for various states and scenarios. To enhance these tests, consider adding cases that simulate network or encoding errors to ensure the robustness of error handling. Also, verify the state of the client after successful and failed verifications to ensure it remains consistent.
  • 689-909: In TestVerifyNonMembership, similar to the membership verification tests, it would be beneficial to include tests for network or encoding errors. Additionally, testing the effect of non-membership verification on client state would ensure that the client's state is not inadvertently modified.
  • 912-1008: TestRecoverClient covers the basic scenarios for client recovery. It would be beneficial to add tests that simulate more complex recovery scenarios, such as recovering from a state where multiple updates have occurred since the last known good state. This can help ensure the resilience of the recovery process.
  • 1010-1095: For TestUpdateState, ensure that the tests cover scenarios where the update would be rejected due to invalid state transitions or incorrect signatures. This can help validate the robustness of the state update logic.
  • 1097-1169: TestCheckForMisbehaviour effectively tests for misbehaviour detection. Consider adding tests that simulate edge cases, such as misbehaviour that is barely within the acceptable time window or misbehaviour involving complex signature schemes.
  • 1171-1231: In TestUpdateStateOnMisbehaviour, it's important to test the client's state after misbehaviour has been detected and processed. This includes verifying that the client is correctly frozen and that subsequent updates are rejected.
  • 1233-1404: TestVerifyClientMessageHeader and TestVerifyClientMessageMisbehaviour provide comprehensive tests for verifying client messages. To further improve these tests, consider adding scenarios that test the limits of the message verification logic, such as messages with minimal or maximal valid values.
  • 1652-1661: TestVerifyUpgradeAndUpdateState checks the upgrade verification logic. Given the critical nature of client upgrades, it's essential to include tests that cover a wide range of upgrade scenarios, including valid and invalid upgrade proposals, to ensure the upgrade process is robust and secure.
  • 1662-1704: For TestLatestHeight, adding tests that simulate scenarios where the client has undergone several state updates would provide a more thorough validation of the LatestHeight functionality. This ensures that the latest height is accurately reported under various conditions.

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.

Great work, @DimitrisJim! Left just a bunch of nits.


suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), clientID, sm.ClientState())
},
// TODO(jim): Doesn't fail on VerifySignature
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to follow up on these TODOs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not entirely certain if this should fail there. Just added a todo since it seemed sketch to me. I will follow up on them.

Copy link
Member

Choose a reason for hiding this comment

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

these were previously using the expPass format in testing, right?

Will check out the branch and step through with debugger and see if I can help!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, exactly. This is an unfortunate thing that happens when we swap from expPass to expErr, some expPass false's just failed in earlier points.

modules/light-clients/06-solomachine/solomachine_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: 2

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between c58bf3d and 236f723.
Files selected for processing (1)
  • modules/light-clients/06-solomachine/light_client_module_test.go (5 hunks)
Files not summarized due to errors (1)
  • modules/light-clients/06-solomachine/light_client_module_test.go: Error: Message exceeds token limit
Additional comments: 2
modules/light-clients/06-solomachine/light_client_module_test.go (2)
  • 22-24: Given the existing comment about potentially removing smClientID in favor of unusedSmClientID, it's important to assess if this change has been made. If smClientID is no longer used, consider removing it to clean up the code and reduce confusion.
  • 22-24: The constants smClientID, unusedSmClientID, and wasmClientID are defined but it's important to ensure they are used appropriately throughout the tests. Given the previous comment about potentially consolidating smClientID and unusedSmClientID, verify their usage and ensure consistency in their application.
Verification successful

The constants smClientID, unusedSmClientID, and wasmClientID are indeed used throughout the tests in modules/light-clients/06-solomachine/light_client_module_test.go, each serving specific roles within the test scenarios. The usage patterns suggest that these constants are applied consistently and appropriately, aligning with the expectations for varied test cases, including error handling and specific client testing. Therefore, the review comment is verified as the constants are utilized effectively in the test file.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check usage of smClientID and unusedSmClientID
rg "smClientID|unusedSmClientID" modules/light-clients/06-solomachine/light_client_module_test.go

Length of output: 1022


suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), clientID, sm.ClientState())
},
// TODO(jim): Doesn't fail on VerifySignature
Copy link
Contributor

Choose a reason for hiding this comment

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

The TODO comment regarding the uncertainty of a test case failing at a specific point needs attention. It's crucial to resolve such uncertainties to ensure the test suite is reliable and covers all necessary scenarios. If the behavior is now understood, the TODO should be addressed by either implementing the required test logic or removing the comment if deemed unnecessary.

Would you like assistance in resolving this TODO by clarifying the expected behavior and potentially adding the necessary test logic?


Given the TODO comment about the uncertainty of a test case's expected behavior, it's crucial to follow up and ensure that all test cases are clear and accurately reflect the intended functionality. Ambiguities in test expectations can lead to overlooked issues or misinterpretations of the light client's behavior.

If there's still uncertainty regarding this test case, I can help clarify the expected behavior or assist in refining the test to ensure it accurately tests the intended functionality.

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 236f723 and 6c97bb1.
Files selected for processing (1)
  • modules/light-clients/06-solomachine/solomachine_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • modules/light-clients/06-solomachine/solomachine_test.go

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.

really thorough work @DimitrisJim! thank you

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 6c97bb1 and 45e483c.
Files selected for processing (2)
  • modules/light-clients/06-solomachine/light_client_module_test.go (5 hunks)
  • modules/light-clients/06-solomachine/proof.go (1 hunks)
Files not summarized due to errors (1)
  • modules/light-clients/06-solomachine/light_client_module_test.go: Error: Message exceeds token limit
Additional Context Used
Path-based Instructions (2)
modules/light-clients/06-solomachine/proof.go (1)

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

modules/light-clients/06-solomachine/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 (14)
modules/light-clients/06-solomachine/proof.go (1)

29-29: The error wrapping with errorsmod.Wrapf adds valuable context to the error, making it easier to debug issues related to signature verification. This change aligns with best practices for error handling in Go, as it provides more detailed error information.

modules/light-clients/06-solomachine/light_client_module_test.go (13)

26-77: The TestStatus function is well-structured and uses table-driven tests effectively to cover different client statuses. This approach enhances the readability and maintainability of the test code.


79-125: The TestGetTimestampAtHeight function effectively tests the timestamp retrieval functionality, including both success and failure scenarios. The use of table-driven tests is commendable for its clarity.


137-173: > 📝 NOTE

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

The TestInitialize function thoroughly tests the initialization process of the Solo Machine client, covering a wide range of scenarios. The detailed test cases ensure that both success and failure paths are adequately tested.


206-683: The TestVerifyMembership function comprehensively tests the membership verification functionality of the Solo Machine client. The extensive range of test cases, including both success and failure scenarios, ensures thorough coverage of the functionality.


688-906: The TestVerifyNonMembership function provides a thorough examination of the non-membership verification functionality, with a well-structured set of test cases that cover both successful and failure scenarios.


911-1007: The TestRecoverClient function effectively tests the client recovery process, including both successful recovery and various failure scenarios. The clear separation of test cases enhances the readability and maintainability of the test code.


1009-1094: The TestUpdateState function thoroughly tests the state update functionality for the Solo Machine client, covering both successful updates and failure scenarios. The use of table-driven tests contributes to the clarity of the test code.


1096-1168: The TestCheckForMisbehaviour function effectively tests the detection of misbehaviour, including both successful detection and failure scenarios. The structured approach to testing ensures comprehensive coverage of the functionality.


1170-1229: The TestUpdateStateOnMisbehaviour function provides a focused test on the client state update process in response to detected misbehaviour. The inclusion of both a successful update and a failure scenario due to missing client state ensures thorough testing of this critical functionality.


1232-1403: The TestVerifyClientMessageHeader function comprehensively tests the verification of client message headers, covering a wide range of scenarios. The detailed test cases ensure that both success and failure paths are adequately tested, contributing to the robustness of the Solo Machine client implementation.


1405-1649: The TestVerifyClientMessageMisbehaviour function thoroughly tests the verification of client message misbehaviour, with a well-structured set of test cases that cover both successful detection and various failure scenarios. This approach ensures comprehensive testing of misbehaviour detection functionality.


1651-1659: The TestVerifyUpgradeAndUpdateState function correctly tests for an error due to missing implementation details for the upgrade verification and state update process. This placeholder test ensures that the functionality is not overlooked in future development.


1661-1702: The TestLatestHeight function effectively tests the retrieval of the latest height for the Solo Machine client, including both a successful retrieval and a failure scenario due to missing client state. The clear and concise test cases contribute to the maintainability of the test suite.

Comment on lines +1356 to +1357
// TODO(jim): Doesn't fail on VerifySignature
clienttypes.ErrInvalidHeader,
Copy link
Contributor

Choose a reason for hiding this comment

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

The TODO comment at lines 1356-1357 regarding the uncertainty of a test case failing at a specific point needs attention. It's crucial to resolve such uncertainties to ensure the test suite is reliable and covers all necessary scenarios. If the behavior is now understood, the TODO should be addressed by either implementing the required test logic or removing the comment if deemed unnecessary.

Would you like assistance in resolving this TODO by clarifying the expected behavior and potentially adding the necessary test logic?

Copy link
Member

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

Awesome work @DimitrisJim! Dropping my approval, will follow up on the todos with you also - I check this out locally and step through to take a look


suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), clientID, sm.ClientState())
},
// TODO(jim): Doesn't fail on VerifySignature
Copy link
Member

Choose a reason for hiding this comment

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

these were previously using the expPass format in testing, right?

Will check out the branch and step through with debugger and see if I can help!

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

Review Status

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 45e483c and 1c3ad24.
Files selected for processing (1)
  • modules/light-clients/06-solomachine/light_client_module_test.go (5 hunks)
Files not summarized due to errors (1)
  • modules/light-clients/06-solomachine/light_client_module_test.go: Error: Message exceeds token limit
Additional Context Used
Path-based Instructions (1)
modules/light-clients/06-solomachine/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 (13)
modules/light-clients/06-solomachine/light_client_module_test.go (13)

26-77: Consider adding a test case for an uninitialized client state to ensure the function handles this scenario gracefully.


79-137: Add a test case to verify behavior when the height argument is greater than the current height of the client state, ensuring the function's robustness in handling such cases.


149-185: > 📝 NOTE

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

Ensure that the test case for a successful initialization verifies not only the absence of errors but also the correct state of the client post-initialization, such as checking if the client state and consensus state are correctly set in the store.


218-696: Consider adding a test case for verifying membership with a valid proof but for data that does not exist in the state, to ensure the function correctly identifies non-existent data as not being part of the state.


700-920: Add a test case for verifying non-membership with a proof that incorrectly indicates the presence of data, to ensure the function correctly identifies such proofs as invalid.


923-1019: In the test case for successful client recovery, verify that the subject client's state is correctly updated to reflect the substitute client's state, including checking the consensus state and sequence number.


1021-1106: For the test case "failure: invalid type misbehaviour", ensure that the test not only checks for the expected error but also verifies that the client state remains unchanged after attempting to update with an invalid misbehaviour.


1108-1180: In the test case for detecting misbehaviour, verify that the client state is correctly updated to reflect the detected misbehaviour, such as checking if the client state is frozen.


1182-1241: In the success scenario for updating state on misbehaviour, ensure that the test verifies the client state is correctly marked as frozen and that the consensus state is updated accordingly.


1244-1415: For the test case "failure: invalid timestamp in header", consider adding a verification step to ensure that the client state remains unchanged after attempting to process an invalid header, maintaining the integrity of the client state.


1417-1660: In the test case "success: successful misbehaviour", ensure that the test verifies the client state is correctly updated to reflect the detected misbehaviour, such as checking if the client state is frozen and the misbehaviour is recorded.


1663-1671: Consider adding test cases for successful upgrade verification and update of the client state, as well as failure scenarios with specific reasons for the upgrade verification failure, to ensure comprehensive testing of the upgrade process.


1673-1715: In the success scenario for retrieving the latest height, verify that the test setup includes updating the client state to a higher sequence number before retrieving the latest height, to ensure the function correctly returns the most recent height.

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

Review Status

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 45e483c and 048debd.
Files selected for processing (2)
  • modules/light-clients/06-solomachine/client_state_test.go (4 hunks)
  • modules/light-clients/06-solomachine/light_client_module_test.go (5 hunks)
Files not summarized due to errors (1)
  • modules/light-clients/06-solomachine/light_client_module_test.go: Error: Message exceeds token limit
Additional Context Used
Path-based Instructions (2)
modules/light-clients/06-solomachine/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/06-solomachine/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 (1)
modules/light-clients/06-solomachine/client_state_test.go (1)

17-17: LGTM! The TestSignBytesMarshalling function correctly tests the marshalling behavior for sign bytes with nil and empty array data.

Copy link

sonarcloud bot commented Apr 3, 2024

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

Issues
1 New issue
0 Accepted issues

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

See analysis details on SonarCloud

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

Successfully merging this pull request may close these issues.

4 participants