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

refactor(tests/integration): Port x/accounts integration tests to server v2 #22881

Merged
merged 4 commits into from
Dec 16, 2024

Conversation

sontrinh16
Copy link
Member

@sontrinh16 sontrinh16 commented Dec 16, 2024

Description

ref: #20799

part 1 of x/accounts integration tests, lockup and multisig tests will be in another PR


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 new integration tests for base account functionality and a fixture for testing context in the accounts module.
    • Added methods for managing account interactions and gas management within the integration testing framework.
  • Bug Fixes

    • Enhanced error handling and modularity in the test setup for account components.
  • Chores

    • Removed obsolete integration test files to streamline the testing framework.

Copy link
Contributor

coderabbitai bot commented Dec 16, 2024

📝 Walkthrough

Walkthrough

This pull request involves a comprehensive refactoring of integration tests for the Cosmos SDK accounts module. The changes include deleting old test files in the tests/integration/accounts/ directory and introducing new test files in tests/integration/v2/accounts/. The new files provide enhanced testing utilities for base accounts, including fixture setup, mock account implementations, and improved gas and context management. The modifications focus on improving the testing infrastructure for account-related functionalities, with an emphasis on modularity and flexibility.

Changes

File Change Summary
tests/integration/accounts/base_account_test.go Deleted integration test file for base account functionality
tests/integration/accounts/fixture_test.go Deleted test fixture file for account module testing
tests/integration/v2/accounts/base_account_test.go New integration test file with updated base account test implementation
tests/integration/v2/accounts/fixture_test.go New test fixture file with enhanced mock account and testing utilities
tests/integration/v2/accounts/wiring_test.go Updated to use new fixture-based testing approach
tests/integration/v2/services.go Added gas meter and context management methods

Possibly related PRs

Suggested labels

C:x/accounts, C:server/v2, backport/v0.52.x

Suggested reviewers

  • testinginprod
  • akhilkumarpilli
  • julienrbrt

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request.


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@sontrinh16 sontrinh16 marked this pull request as ready for review December 16, 2024 08:16
@sontrinh16 sontrinh16 requested a review from a team as a code owner December 16, 2024 08:16
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

🧹 Nitpick comments (2)
tests/integration/v2/accounts/fixture_test.go (1)

36-36: Remove the Extraneous Backticks in Comment

There's an extra backtick at the end of the comment in line 36.

Apply the following diff:

-	_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring``
+	_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring
tests/integration/v2/accounts/base_account_test.go (1)

81-89: Improve Error Message in toAnyPb Function

The error message "no" in t.Fatal("no") is not descriptive. Consider providing a more informative message to aid in debugging.

Apply this diff to enhance the error message:

	if gogoproto.MessageName(pm) == gogoproto.MessageName(&gogoany.Any{}) {
-		t.Fatal("no")
+		t.Fatal("cannot convert a message of type Any to protobuf Any representation")
	}
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6500a72 and 7756bf0.

📒 Files selected for processing (6)
  • tests/integration/accounts/base_account_test.go (0 hunks)
  • tests/integration/accounts/fixture_test.go (0 hunks)
  • tests/integration/v2/accounts/base_account_test.go (1 hunks)
  • tests/integration/v2/accounts/fixture_test.go (1 hunks)
  • tests/integration/v2/accounts/wiring_test.go (3 hunks)
  • tests/integration/v2/services.go (3 hunks)
💤 Files with no reviewable changes (2)
  • tests/integration/accounts/fixture_test.go
  • tests/integration/accounts/base_account_test.go
🧰 Additional context used
📓 Path-based instructions (4)
tests/integration/v2/accounts/base_account_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/integration/v2/accounts/fixture_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/integration/v2/services.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/integration/v2/accounts/wiring_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 (4)
tests/integration/v2/accounts/wiring_test.go (4)

9-9: LGTM: Import changes align with server v2 migration

The updated imports correctly reflect the transition to server v2's gas metering system and integration test utilities.

Also applies to: 13-13


30-36: LGTM: Account initialization properly uses fixture keepers

The account initialization and funding logic is correctly implemented using the fixture's keepers while maintaining proper error handling.


Line range hint 39-69: LGTM: Comprehensive test coverage with proper assertions

The test thoroughly verifies all components:

  • Transaction execution
  • Gas consumption
  • Header information
  • Address codec functionality
  • Fund transfers and balance checks

All verifications properly utilize the fixture's keepers and maintain strong assertions.


25-28: LGTM: Clean test setup with fixture pattern

The test setup has been improved using a fixture-based approach, which enhances modularity and maintainability. The gas meter and header configurations are properly initialized using the new v2 utilities.

Let's verify the fixture initialization implementation:

✅ Verification successful

LGTM: Fixture initialization is properly implemented

The fixture implementation in tests/integration/v2/accounts/fixture_test.go follows good testing practices:

  • Uses test helper pattern with t.Helper()
  • Sets up proper module encoding configuration
  • Initializes necessary module dependencies (accounts, auth)
  • Provides a clean context with header and gas meter configuration

The usage in wiring_test.go correctly leverages the fixture for test setup.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the fixture implementation
ast-grep --pattern 'func initFixture($$$) *testing.($$$)' 

Length of output: 59


Script:

#!/bin/bash
# Let's try a broader search for the fixture implementation
rg "func initFixture" -A 5

# Also search for any imports of fixture-related types
rg "import.*fixture" --type go

# Search for the integration package usage
rg "integration\." --type go -A 2

Length of output: 60759


Script:

#!/bin/bash
# Let's check the fixture implementation in the specific file
rg -A 10 "func initFixture" tests/integration/v2/accounts/fixture_test.go

# Also check for any test files that use this fixture
rg "initFixture.*\(" tests/integration/v2/accounts/wiring_test.go -A 5

Length of output: 815

Comment on lines +43 to +45
type mockAccount struct {
authenticate authentiacteFunc
}
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

Correct the Typo in authentiacteFunc Type Name

There's a typo in the type name authentiacteFunc; it should be authenticateFunc.

Apply the following diff to fix the typo:

- type authentiacteFunc = func(ctx context.Context, msg *account_abstractionv1.MsgAuthenticate) (*account_abstractionv1.MsgAuthenticateResponse, error)
+ type authenticateFunc = func(ctx context.Context, msg *account_abstractionv1.MsgAuthenticate) (*account_abstractionv1.MsgAuthenticateResponse, error)

Also, update its usage in the mockAccount struct:

type mockAccount struct {
-	authenticate authentiacteFunc
+	authenticate authenticateFunc
}

Also applies to: 69-70

Comment on lines +266 to +267
_ = originalGasMeter.Consume(gasUsed, "execute-with-gas-limit")
iCtx.gasMeter = stfgas.DefaultGasMeter(originalGasMeter.Remaining())
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

Handle Potential Errors from Gas Consumption

The error returned by originalGasMeter.Consume() is ignored. It's important to check and handle this error to prevent unexpected behavior if gas consumption fails.

Apply this diff to handle the error:

-	_ = originalGasMeter.Consume(gasUsed, "execute-with-gas-limit")
+	errConsume := originalGasMeter.Consume(gasUsed, "execute-with-gas-limit")
+	if errConsume != nil {
+		return gasUsed, errConsume
+	}

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Contributor

@hieuvubk hieuvubk left a comment

Choose a reason for hiding this comment

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

lgtm

@tac0turtle tac0turtle added this pull request to the merge queue Dec 16, 2024
Merged via the queue into main with commit f22d2a8 Dec 16, 2024
83 of 84 checks passed
@tac0turtle tac0turtle deleted the son/port_accounts_integration_tests branch December 16, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants