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(integration): port x/evidence tests to server v2 #22709

Merged
merged 6 commits into from
Dec 3, 2024

Conversation

akhilkumarpilli
Copy link
Contributor

@akhilkumarpilli akhilkumarpilli commented Dec 2, 2024

Description

Closes: #22668


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • Chores

    • Removed the app_config.go file, simplifying the application configuration.
  • Documentation

    • Updated comments for clarity in the app.go file.
  • Refactor

    • Restructured the genesis_test.go file for improved clarity and maintainability.
    • Renamed and restructured infraction_test.go to evidence_test.go, enhancing context management.
    • Introduced new context management functions in services.go to improve robustness.

Copy link
Contributor

coderabbitai bot commented Dec 2, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request involves significant changes to the testing framework and application configuration within a Cosmos SDK-based application. Key modifications include the removal of the app_config.go file, updates to test files for better context management, and the introduction of new functions for handling context in the integration package. Additionally, there are improvements in the naming conventions and organization of test suites, which enhance the clarity and maintainability of the test code.

Changes

File Path Change Summary
tests/integration/evidence/app_config.go Deleted the file, which contained the application configuration for the evidence module.
tests/integration/v2/app.go Updated comments for clarity, correcting typographical errors.
tests/integration/v2/distribution/module_test.go Reordered import statements without affecting functionality.
tests/integration/v2/evidence/genesis_test.go Changed package name, updated context management, and restructured the SetupTest method for simplicity.
tests/integration/v2/evidence/infraction_test.go Renamed to evidence_test.go, updated package declaration, and restructured context handling.
tests/integration/v2/services.go Added new functions for improved context management without altering existing logic.

Possibly related PRs

Suggested labels

C:x/evidence, C:server/v2, backport/v0.52.x

Suggested reviewers

  • kocubinski
  • facundomedica
  • testinginprod
  • julienrbrt
  • sontrinh16

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@akhilkumarpilli akhilkumarpilli changed the title tests(integration): port x/evidence tests to server v2 test(integration): port x/evidence tests to server v2 Dec 2, 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.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
tests/integration/v2/evidence/infraction_test.go (2)

85-85: Consider using testing.TB instead of *testing.T

Changing the parameter from tb testing.TB to t *testing.T in initFixture reduces flexibility, as testing.TB allows both *testing.T and *testing.B. Unless specific methods of *testing.T are required, consider retaining testing.TB for broader compatibility.

Apply this diff to revert to testing.TB:

-func initFixture(t *testing.T) *fixture {
+func initFixture(tb testing.TB) *fixture {
     tb.Helper()
     // ...
 }

398-401: Ensure consistent use of context variables

In the populateValidators function, both f.ctx and ctx are used for context. This might lead to confusion or unintended behavior. Consider using a single context variable consistently throughout the function.

Apply this diff to use ctx consistently:

-func populateValidators(t assert.TestingT, f *fixture) {
+func populateValidators(t assert.TestingT, f *fixture, ctx context.Context) {
     // ...
-    assert.NilError(t, f.bankKeeper.MintCoins(f.ctx, minttypes.ModuleName, totalSupply))
+    assert.NilError(t, f.bankKeeper.MintCoins(ctx, minttypes.ModuleName, totalSupply))
     for _, addr := range valAddresses {
-        assert.NilError(t, f.bankKeeper.SendCoinsFromModuleToAccount(f.ctx, minttypes.ModuleName, sdk.AccAddress(addr), initCoins))
+        assert.NilError(t, f.bankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, sdk.AccAddress(addr), initCoins))
     }
 }
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6a52694 and 434c66d.

📒 Files selected for processing (6)
  • tests/integration/evidence/app_config.go (0 hunks)
  • tests/integration/v2/app.go (1 hunks)
  • tests/integration/v2/distribution/module_test.go (1 hunks)
  • tests/integration/v2/evidence/genesis_test.go (1 hunks)
  • tests/integration/v2/evidence/infraction_test.go (15 hunks)
  • tests/integration/v2/services.go (2 hunks)
💤 Files with no reviewable changes (1)
  • tests/integration/evidence/app_config.go
✅ Files skipped from review due to trivial changes (2)
  • tests/integration/v2/distribution/module_test.go
  • tests/integration/v2/app.go
🧰 Additional context used
📓 Path-based instructions (3)
tests/integration/v2/services.go (2)

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


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/v2/evidence/genesis_test.go (3)

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


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/v2/evidence/infraction_test.go (3)

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


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

🔇 Additional comments (20)
tests/integration/v2/evidence/infraction_test.go (11)

1-1: Package name change is appropriate

Changing the package name from keeper_test to evidence accurately reflects the focus of the tests on the evidence module and improves clarity.


68-68: Initialization of cometInfoService is correct

The initialization of cometInfoService with &services.ContextAwareCometInfoService{} is appropriate and aligns with the updates for context management.


74-82: Struct fixture fields are correctly updated

Adding the consensusKeeper field and updating other keeper references in the fixture struct enhances the setup for the tests and ensures that all necessary keepers are accessible.


123-123: Use of ctx from fixture is consistent

Assigning ctx := f.ctx ensures that the test uses the consistent context from the fixture, maintaining proper context for the test execution.


149-151: Correct setup of validator signing info

Initializing the validator signing info with the correct height and time ensures accurate tracking of the validator's signing behavior.


170-171: Properly setting Comet info in context

Using integration.SetCometInfo to set the Comet info in the context before calling BeginBlocker is appropriate and ensures that evidence processing has the necessary information.


192-192: Updating context with new header information

Adjusting the context with integration.SetHeaderInfo to simulate the passage of time aligns with test requirements for unbonding period checks.


221-221: Initializing context with specific height and time

Setting the header info at the beginning of the test provides a consistent starting point for the test scenario.


251-253: Ensuring consensus parameters are set

Setting the consensus parameters ensures that the evidence age calculations are based on the correct configuration, which is vital for the test's validity.


273-273: Setting initial header info in context

Initializing the context with the current time is important for accurately testing validator behavior after rotation.


336-338: Creating a new context with Comet info

Assigning ctxWithCometInfo by setting the Comet info into the context is appropriate for isolating the test scenario involving evidence handling.

tests/integration/v2/evidence/genesis_test.go (5)

1-1: Package name change is appropriate

Changing the package name from evidence_test to evidence conforms to Go testing conventions and enhances the consistency of the test package structure.


22-22: Updating ctx to use context.Context

Changing the ctx field from sdk.Context to context.Context aligns with the updated context usage throughout the codebase and ensures compatibility with functions expecting context.Context.


27-30: Refactored SetupTest improves test initialization

Using initFixture in SetupTest simplifies the test setup process and ensures consistent initialization across tests.


29-30: Assigning context and keeper from fixture

Setting suite.ctx and suite.keeper from the fixture provides the necessary components for the tests, maintaining modularity and reusability.


Line range hint 58-88: Test cases are correctly structured

The test cases in TestInitGenesis and TestExportGenesis are well-defined, and the use of malleate and posttests functions enhances test clarity and reusability.

tests/integration/v2/services.go (4)

85-91: Retrieve header info without assuming mutable context

In HeaderInfoFromContext, accessing the header information without modifying the context is appropriate. Ensure that the function handles cases where the integration context may not be present.


93-95: Properly setting Comet info in context

Using context.WithValue in SetCometInfo to associate Comet info with the context is acceptable and aligns with Go's context usage guidelines.


Line range hint 119-136: Implementation of BranchService is sound

The custom BranchService correctly implements the branch.Service interface, and the methods handle context properly without unintended side effects.


Line range hint 168-175: RouterService correctly manages handlers

The RouterService provides a clear mechanism to register and invoke message handlers based on type URLs, enhancing modularity and extensibility.

tests/integration/v2/services.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.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
tests/integration/v2/services.go (1)

86-92: Add documentation for HeaderInfoFromContext

Consider adding a doc comment explaining the function's behavior, especially the empty return case when context type doesn't match.

Add this documentation:

+// HeaderInfoFromContext retrieves header information from the integration context.
+// Returns an empty header.Info if the context doesn't contain integration context.
 func HeaderInfoFromContext(ctx context.Context) header.Info {
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 434c66d and c721c5a.

📒 Files selected for processing (1)
  • tests/integration/v2/services.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
tests/integration/v2/services.go (2)

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


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"

🔇 Additional comments (3)
tests/integration/v2/services.go (3)

12-12: LGTM!

The import is correctly aliased and follows Go conventions.


94-96: LGTM!

The implementation correctly follows context best practices by using a predefined key from the core package.


77-84: ⚠️ Potential issue

Critical: Context values should be immutable

The current implementation modifies the context value directly, which violates Go's context immutability principle and could lead to race conditions.

Apply this diff to fix the issue:

func SetHeaderInfo(ctx context.Context, h header.Info) context.Context {
    iCtx, ok := ctx.Value(contextKey).(*integrationContext)
    if !ok {
        return ctx
    }
-   iCtx.header = h
-   return context.WithValue(ctx, contextKey, iCtx)
+   return context.WithValue(ctx, contextKey, &integrationContext{
+       state:    iCtx.state,
+       gasMeter: iCtx.gasMeter,
+       header:   h,
+   })
}

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

nice!

@julienrbrt julienrbrt added this pull request to the merge queue Dec 3, 2024
Merged via the queue into main with commit 0e31188 Dec 3, 2024
75 of 76 checks passed
@julienrbrt julienrbrt deleted the akhil/evidence-integration-v2 branch December 3, 2024 12:16
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.

x/evidence: server/v2 integration tests
4 participants