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

chore: remove baseapp and sdk.Context fully from x/upgrade #23396

Open
wants to merge 78 commits into
base: main
Choose a base branch
from

Conversation

aljo242
Copy link
Collaborator

@aljo242 aljo242 commented Jan 15, 2025

Description

Closes: #XXXX


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

Release Notes

  • New Features

    • Introduced a new testing package coretesting with enhanced test environment support.
    • Improved context handling in testing infrastructure.
  • Refactoring

    • Updated test suites to use new testing environment.
    • Removed dependencies on baseapp in multiple modules.
    • Streamlined context and query client initialization.
  • Chores

    • Updated module dependencies and replace directives.
    • Reorganized import statements across multiple files.
  • Testing

    • Enhanced test coverage for upgrade, auth, and circuit modules.
    • Improved test environment configuration and context management.

Copy link
Contributor

coderabbitai bot commented Jan 15, 2025

📝 Walkthrough

Walkthrough

This pull request introduces significant changes to the Cosmos SDK testing infrastructure, focusing on creating a new coretesting package and updating various test suites across different modules. The changes primarily involve replacing baseapp dependencies with a more modular testing approach, introducing a new TestBranchService, and updating context handling in test environments. The modifications streamline testing processes and reduce dependencies on specific application implementations.

Changes

File Change Summary
core/testing/branch.go Added new TestBranchService with Execute and ExecuteWithGasLimit methods.
core/testing/environment.go Updated TestEnvironment to initialize BranchService with TestBranchService{}.
go.mod Added local replace directive for cosmossdk.io/core/testing.
tests/integration/bank/app_test.go Updated test configurations and added transaction encoder/decoder setups.
tests/integration/baseapp/block_gas_test.go Added transaction encoder/decoder setups for bapp.
x/auth/ante/testutil_test.go Removed baseapp and simplified environment setup.
x/auth/keeper/deterministic_test.go Updated imports and query helper initialization.
x/auth/keeper/grpc_query_test.go Updated context handling in query tests.
x/auth/keeper/keeper_test.go Refactored test suite to use new context and environment setup.
x/auth/tx/config/depinject.go Removed BaseAppOption references and imports.
x/circuit/go.mod Restructured replace directives for improved readability.
x/upgrade/go.mod Updated dependency management and replace directives.
x/upgrade/keeper/abci_test.go Refactored test suite with new context handling.
x/upgrade/keeper/grpc_query_test.go Updated context and environment setup for queries.
x/upgrade/keeper/keeper.go Clarified comments regarding versionModifier.
x/upgrade/keeper/keeper_test.go Refactored test suite structure and initialization.

Suggested labels

C:server/v2

Suggested reviewers

  • julienrbrt
  • tac0turtle
  • sontrinh16
  • akhilkumarpilli

Possibly related PRs


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 31034f9 and b537e0a.

⛔ Files ignored due to path filters (3)
  • go.sum is excluded by !**/*.sum
  • x/circuit/go.sum is excluded by !**/*.sum
  • x/upgrade/go.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • go.mod (1 hunks)
  • x/circuit/go.mod (1 hunks)
  • x/upgrade/go.mod (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • go.mod
  • x/upgrade/go.mod
  • x/circuit/go.mod
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary

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.

Base automatically changed from chore/remove-baseapp-accounts to main January 16, 2025 18:59
@aljo242 aljo242 marked this pull request as ready for review January 16, 2025 19:04
@aljo242 aljo242 requested review from a team, lucaslopezf and julienrbrt as code owners January 16, 2025 19:04
@aljo242 aljo242 added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Jan 16, 2025
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

🧹 Nitpick comments (4)
core/testing/branch.go (2)

18-25: Consider implementing actual gas tracking in ExecuteWithGasLimit.

The current implementation always returns the input gasLimit without tracking actual gas consumption, which might be misleading in tests that rely on accurate gas measurements.

 func (bs TestBranchService) ExecuteWithGasLimit(
 	ctx context.Context,
 	gasLimit uint64,
 	f func(ctx context.Context) error,
 ) (gasUsed uint64, err error) {
 	unwrap(ctx) // check that this is a testing context
-	return gasLimit, f(ctx)
+	err = f(ctx)
+	// Return a portion of gasLimit to simulate actual consumption
+	gasUsed = gasLimit / 2
+	return gasUsed, err
}

9-11: Add documentation for exported types and methods.

The TestBranchService type and its methods are exported but lack documentation comments. This makes it harder for other developers to understand their purpose and usage.

+// TestBranchService implements branch.Service for testing purposes.
 var _ branch.Service = &TestBranchService{}

+// TestBranchService provides a minimal implementation of branch.Service for testing.
 type TestBranchService struct{}
x/upgrade/keeper/keeper.go (1)

Line range hint 440-449: Consider adding error handling for nil versionModifier.

The code checks for nil versionModifier but doesn't handle potential errors from AppVersion() and SetAppVersion() consistently.

Consider this implementation:

 if k.versionModifier != nil {
     currentAppVersion, err := k.versionModifier.AppVersion(ctx)
     if err != nil {
         return err
     }
-
-    if err := k.versionModifier.SetAppVersion(ctx, currentAppVersion+1); err != nil {
-        return err
-    }
+    return k.versionModifier.SetAppVersion(ctx, currentAppVersion+1)
 }
x/upgrade/keeper/abci_test.go (1)

71-85: Consider adding validation in version modifier.

The mocked version modifier implementation could benefit from basic validation.

Consider adding validation:

 func (m *mockedVersionModifier) SetAppVersion(_ context.Context, u uint64) error {
+    if u < m.version {
+        return fmt.Errorf("cannot decrease version from %d to %d", m.version, u)
+    }
     m.version = u
     return nil
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7f827c5 and 06da05e.

⛔ Files ignored due to path filters (3)
  • go.sum is excluded by !**/*.sum
  • x/circuit/go.sum is excluded by !**/*.sum
  • x/upgrade/go.sum is excluded by !**/*.sum
📒 Files selected for processing (16)
  • core/testing/branch.go (1 hunks)
  • core/testing/environment.go (1 hunks)
  • go.mod (1 hunks)
  • tests/integration/bank/app_test.go (2 hunks)
  • tests/integration/baseapp/block_gas_test.go (1 hunks)
  • x/auth/ante/testutil_test.go (1 hunks)
  • x/auth/keeper/deterministic_test.go (3 hunks)
  • x/auth/keeper/grpc_query_test.go (2 hunks)
  • x/auth/keeper/keeper_test.go (5 hunks)
  • x/auth/tx/config/depinject.go (0 hunks)
  • x/circuit/go.mod (1 hunks)
  • x/upgrade/go.mod (2 hunks)
  • x/upgrade/keeper/abci_test.go (16 hunks)
  • x/upgrade/keeper/grpc_query_test.go (5 hunks)
  • x/upgrade/keeper/keeper.go (3 hunks)
  • x/upgrade/keeper/keeper_test.go (7 hunks)
💤 Files with no reviewable changes (1)
  • x/auth/tx/config/depinject.go
✅ Files skipped from review due to trivial changes (2)
  • x/auth/keeper/grpc_query_test.go
  • x/circuit/go.mod
🧰 Additional context used
📓 Path-based instructions (11)
x/auth/ante/testutil_test.go (2)

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/baseapp/block_gas_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"

core/testing/environment.go (1)

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

x/upgrade/keeper/keeper.go (1)

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

tests/integration/bank/app_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"

core/testing/branch.go (1)

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

x/auth/keeper/keeper_test.go (2)

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/upgrade/keeper/grpc_query_test.go (2)

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/auth/keeper/deterministic_test.go (2)

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/upgrade/keeper/keeper_test.go (2)

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/upgrade/keeper/abci_test.go (2)

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test-system-v2
  • GitHub Check: Analyze
  • GitHub Check: Summary
🔇 Additional comments (27)
core/testing/environment.go (1)

36-36: LGTM!

Initializing BranchService with TestBranchService{} aligns with the PR objective of removing baseapp dependencies.

x/upgrade/keeper/grpc_query_test.go (3)

31-32: LGTM!

The type changes from sdk.Context to coretesting.TestContext align with the PR objective of removing SDK context dependencies.


41-47: LGTM!

The test environment setup is clean and properly initialized with the required configuration.


103-103: Verify all context usage is updated consistently.

Ensure that all query client calls use the test context consistently. Let's verify this:

Also applies to: 161-161, 211-211

tests/integration/baseapp/block_gas_test.go (1)

104-105: LGTM!

Setting the transaction encoder and decoder is necessary for proper transaction handling in the test environment.

x/auth/keeper/keeper_test.go (4)

13-14: LGTM! Import changes align with the new query handling pattern.

The addition of the queryclient package supports the transition away from baseapp dependencies.


54-58: LGTM! Environment setup follows the new testing pattern.

The use of coretesting.NewTestEnvironment provides a more modular and maintainable test setup.


Line range hint 81-89: LGTM! Keeper initialization updated correctly.

The environment parameter is properly passed to the keeper constructor.


91-93: LGTM! Query helper setup follows the new pattern.

The transition to queryclient.NewQueryHelper with codec.NewProtoCodec improves the query handling mechanism.

x/auth/ante/testutil_test.go (1)

99-100: LGTM! Environment setup simplified correctly.

The environment initialization has been streamlined by removing baseapp dependencies.

x/upgrade/keeper/keeper_test.go (4)

13-14: LGTM! Import changes support new functionality.

The addition of server and queryclient packages aligns with the module's requirements.


33-35: LGTM! Type declarations updated appropriately.

The change to use coretesting types improves test environment management.


68-76: LGTM! Keeper initialization updated correctly.

The keeper parameters are properly configured with the new environment setup.


Line range hint 289-307: LGTM! Version checks implemented correctly.

The context usage in version checks is consistent with the new context management approach.

x/auth/keeper/deterministic_test.go (3)

17-17: LGTM! Import changes align with new query handling.

The addition of the queryclient package supports the new query helper pattern.


263-265: LGTM! Query helper initialization follows new pattern.

The use of queryclient.NewQueryHelper with codec.NewProtoCodec improves query handling.


269-269: LGTM! Context type updated appropriately.

The parameter type change to context.Context aligns with the new context management approach.

x/upgrade/keeper/keeper.go (2)

37-37: LGTM! Clear and accurate documentation.

The updated comment for versionModifier field accurately describes its purpose without tying it to a specific implementation.


50-50: LGTM! Improved parameter documentation.

The updated comment for the vs parameter provides a clearer description of its functionality.

tests/integration/bank/app_test.go (3)

93-93: TODO comment needs clarification.

The TODO comment about using a v2 application lacks context and actionable details.

Please clarify:

  • What is a v2 application?
  • What are the requirements or blockers?
  • Is there a tracking issue?

Line range hint 94-115: LGTM! Improved test setup readability.

The expanded configuration parameters enhance code readability and maintainability.


118-119: LGTM! Proper transaction handling setup.

The addition of TxEncoder and TxDecoder setup ensures proper transaction handling in tests.

x/upgrade/keeper/abci_test.go (2)

36-38: LGTM! Clear test suite structure.

The updated TestSuite structure properly uses the new testing infrastructure.


40-69: LGTM! Well-structured test setup.

The setupTest function properly initializes the test environment with all necessary components.

go.mod (1)

173-173: LGTM! Proper module replacement.

The replace directive correctly points to the local core/testing implementation.

x/upgrade/go.mod (2)

73-73: LGTM: Addition of cometbft/api as indirect dependency

The addition of github.com/cometbft/cometbft/api as an indirect dependency aligns with the PR's objective of removing baseapp dependencies.


200-203: LGTM: Well-organized replace directives

The replace directives are properly organized, grouping related replacements together. The addition of cosmossdk.io/core/testing replacement is consistent with the module's testing requirements.

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:core/testing C:x/auth C:x/circuit C:x/upgrade
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants