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/group to system tests #22278

Merged
merged 3 commits into from
Oct 16, 2024
Merged

Conversation

akhilkumarpilli
Copy link
Contributor

@akhilkumarpilli akhilkumarpilli commented Oct 16, 2024

Description

Closes: #22219


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 new set of system tests for group commands, enhancing the testing of group creation, policies, and proposal functionalities within the blockchain application.
  • Bug Fixes

    • Removed outdated end-to-end test files that were no longer necessary, streamlining the testing process.

@akhilkumarpilli akhilkumarpilli marked this pull request as ready for review October 16, 2024 11:22
@akhilkumarpilli akhilkumarpilli requested a review from a team as a code owner October 16, 2024 11:22
Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

📝 Walkthrough

Walkthrough

This pull request involves the removal of end-to-end (E2E) tests for the group package located in tests/e2e/group/cli_test.go and tests/e2e/group/suite.go. In their place, a new system test file tests/systemtests/group_test.go has been created, which tests group commands within a blockchain application. The new tests validate functionalities such as group creation, policy association, proposal creation, and voting outcomes.

Changes

File(s) Change Summary
tests/e2e/group/cli_test.go, .../suite.go Deleted E2E test files including test functions and struct definitions for the group package.
tests/systemtests/group_test.go Added a new system test file that tests group commands and functionalities in a blockchain context.

Assessment against linked issues

Objective Addressed Explanation
Migrate E2E tests to system tests and verify them (22219)
Delete the old E2E test files

Possibly related PRs

Suggested labels

C:CLI, backport/v0.52.x

Suggested reviewers

  • alpe
  • julienrbrt
  • hieuvubk
  • tac0turtle

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

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

59-59: Extract hardcoded 'voting_period' values into a constant.

The voting_period is hardcoded as "30000s" in multiple places. Defining it as a constant will improve maintainability and make updates easier if the value changes in the future.

Apply this diff to define a constant and use it:

+	const votingPeriod = "30000s"
	
	// Inside the loop at line 59
-	policyFile := StoreTempFile(t, []byte(fmt.Sprintf(`{"@type":"/cosmos.group.v1.ThresholdDecisionPolicy", "threshold":"%d", "windows":{"voting_period":"30000s"}}`, threshold)))
+	policyFile := StoreTempFile(t, []byte(fmt.Sprintf(`{"@type":"/cosmos.group.v1.ThresholdDecisionPolicy", "threshold":"%d", "windows":{"voting_period":"%s"}}`, threshold, votingPeriod)))
	
	// At line 83 for the percentage policy
-	policyFile := StoreTempFile(t, []byte(fmt.Sprintf(`{"@type":"%s", "percentage":"%f", "windows":{"voting_period":"30000s"}}`, percentagePolicyType, 0.5)))
+	policyFile := StoreTempFile(t, []byte(fmt.Sprintf(`{"@type":"%s", "percentage":"%f", "windows":{"voting_period":"%s"}}`, percentagePolicyType, 0.5, votingPeriod)))

Also applies to: 83-83


48-120: Consider renaming 'rsp' to 'response' for clarity.

The variable rsp is used throughout the test to store command responses. Renaming rsp to response will enhance readability and align with the Uber Go Style Guide, which recommends using descriptive variable names.

Apply this diff to rename the variable:

-	rsp := cli.RunAndWait(createGroupCmd...)
+	response := cli.RunAndWait(createGroupCmd...)

Update subsequent references to rsp accordingly.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ee3d320 and dd0f10f.

📒 Files selected for processing (3)
  • tests/e2e/group/cli_test.go (0 hunks)
  • tests/e2e/group/suite.go (0 hunks)
  • tests/systemtests/group_test.go (1 hunks)
💤 Files with no reviewable changes (2)
  • tests/e2e/group/cli_test.go
  • tests/e2e/group/suite.go
🧰 Additional context used
📓 Path-based instructions (1)
tests/systemtests/group_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/group_test.go (1)

74-74: ⚠️ Potential issue

Verify the correctness of 'pagination.total' comparison with 'threshold'.

In the assertion require.Equal(t, gjson.Get(groupPoliciesResp, "pagination.total").Int(), int64(threshold)), you're comparing pagination.total to threshold. Ensure that pagination.total represents the total number of group policies at the current state and that it aligns with the expected threshold value in each iteration. If pagination.total is cumulative across iterations, this comparison may not behave as intended.

Run the following script to verify the cumulative value of pagination.total:

Comment on lines +17 to +131
baseurl := sut.APIAddress()

// test create group
memberWeight := "5"
validMembers := fmt.Sprintf(`
{
"members": [
{
"address": "%s",
"weight": "%s",
"metadata": "%s"
}
]
}`, valAddr, memberWeight, validMetadata)
validMembersFile := StoreTempFile(t, []byte(validMembers))
createGroupCmd := []string{"tx", "group", "create-group", valAddr, validMetadata, validMembersFile.Name(), "--from=" + valAddr}
rsp := cli.RunAndWait(createGroupCmd...)
RequireTxSuccess(t, rsp)

// query groups by admin to confirm group creation
rsp = cli.CustomQuery("q", "group", "groups-by-admin", valAddr)
require.Len(t, gjson.Get(rsp, "groups").Array(), 1)
groupId := gjson.Get(rsp, "groups.0.id").String()

// test create group policies
for i := 0; i < 5; i++ {
threshold := i + 1
policyFile := StoreTempFile(t, []byte(fmt.Sprintf(`{"@type":"/cosmos.group.v1.ThresholdDecisionPolicy", "threshold":"%d", "windows":{"voting_period":"30000s"}}`, threshold)))
policyCmd := []string{"tx", "group", "create-group-policy", valAddr, groupId, validMetadata, policyFile.Name(), "--from=" + valAddr}
rsp = cli.RunAndWait(policyCmd...)
RequireTxSuccess(t, rsp)

// TODO: remove isV2() check once v2 is integrated with grpc gateway
var groupPoliciesResp, policyAddrQuery string
if isV2() {
groupPoliciesResp = cli.CustomQuery("q", "group", "group-policies-by-group", groupId)
policyAddrQuery = fmt.Sprintf("group_policies.#(decision_policy.value.threshold==%d).address", threshold)
} else {
groupPoliciesResp = string(GetRequest(t, fmt.Sprintf("%s/cosmos/group/v1/group_policies_by_group/%s", baseurl, groupId)))
policyAddrQuery = fmt.Sprintf("group_policies.#(decision_policy.threshold==%d).address", threshold)
}
require.Equal(t, gjson.Get(groupPoliciesResp, "pagination.total").Int(), int64(threshold))
policyAddr := gjson.Get(groupPoliciesResp, policyAddrQuery).String()
require.NotEmpty(t, policyAddr)

rsp = cli.RunCommandWithArgs(cli.withTXFlags("tx", "bank", "send", valAddr, policyAddr, "1000stake", "--generate-only")...)
require.Equal(t, policyAddr, gjson.Get(rsp, "body.messages.0.to_address").String())
}

// test create group policy with percentage decision policy
percentagePolicyType := "/cosmos.group.v1.PercentageDecisionPolicy"
policyFile := StoreTempFile(t, []byte(fmt.Sprintf(`{"@type":"%s", "percentage":"%f", "windows":{"voting_period":"30000s"}}`, percentagePolicyType, 0.5)))
policyCmd := []string{"tx", "group", "create-group-policy", valAddr, groupId, validMetadata, policyFile.Name(), "--from=" + valAddr}
rsp = cli.RunAndWait(policyCmd...)
RequireTxSuccess(t, rsp)

groupPoliciesResp := cli.CustomQuery("q", "group", "group-policies-by-admin", valAddr)
require.Equal(t, gjson.Get(groupPoliciesResp, "pagination.total").Int(), int64(6))
policyAddr := gjson.Get(groupPoliciesResp, fmt.Sprintf("group_policies.#(decision_policy.type==%s).address", percentagePolicyType)).String()
require.NotEmpty(t, policyAddr)

// test create proposal
proposalJSON := fmt.Sprintf(`{
"group_policy_address": "%s",
"messages":[
{
"@type": "/cosmos.bank.v1beta1.MsgSend",
"from_address": "%s",
"to_address": "%s",
"amount": [{"denom": "stake","amount": "100"}]
}
],
"metadata": "%s",
"title": "My Proposal",
"summary": "Summary",
"proposers": ["%s"]
}`, policyAddr, policyAddr, valAddr, validMetadata, valAddr)
proposalFile := StoreTempFile(t, []byte(proposalJSON))
rsp = cli.RunAndWait("tx", "group", "submit-proposal", proposalFile.Name())
RequireTxSuccess(t, rsp)

// query proposals
rsp = cli.CustomQuery("q", "group", "proposals-by-group-policy", policyAddr)
require.Len(t, gjson.Get(rsp, "proposals").Array(), 1)
proposalId := gjson.Get(rsp, "proposals.0.id").String()

// test vote proposal
rsp = cli.RunAndWait("tx", "group", "vote", proposalId, valAddr, "yes", validMetadata)
RequireTxSuccess(t, rsp)

// query votes
// TODO: remove isV2() check once v2 is integrated with grpc gateway
var voteResp string
if isV2() {
voteResp = cli.CustomQuery("q", "group", "vote", proposalId, valAddr)
} else {
voteResp = string(GetRequest(t, fmt.Sprintf("%s/cosmos/group/v1/vote_by_proposal_voter/%s/%s", baseurl, proposalId, valAddr)))
}
require.Equal(t, "VOTE_OPTION_YES", gjson.Get(voteResp, "vote.option").String())
}
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

Consider splitting 'TestGroupCommands' into smaller, focused test functions.

The TestGroupCommands function is quite extensive and covers multiple scenarios including group creation, policy creation, proposal submission, and voting. According to the Uber Go Style Guide, it's recommended to keep functions small and focused on a single responsibility. Splitting this function into smaller test functions will improve readability, make maintenance easier, and help isolate test failures.


🛠️ Refactor suggestion

Enhance test coverage by adding error scenarios and edge cases.

The current tests cover the standard workflow for group commands. To ensure robustness, consider adding test cases for error scenarios such as:

  • Attempting to create a group with invalid members.
  • Submitting a proposal with invalid messages.
  • Voting with an unauthorized address.
  • Edge cases like zero thresholds or percentages outside the valid range.

Including these cases will improve test coverage and help catch potential issues early.

tests/systemtests/group_test.go Show resolved Hide resolved
tests/systemtests/group_test.go Show resolved Hide resolved
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 this pull request to the merge queue Oct 16, 2024
@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Oct 16, 2024
Merged via the queue into main with commit 553e110 Oct 16, 2024
79 of 80 checks passed
@julienrbrt julienrbrt deleted the akhil/group-system-tests branch October 16, 2024 20:14
mergify bot pushed a commit that referenced this pull request Oct 16, 2024
julienrbrt pushed a commit that referenced this pull request Oct 17, 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/group to system tests
4 participants