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(systemtest): Fix prune & gov test #22190

Merged
merged 3 commits into from
Oct 9, 2024
Merged

Conversation

hieuvubk
Copy link
Contributor

@hieuvubk hieuvubk commented Oct 9, 2024

Description

Closes: #XXXX

Update flag keep-recent => store.keep-recent for appv2. Will fix main & v0.52

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

  • Bug Fixes

    • Updated the command used for the pruning operation to ensure it correctly reflects the new argument format, enhancing the reliability of the pruning feature.
  • Tests

    • Added a new test case for querying deposits after a proposal submission to verify behavior before and after the voting period.
    • Introduced a new function to set the expedited voting period in the genesis state, improving governance proposal testing.
    • Simplified the genesis configuration by removing unnecessary voting period settings, streamlining the test environment setup.

@hieuvubk hieuvubk requested a review from a team as a code owner October 9, 2024 12:04
Copy link
Contributor

coderabbitai bot commented Oct 9, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request enhance the testing of governance proposals in the tests/systemtests/gov_test.go file by adding a new test case for querying deposits after a proposal is submitted. The TestQueryDeposit function has been updated to include logic for a short voting period of 8 seconds. Additionally, the TestPrune function in tests/systemtests/snapshots_test.go has been modified to change the command format for pruning operations. Lastly, the SystemUnderTest struct in tests/systemtests/system.go has had the section for setting the voting period removed, streamlining the genesis configuration.

Changes

File Path Change Summary
tests/systemtests/gov_test.go Added a new test case in TestQueryDeposit for querying deposits after a proposal submission with an 8-second voting period.
tests/systemtests/snapshots_test.go Updated command in TestPrune function from []string{"store", "prune", "--keep-recent=1"} to []string{"store", "prune", "--store.keep-recent=1"}.
tests/systemtests/system.go Removed section that sets the voting period for governance in the genesis block configuration.
tests/systemtests/genesis_io.go Introduced SetGovExpeditedVotingPeriod function to modify the expedited voting period in the genesis state.

Possibly related PRs

  • test(gov): Migrate e2e to system test #21927: This PR introduces a comprehensive suite of system tests for the governance module, including the TestQueryDeposit function, which is directly related to the changes made in the main PR that also modifies the TestQueryDeposit function.
  • test(systemtests): fix failing tests #22145: This PR addresses issues related to failing system tests, which may include tests in the governance module, thus potentially impacting the tests introduced in the main PR.

Suggested labels

C:x/gov, C:Store

Suggested reviewers

  • alpe
  • julienrbrt
  • tac0turtle
  • akhilkumarpilli

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.

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Oct 9, 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: 0

🧹 Outside diff range and nitpick comments (1)
tests/systemtests/snapshots_test.go (1)

92-92: LGTM! Consider adding a comment for clarity.

The update to use --store.keep-recent=1 for app version 2 is correct and aligns with the PR objectives. This change maintains the test's functionality while adapting to the new command structure.

Consider adding a brief comment explaining the difference in command structure between v1 and v2, for better maintainability:

if isV2() {
    // App v2 uses a nested flag structure for store commands
    command = []string{"store", "prune", "--store.keep-recent=1"}
} else {
    // App v1 uses a simpler command structure
    command = []string{"prune", "everything"}
}
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3220aab and 7cc6b64.

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

@julienrbrt
Copy link
Member

Could you fix the other issue maybe too? @hieuvubk :)

@hieuvubk hieuvubk disabled auto-merge October 9, 2024 14:44
genesisBz, err = sjson.SetRawBytes(genesisBz, "app_state.gov.params.voting_period", []byte(fmt.Sprintf(`"%s"`, "8s")))
if err != nil {
panic(fmt.Sprintf("failed to set regular voting period: %s", err))
}
// update expedited voting period to avoid validation error
genesisBz, err = sjson.SetRawBytes(genesisBz, "app_state.gov.params.expedited_voting_period", []byte(fmt.Sprintf(`"%s"`, "7s")))
Copy link
Contributor

Choose a reason for hiding this comment

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

@hieuvubk Can you move this too to gov_test.go? This was added due to voting_period change earlier.

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

378-379: LGTM! Consider adding a constant for the voting period.

The addition of a short voting period enhances the test efficiency. It allows for faster execution while still covering the full lifecycle of a proposal's deposits.

Consider defining a constant for the voting period (8 seconds) at the package level for better maintainability:

const testVotingPeriod = 8 * time.Second

// Then use it in the test:
sut.ModifyGenesisJSON(t, SetGovVotingPeriod(t, testVotingPeriod))

Line range hint 380-424: LGTM! Consider adding comments for test stages.

The test comprehensively covers the deposit lifecycle, including initial deposit verification and post-voting period clearing. The use of gjson for parsing JSON responses is consistent with other tests in the file.

To improve readability, consider adding comments to clearly delineate the stages of the test:

// Submit a new proposal
proposalArgs := []string{
    // ... (existing code)
}
// ... (existing code)

// Query initial deposit
resp := cli.CustomQuery("q", "gov", "deposit", "1", valAddr)
// ... (existing code)

// Wait for voting period to end
time.Sleep(time.Second * 8)

// Query deposits after voting period
resp = cli.CustomQuery("q", "gov", "deposits", "1")
// ... (existing code)
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7cc6b64 and 8efc28c.

📒 Files selected for processing (2)
  • tests/systemtests/gov_test.go (1 hunks)
  • tests/systemtests/system.go (0 hunks)
💤 Files with no reviewable changes (1)
  • tests/systemtests/system.go
🧰 Additional context used
📓 Path-based instructions (1)
tests/systemtests/gov_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 (1)
tests/systemtests/gov_test.go (1)

Line range hint 1-424: Overall improvements to governance testing

The changes in this file enhance the testing of the governance module, particularly in the TestQueryDeposit function. The addition of a short voting period and the verification of deposit clearing after the voting period ends contribute to more comprehensive test coverage.

These modifications align well with the PR objectives and maintain consistency with the existing code style and testing practices. The improved tests will help ensure the robustness of the governance functionality.

@julienrbrt julienrbrt changed the title test(systemtest): Fix Prune test test(systemtest): Fix prune & gov test Oct 9, 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: 0

🧹 Outside diff range and nitpick comments (2)
tests/systemtests/gov_test.go (2)

378-384: LGTM! Consider clarifying the comment.

The addition of short voting periods for testing purposes is a good approach to speed up test execution. The implementation correctly sets the expedited voting period shorter than the regular voting period.

Consider clarifying the comment on line 379 to explain why the expedited voting period needs to be updated. For example:

- // update expedited voting period to avoid validation error
+ // update expedited voting period to be shorter than the regular voting period, avoiding a validation error

Line range hint 376-431: LGTM! Consider adding a tolerance to the waiting period.

The changes to TestQueryDeposit effectively test the deposit lifecycle with a shortened voting period. The test structure is well-organized and covers important aspects of governance proposal deposits.

To improve test robustness, consider adding a small tolerance to the waiting period. Instead of a fixed sleep, you could use a loop with a timeout:

maxWaitTime := time.Second * 10
startTime := time.Now()
for {
    resp = cli.CustomQuery("q", "gov", "deposits", "1")
    deposits = gjson.Get(resp, "deposits").Array()
    if len(deposits) == 0 || time.Since(startTime) > maxWaitTime {
        break
    }
    time.Sleep(time.Millisecond * 500)
}
require.Equal(t, len(deposits), 0, "Deposits should be cleared after voting period")

This approach would make the test more resilient to potential timing issues while still maintaining a maximum execution time.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8efc28c and 96cbdc9.

📒 Files selected for processing (3)
  • tests/systemtests/genesis_io.go (1 hunks)
  • tests/systemtests/gov_test.go (1 hunks)
  • tests/systemtests/system.go (0 hunks)
💤 Files with no reviewable changes (1)
  • tests/systemtests/system.go
🧰 Additional context used
📓 Path-based instructions (2)
tests/systemtests/genesis_io.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/systemtests/gov_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 (1)
tests/systemtests/genesis_io.go (1)

36-43: LGTM! Well-structured and consistent with existing code.

The new SetGovExpeditedVotingPeriod function is well-implemented and follows good practices:

  1. It uses t.Helper() to mark it as a test helper function.
  2. Error handling is appropriate for test code with require.NoError.
  3. The function is concise and maintains consistency with the existing SetGovVotingPeriod function.
  4. It provides good test coverage for the new expedited voting period feature.

The implementation adheres to the Uber Golang style guide and test code guidelines.

@julienrbrt julienrbrt added this pull request to the merge queue Oct 9, 2024
Merged via the queue into main with commit 597e0fa Oct 9, 2024
75 of 76 checks passed
@julienrbrt julienrbrt deleted the hieu/systemtest/fix_store branch October 9, 2024 15:48
mergify bot pushed a commit that referenced this pull request Oct 9, 2024
julienrbrt added a commit that referenced this pull request Oct 11, 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.

3 participants