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/auth to system tests and fix sign-batch #22149

Merged
merged 16 commits into from
Oct 11, 2024

Conversation

akhilkumarpilli
Copy link
Contributor

@akhilkumarpilli akhilkumarpilli commented Oct 7, 2024

Description

Closes: #21926


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 authentication-related transaction commands.
    • Enhanced handling of multisig transactions in the command execution process.
  • Bug Fixes

    • Adjusted output handling in the distribution tests for improved clarity.
  • Chores

    • Cleaned up unused imports and functions in the system tests for better maintainability.

Copy link
Contributor

coderabbitai bot commented Oct 7, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request involves the deletion of end-to-end (E2E) tests for the auth package and the introduction of new system tests that cover authentication-related transaction commands. The deleted files included a test suite that validated various CLI commands, while the new files provide comprehensive coverage for signing, broadcasting, and querying transactions in a blockchain environment. Additionally, modifications were made to the logic for handling multisig transactions in the CLI command files.

Changes

File(s) Change Summary
tests/e2e/auth/cli_test.go, tests/e2e/auth/suite.go Deleted files containing E2E test suite and related methods for CLI command testing.
tests/systemtests/auth_test.go Introduced new system test suite for authentication commands with multiple test functions.
tests/systemtests/cli.go Removed unused imports and the filterProtoNoise function.
tests/systemtests/distribution_test.go Adjusted output handling logic in TestWithdrawAllRewardsCmd function.
x/auth/client/cli/tx_sign.go Modified logic for multisig transactions in GetSignBatchCommand and GetSignCommand functions.

Assessment against linked issues

Objective Addressed Explanation
Migrate E2E tests to system tests and delete old ones (#21926)

Possibly related PRs

Suggested labels

C:x/accounts, Type: CI

Suggested reviewers

  • alpe
  • julienrbrt
  • 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.

@akhilkumarpilli akhilkumarpilli changed the title test: migrate e2e/auth to system tests [WIP] test: migrate e2e/auth to system tests Oct 7, 2024
@akhilkumarpilli akhilkumarpilli changed the title [WIP] test: migrate e2e/auth to system tests test: migrate e2e/auth to system tests and fix sign-batch Oct 10, 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 (1)
client/account_retriever.go (1)

16-18: Consider using a more descriptive field name

The mockAccount struct is well-defined, but the field name addr could be more descriptive. Consider renaming it to address for better clarity.

 type mockAccount struct {
-	addr []byte
+	address []byte
 }
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a9f74cd and 6d04bb7.

📒 Files selected for processing (1)
  • client/account_retriever.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
client/account_retriever.go (1)

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

🔇 Additional comments (3)
client/account_retriever.go (3)

20-22: LGTM: GetAddress method implementation

The GetAddress method is correctly implemented, returning the address field as required by the Account interface.


55-56: LGTM: Updated GetAccount method

The GetAccount method has been correctly updated to return a mockAccount instance initialized with the provided address. This change enhances the mock implementation, allowing for more realistic testing scenarios.


Line range hint 1-70: Summary of changes and their impact

The introduction of the mockAccount struct and the update to the MockAccountRetriever.GetAccount method enhance the mocking capabilities of the AccountRetriever interface. These changes allow for more realistic testing scenarios by providing a concrete mock implementation instead of returning nil.

The changes are well-contained and don't introduce any inconsistencies in the existing code. The MockAccountRetriever continues to correctly implement the AccountRetriever interface.

Overall, these changes improve the testability of code that depends on the AccountRetriever interface.

Comment on lines +24 to +34
func (m mockAccount) GetPubKey() cryptotypes.PubKey {
return nil
}

func (m mockAccount) GetAccountNumber() uint64 {
return 0
}

func (m mockAccount) GetSequence() uint64 {
return 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

Consider making mock values configurable

The implementation of GetPubKey, GetAccountNumber, and GetSequence methods is correct for a basic mock. However, to enhance flexibility in testing scenarios, consider making these values configurable. This would allow tests to set specific values when needed.

Here's a suggested implementation:

type mockAccount struct {
	address []byte
	pubKey  cryptotypes.PubKey
	accNum  uint64
	seq     uint64
}

func (m mockAccount) GetPubKey() cryptotypes.PubKey {
	return m.pubKey
}

func (m mockAccount) GetAccountNumber() uint64 {
	return m.accNum
}

func (m mockAccount) GetSequence() uint64 {
	return m.seq
}

This change would require updating the MockAccountRetriever.GetAccount method to initialize these fields.

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

🧹 Outside diff range and nitpick comments (3)
tests/systemtests/auth_test.go (3)

70-75: Reminder: Address the TODO about multi-message support in v2

There's a TODO comment indicating that the code block should be removed once version 2 supports multiple messages. To maintain code cleanliness and prevent outdated code from persisting, please ensure that this TODO is tracked and addressed when v2 supports multi-message transactions.

Would you like me to open a GitHub issue to track this task and ensure it's revisited in the future?


96-112: Enhance test coverage with additional cases

The test cases in testSignTxBroadcast cover primary scenarios. To ensure robust testing, consider adding edge cases such as invalid account numbers, incorrect sequences, missing signatures, and unsupported sign modes. This will help catch potential issues and improve the reliability of the transaction signing process.


495-505: Ensure proper cleanup of temporary files

In the TestTxEncodeandDecode function, temporary files are created to store transaction data. Consider cleaning up these files after the test completes to prevent resource leaks and maintain a clean testing environment.

You can defer the removal of the temporary file:

 txFile := StoreTempFile(t, []byte(sendTx))
+defer os.Remove(txFile.Name())
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6d04bb7 and 18dc0cb.

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

Comment on lines +227 to +234
for _, tc := range txsTestCases {
t.Run(tc.name, func(t *testing.T) {
cmd := []string{"q", "txs", tc.query}
rsp = cli.CustomQuery(cmd...)
txs := gjson.Get(rsp, "txs").Array()
require.Equal(t, tc.expLen, len(txs))
})
}
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

Fix variable capture in for-loop when using t.Run

In the loop starting at line 227, the variable tc is captured by reference within the closure passed to t.Run. This can lead to subtests using the last value of tc rather than the intended one, causing flaky or incorrect test results. To fix this, capture tc at each iteration by re-declaring it inside the loop.

Apply the following fix:

 for _, tc := range txsTestCases {
+    tc := tc // capture loop variable
     t.Run(tc.name, func(t *testing.T) {
         // test code
     })
 }
📝 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
for _, tc := range txsTestCases {
t.Run(tc.name, func(t *testing.T) {
cmd := []string{"q", "txs", tc.query}
rsp = cli.CustomQuery(cmd...)
txs := gjson.Get(rsp, "txs").Array()
require.Equal(t, tc.expLen, len(txs))
})
}
for _, tc := range txsTestCases {
tc := tc // capture loop variable
t.Run(tc.name, func(t *testing.T) {
cmd := []string{"q", "txs", tc.query}
rsp = cli.CustomQuery(cmd...)
txs := gjson.Get(rsp, "txs").Array()
require.Equal(t, tc.expLen, len(txs))
})
}

Comment on lines 473 to 480
assertTxOutput := func(_ assert.TestingT, gotErr error, gotOutputs ...interface{}) bool {
require.Len(t, gotOutputs, 1)
output := gotOutputs[0].(string)
if tc.expErrMsg != "" {
require.Contains(t, output, tc.expErrMsg)
}
return 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

Consider handling the return value from assertTxOutput

In the TestAuxSigner function, the custom error matcher assertTxOutput returns a boolean value indicating the success of the assertion. Currently, the return value is being ignored. To improve test reliability and clarity, consider checking the return value or using assert.NoError if appropriate.

Modify the code to handle the return value:

 _ = cli.WithRunErrorMatcher(assertTxOutput).Run(cli.withTXFlags(cmd...)...)
+// Optionally, you can check the return value to assert test success
+success := cli.WithRunErrorMatcher(assertTxOutput).Run(cli.withTXFlags(cmd...)...)
+require.True(t, success)

Committable suggestion was skipped due to low confidence.

@julienrbrt julienrbrt added this pull request to the merge queue Oct 11, 2024
Merged via the queue into main with commit 4733fc1 Oct 11, 2024
72 of 73 checks passed
@julienrbrt julienrbrt deleted the akhil/auth-system-tests branch October 11, 2024 12:17
mergify bot pushed a commit that referenced this pull request Oct 11, 2024
julienrbrt pushed 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 C:CLI C:x/auth
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tests/e2e/auth to system tests
9 participants