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(gov): Migrate e2e to system test #21927

Merged
merged 12 commits into from
Sep 30, 2024
Merged

test(gov): Migrate e2e to system test #21927

merged 12 commits into from
Sep 30, 2024

Conversation

hieuvubk
Copy link
Contributor

@hieuvubk hieuvubk commented Sep 26, 2024

Description

Closes: #21872


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

  • New Features

    • Introduced a comprehensive suite of system tests for the governance module, including proposal submission, voting, and deposit management.
    • Added tests for both valid and invalid scenarios to ensure robust functionality.
  • Chores

    • Updated the genesis block configuration to set a shorter voting period of 8 seconds for the governance module.
    • Removed outdated end-to-end test files that were redundant for the current testing strategy.

Copy link
Contributor

coderabbitai bot commented Sep 26, 2024

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces system tests for the governance module of a blockchain application, validating proposal submissions, voting mechanisms, and deposit management. It modifies the genesis block configuration to set a short voting period. Additionally, it removes existing end-to-end tests related to governance, consolidating the testing framework to focus on system tests.

Changes

Files Change Summary
tests/systemtests/gov_test.go Added system tests for governance module: TestSubmitProposal, TestSubmitLegacyProposal, TestNewCmdWeightedVote, and TestQueryDeposit.
tests/systemtests/system.go Modified the SetupChain method to set the voting_period parameter in the genesis block configuration to "8s".
tests/e2e/gov/cli_test.go Removed end-to-end tests: TestE2ETestSuite and TestDepositTestSuite.
tests/e2e/gov/deposits.go Removed deposit-related end-to-end test suite, including the DepositTestSuite and its methods.
tests/e2e/gov/tx.go Removed end-to-end test suite for governance transactions, including the E2ETestSuite struct and its methods.

Assessment against linked issues

Objective Addressed Explanation
Convert test/e2e/gov to system test (#21872)

Possibly related PRs

Suggested reviewers

  • tac0turtle
  • 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.

@github-actions github-actions bot removed the C:x/gov label Sep 30, 2024
@hieuvubk hieuvubk marked this pull request as ready for review September 30, 2024 08:59
@hieuvubk hieuvubk requested a review from a team as a code owner September 30, 2024 08:59
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

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

135-139: Governance voting period set to a short duration.

The change introduces a short voting period of 8 seconds for the governance module in the genesis configuration. This aligns with the PR objective of converting e2e tests to system tests, as it allows for faster testing of governance-related functionalities.

However, there are a few points to consider:

  1. The error message in the panic is incorrect. It mentions "failed set block max gas" instead of something related to the voting period.
  2. The hard-coded duration might make the tests less flexible. Consider making this value configurable or using a constant.

Consider applying the following improvements:

  1. Fix the error message:
-		panic(fmt.Sprintf("failed set block max gas: %s", err))
+		panic(fmt.Sprintf("failed to set governance voting period: %s", err))
  1. Use a constant for the voting period:
+const defaultTestVotingPeriod = "8s"

-	genesisBz, err = sjson.SetRawBytes(genesisBz, "app_state.gov.params.voting_period", []byte(fmt.Sprintf(`"%s"`, "8s")))
+	genesisBz, err = sjson.SetRawBytes(genesisBz, "app_state.gov.params.voting_period", []byte(fmt.Sprintf(`"%s"`, defaultTestVotingPeriod)))

These changes will improve error handling and make the code more maintainable.

tests/systemtests/gov_test.go (3)

220-220: Remove unnecessary debugging fmt.Println statement.

The line fmt.Println("gotOut", gotOutputs) appears to be leftover debugging code. Removing it will clean up the test output and adhere to best practices.

Apply this diff to remove the print statement:

-	fmt.Println("gotOut", gotOutputs)

269-269: Remove unnecessary fmt.Println statement.

The fmt.Println("first proposal", proposal1) statement is unnecessary for the test's functionality and may clutter the output. Consider removing it to keep the test output clean.

Apply this diff to remove the print statement:

-	fmt.Println("first proposal", proposal1)

323-323: Clarify test case name for better readability.

The test case name "invalid valid split vote string" is confusing. Renaming it to "invalid split vote string" improves clarity and accurately reflects the test scenario.

Apply this diff to correct the test case name:

-    			"invalid valid split vote string",
+    			"invalid split vote string",
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7ce403f and e96f2b4.

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

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

327-327: ⚠️ Potential issue

Correct the invalid split vote string format.

The split vote string "yes/0.6,no/0.3,abstain/0.05,no_with_veto/0.05" uses / instead of = to separate options and weights, which is invalid. The correct format should use =. This misformatting is intentional for the test case; however, ensure that the error message accurately reflects this.

Apply this diff if the misformatting was unintentional:

-    				"yes/0.6,no/0.3,abstain/0.05,no_with_veto/0.05",
+    				"yes=0.6,no=0.3,abstain=0.05,no_with_veto=0.05",

Likely invalid or redundant comment.

Comment on lines +76 to +102
{
"invalid proposal",
[]string{
"tx", "gov", "submit-proposal",
invalidPropFile.Name(),
fmt.Sprintf("--%s=%s", flags.FlagFrom, valAddr),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(10))).String()),
},
true,
"invalid character in coin string",
},
{
"valid proposal",
[]string{
"tx", "gov", "submit-proposal",
validPropFile.Name(),
fmt.Sprintf("--%s=%s", flags.FlagFrom, valAddr),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(10))).String()),
},
false,
"",
},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance test coverage by adding more test cases.

Currently, the TestSubmitProposal function includes only one valid and one invalid proposal test case. To ensure comprehensive coverage, consider adding additional test cases, such as:

  • Proposals with missing required fields (e.g., missing description or deposit).
  • Proposals with invalid or malformed metadata.
  • Proposals with oversized deposit amounts to test boundary conditions.
  • Proposals with invalid message types or unsupported content.

Comment on lines +409 to +413
time.Sleep(time.Second * 8)
resp = cli.CustomQuery("q", "gov", "deposits", "1")
deposits = gjson.Get(resp, "deposits").Array()
require.Equal(t, len(deposits), 0)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid using time.Sleep in tests; implement a dynamic wait mechanism.

Using time.Sleep(time.Second * 8) can make tests slower and less reliable due to fixed wait times. Instead, implement a polling mechanism that periodically checks if the deposits have been cleared, up to a maximum timeout. This approach reduces test duration and improves reliability.

"deposit": "-324foocoin"
}`
invalidPropFile := testutil.WriteToNewTempFile(t, invalidProp)
os.WriteFile("test", []byte(invalidProp), 0o600)
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

Remove unnecessary file write operation to 'test'.

The call to os.WriteFile("test", []byte(invalidProp), 0o600) is unnecessary because invalidProp is already written to invalidPropFile. Additionally, writing to a hardcoded file named "test" may cause conflicts or unintended side effects. Consider removing this line to clean up the code.

Apply this diff to remove the unnecessary file write:

-	os.WriteFile("test", []byte(invalidProp), 0o600)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
os.WriteFile("test", []byte(invalidProp), 0o600)

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.

Could you delete the relevant e2e tests here as well?

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.

lgtm!

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Sep 30, 2024
@julienrbrt julienrbrt self-assigned this Sep 30, 2024
@julienrbrt julienrbrt requested a review from alpe September 30, 2024 11:19
@hieuvubk hieuvubk enabled auto-merge September 30, 2024 13:55
@hieuvubk hieuvubk disabled auto-merge September 30, 2024 14:06
@hieuvubk hieuvubk enabled auto-merge September 30, 2024 14:06
@hieuvubk hieuvubk added this pull request to the merge queue Sep 30, 2024
Merged via the queue into main with commit d493145 Sep 30, 2024
71 of 72 checks passed
@hieuvubk hieuvubk deleted the hieu/systemtest/gov branch September 30, 2024 14:35
mergify bot pushed a commit that referenced this pull request Sep 30, 2024
julienrbrt pushed a commit that referenced this pull request Oct 1, 2024
alpe added a commit that referenced this pull request Oct 1, 2024
* main:
  docs: amend docs for 52 changes  (#21992)
  test: migrate e2e/authz to system tests (#21819)
  refactor(runtime/v2): use StoreBuilder (#21989)
  feat(schema): add API descriptors, struct, oneof & list types, and wire encoding spec (#21482)
  docs: add instructions to change DefaultGenesis (#21680)
  feat(x/staking)!: Add metadata field to validator info (#21315)
  chore(x/authz)!: Remove account keeper dependency (#21632)
  chore(contributing): delete link (#21990)
  test(gov): Migrate e2e to system test (#21927)
  test: e2e/client to system tests (#21981)
@coderabbitai coderabbitai bot mentioned this pull request Nov 26, 2024
12 tasks
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/gov to system tests
4 participants