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: migrate e2e/genutil to systemtest #22325

Merged
merged 16 commits into from
Oct 25, 2024
Merged

Conversation

hieuvubk
Copy link
Contributor

@hieuvubk hieuvubk commented Oct 21, 2024

Description

Closes: #21871


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

  • Tests
    • Introduced new tests for the export command, validating behavior with height parameters and output file specifications.
    • Removed an outdated test file that previously covered export command functionality.
  • Chores
    • Added a constant for maximum gas limit to improve maintainability in system tests.
    • Updated module dependencies to align with the latest developments in the Cosmos SDK testing environment.

@hieuvubk hieuvubk requested a review from a team as a code owner October 21, 2024 14:23
Copy link
Contributor

coderabbitai bot commented Oct 21, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

A new test file export_test.go has been added to the systemtests package, featuring two test functions: TestExportCmd_WithHeight and TestExportCmd_WithFileFlag. These functions validate the export command's behavior concerning height parameters and file output, respectively. Additionally, a new constant MaxGas has been introduced in system.go, replacing a hardcoded maximum gas limit in the SetupChain method, enhancing maintainability.

Changes

File Path Change Summary
tests/systemtests/export_test.go Added two new test functions: TestExportCmd_WithHeight and TestExportCmd_WithFileFlag.
tests/systemtests/system.go Introduced a new constant MaxGas with a value of 10_000_000 to replace a hardcoded gas limit.
tests/e2e/genutil/export_test.go Deleted file containing previous unit tests for the export command functionality in genutil.
tests/go.mod Updated module dependencies, added new dependencies, and marked some as indirect.

Possibly related PRs

Suggested labels

backport/v0.52.x

Suggested reviewers

  • alpe
  • julienrbrt
  • tac0turtle
  • testinginprod

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.

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/systemtests/export_test.go (2)

5-13: LGTM: Imports are correctly grouped, but consider removing unused import.

The imports are properly organized with standard library imports first, followed by third-party imports. However, the assert package is imported but not used directly in the code.

Consider removing the unused import:

-	"github.com/stretchr/testify/assert"

39-67: LGTM: Test execution and assertions are comprehensive.

The test execution logic is well-structured, covering both error and success cases. The use of a custom assertion function for error cases is a good practice. The verification of exported state, including consensus parameters, is thorough.

Consider adding a comment to explain the MaxGas constant, as it's not defined in this file:

// MaxGas is defined in system.go and represents the maximum gas limit for transactions
require.Equal(t, maxGas, int64(MaxGas))
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 681366e and 5b8f187.

📒 Files selected for processing (2)
  • tests/systemtests/export_test.go (1 hunks)
  • tests/systemtests/system.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
tests/systemtests/export_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/systemtests/system.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/systemtests/export_test.go (2)

1-3: LGTM: Build tag and package declaration are correct.

The build tag //go:build system_test is properly formatted and appropriate for system tests. The package name systemtests follows Go naming conventions.


15-37: LGTM: Test function structure and setup are well-designed.

The TestExportCmd function follows Go naming conventions for tests. The setup, including chain reset and CLI wrapper initialization, is appropriate for system tests. The test cases are well-structured and cover various scenarios for the export command, including error cases and different export options.

tests/systemtests/system.go (1)

38-39: New constant MaxGas introduced

The addition of the MaxGas constant with a value of 10,000,000 is a good practice for centralizing the definition of the maximum gas limit. This enhances maintainability by providing a single point of control for this value.

Comment on lines +135 to 138
genesisBz, err = sjson.SetRawBytes(genesisBz, "consensus.params.block.max_gas", []byte(fmt.Sprintf(`"%d"`, MaxGas)))
if err != nil {
panic(fmt.Sprintf("failed to set block max gas: %s", err))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Inconsistent Usage of Gas Limits Detected

Several hardcoded gas limits found alongside MaxGas usage may lead to inconsistencies.

  • x/simulation/simulate.go:40-45
  • types/tx/types.go:18-19,61-64
  • server/v2/cometbft/abci_test.go:37,335,374,638
  • baseapp/abci_utils.go:262,415
🔗 Analysis chain

Usage of MaxGas constant in SetupChain method

The MaxGas constant is now used to set the maximum gas limit in the genesis block configuration. This change improves code consistency and makes it easier to modify the gas limit across the system if needed.

However, to ensure this change doesn't have unintended consequences, we should verify its usage across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other occurrences of hardcoded gas limits that might need updating

# Search for potential hardcoded gas limits
rg -n '(?i)gas.*limit.*=.*\d{7,}' --type go

# Search for other uses of MaxGas to ensure consistent usage
rg -n 'MaxGas' --type go

Length of output: 5558

@hieuvubk hieuvubk marked this pull request as draft October 21, 2024 14:32
@hieuvubk hieuvubk marked this pull request as ready for review October 22, 2024 10:10
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/systemtests/export_test.go (2)

15-44: LGTM: Well-structured test function with comprehensive scenarios.

The TestExportCmd_WithHeight function uses table-driven tests to cover various export scenarios effectively. It checks both the initial height and consensus parameters, which is thorough.

Consider adding a test case for an invalid height value to ensure proper error handling.


46-77: LGTM: Comprehensive test function for file export scenarios.

The TestExportCmd_WithFileFlag function effectively tests both error and success cases for file export. The cleanup of the export file is a good practice.

Consider adding a test case for exporting to a file in a non-existent directory to ensure proper error handling in such scenarios.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5b8f187 and c0dc7b3.

📒 Files selected for processing (3)
  • tests/e2e/genutil/export_test.go (0 hunks)
  • tests/go.mod (1 hunks)
  • tests/systemtests/export_test.go (1 hunks)
💤 Files with no reviewable changes (1)
  • tests/e2e/genutil/export_test.go
🧰 Additional context used
📓 Path-based instructions (2)
tests/go.mod (1)

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

tests/systemtests/export_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 (6)
tests/systemtests/export_test.go (3)

1-13: LGTM: File header and imports are appropriate.

The build tag, package name, and imports are well-structured and relevant for system tests.


1-77: LGTM: Comprehensive test coverage for the export command.

The test file provides thorough coverage of the export command functionality, including various scenarios and error cases. The structure is consistent and follows good Go testing practices.

This test file successfully contributes to the PR objective of migrating e2e tests to the systemtest framework.


1-77: LGTM: Code conforms to the Uber Golang style guide.

The code follows good Go practices, uses descriptive names, and maintains consistent formatting. No obvious style violations were found.

tests/go.mod (3)

Line range hint 36-39: New dependencies added for testing and module support

Several new dependencies have been added, including cosmossdk.io/core/testing, cosmossdk.io/x/accounts, and cosmossdk.io/x/gov. These additions align with the PR objective of migrating e2e tests to the systemtest framework and potentially introduce new testing capabilities or features.

Please ensure that:

  1. These new dependencies are necessary for the test migration.
  2. They are compatible with the existing codebase.
  3. Any new features or capabilities introduced by these dependencies are properly utilized in the migrated tests.

Line range hint 265-293: Updated replace directives for local module testing

The replace directives have been updated to use local versions of various SDK modules. This change ensures that the testing environment uses the most up-to-date versions of these modules, which is crucial for maintaining consistency across interdependent modules during development.

This approach is beneficial for:

  1. Testing the latest changes in the SDK and related modules.
  2. Ensuring compatibility between different parts of the Cosmos SDK ecosystem.
  3. Facilitating easier debugging and development of interdependent modules.

However, please ensure that:

  1. All referenced local paths are correct and exist in the repository.
  2. This setup doesn't unintentionally introduce any version conflicts or compatibility issues.
  3. The CI/CD pipeline is configured to handle these local replacements correctly.

Line range hint 1-293: Overall assessment of go.mod changes

The changes in this go.mod file primarily focus on updating dependencies and configuring the testing environment to use local versions of SDK modules. These modifications align well with the PR objective of migrating e2e tests to the systemtest framework.

Key points:

  1. New testing-related dependencies have been added, supporting the test migration effort.
  2. Some existing dependencies have been updated or marked as indirect, potentially optimizing the dependency tree.
  3. Replace directives have been extensively updated to use local module versions, ensuring tests run against the latest SDK changes.

These changes collectively contribute to a more robust and up-to-date testing environment. However, it's crucial to ensure that these updates don't introduce any unintended side effects or compatibility issues in the broader project context.

@@ -22,7 +22,7 @@ require (
// this version is not used as it is always replaced by the latest Cosmos SDK version
github.com/cosmos/cosmos-sdk v0.53.0
github.com/cosmos/gogoproto v1.7.0
github.com/spf13/cobra v1.8.1
github.com/spf13/cobra v1.8.1 // indirect
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Direct usage of github.com/spf13/cobra detected

The github.com/spf13/cobra dependency is still directly used in the codebase. Please review the dependency status to ensure it is correctly marked as indirect.

🔗 Analysis chain

Verify the indirect status of github.com/spf13/cobra

The github.com/spf13/cobra dependency is now marked as indirect. This suggests that it's no longer directly used in the code but is still required by other dependencies. Please verify that this change is intentional and doesn't affect any functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for direct usage of cobra in the codebase
rg -i 'cobra\.' --type go

Length of output: 55686

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Oct 22, 2024
@hieuvubk hieuvubk marked this pull request as draft October 22, 2024 18:06
@hieuvubk hieuvubk marked this pull request as ready for review October 24, 2024 13:14
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/systemtests/export_test.go (2)

27-35: Add documentation for test cases

Consider adding comments explaining each test case's purpose and expected behavior for better maintainability.

Example:

 testCases := []struct {
     name          string
     args          []string
     expZeroHeight bool
 }{
+    // Tests basic export without height parameter - should export at latest height
     {"should export correct height", []string{"genesis", "export", "--home", sut.nodePath(0)}, false},
+    // Tests export with specific height parameter
     {"should export correct height with --height", []string{"genesis", "export", "--height=5", "--home", sut.nodePath(0), "--log_level=disabled"}, false},
+    // Tests export with zero height flag - should reset all heights to 0
     {"should export height 0 with --for-zero-height", []string{"genesis", "export", "--for-zero-height=true", "--home", sut.nodePath(0)}, true},
 }

55-55: Use constants for test file paths and error messages

Consider extracting the file path and error messages into constants at the package level for better maintainability and reusability.

Example:

+const (
+    testExportFileName = "foobar.json"
+    errNoSuchFile     = "no such file or directory"
+)
+
-exportFile := "foobar.json"
+exportFile := testExportFileName

 testCases := []struct {
     name   string
     args   []string
     expErr bool
     errMsg string
 }{
-    {"invalid home dir", []string{"genesis", "export", "--home=foo"}, true, "no such file or directory"},
+    {"invalid home dir", []string{"genesis", "export", "--home=foo"}, true, errNoSuchFile},

Also applies to: 70-71

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c0dc7b3 and ca0e086.

📒 Files selected for processing (2)
  • tests/go.mod (1 hunks)
  • tests/systemtests/export_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/go.mod
🧰 Additional context used
📓 Path-based instructions (1)
tests/systemtests/export_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 (2)
tests/systemtests/export_test.go (2)

1-14: LGTM: File structure and imports are well-organized

The build tags, package name, and imports are properly structured following Go conventions.


16-88: 🛠️ Refactor suggestion

Consider adding more edge cases to improve test coverage

While the current test coverage is good, consider adding these test cases:

  1. Export with invalid height parameter
  2. Export with height greater than chain height
  3. Export with malformed output file path
  4. Concurrent export attempts to the same file

Let's check if these cases are covered elsewhere:

Comment on lines +22 to +23
// Wait 10s for producing blocks
time.Sleep(10 * time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Replace hard-coded sleep with deterministic block height check

Using time.Sleep for block production can lead to flaky tests. Consider implementing a polling mechanism that checks for the desired block height.

Example implementation:

-// Wait 10s for producing blocks
-time.Sleep(10 * time.Second)
+// Wait for chain to produce some blocks
+require.Eventually(t, func() bool {
+    height, err := sut.QueryCurrentHeight()
+    return err == nil && height >= 5
+}, 30*time.Second, 100*time.Millisecond)

Committable suggestion was skipped due to low confidence.

Copy link
Contributor

@akhilkumarpilli akhilkumarpilli left a comment

Choose a reason for hiding this comment

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

lgtm!

@julienrbrt julienrbrt added this pull request to the merge queue Oct 25, 2024
Merged via the queue into main with commit aa4614e Oct 25, 2024
74 of 75 checks passed
@julienrbrt julienrbrt deleted the hieu/systemtest/genutil branch October 25, 2024 07:59
mergify bot pushed a commit that referenced this pull request Oct 25, 2024
(cherry picked from commit aa4614e)

# Conflicts:
#	tests/go.mod
alpe added a commit that referenced this pull request Oct 25, 2024
* main: (157 commits)
  feat(core): add ConfigMap type (#22361)
  test: migrate e2e/genutil to systemtest (#22325)
  feat(accounts): re-introduce bundler (#21562)
  feat(log): add slog-backed Logger type (#22347)
  fix(x/tx): add feePayer as signer (#22311)
  test: migrate e2e/baseapp to integration tests (#22357)
  test: add x/circuit system tests (#22331)
  test: migrate e2e/tx tests to systemtest (#22152)
  refactor(simdv2): allow non-comet server components (#22351)
  build(deps): Bump rtCamp/action-slack-notify from 2.3.1 to 2.3.2 (#22352)
  fix(server/v2): respect context cancellation in start command (#22346)
  chore(simdv2): allow overriding the --home flag (#22348)
  feat(server/v2): add SimulateWithState to AppManager (#22335)
  docs(x/accounts): improve comments (#22339)
  chore: remove unused local variables (#22340)
  test: x/accounts systemtests (#22320)
  chore(client): use command's configured output (#22334)
  perf(log): use sonic json lib  (#22233)
  build(deps): bump x/tx (#22327)
  fix(x/accounts/lockup): fix proto path (#22319)
  ...
julienrbrt added a commit that referenced this pull request Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tests/e2e/genutil to system tests
3 participants