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: simplify group dependency graph and align 0.52 and main #22978

Merged
merged 6 commits into from
Dec 18, 2024

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Dec 18, 2024

Description


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 minimalBankKeeper interface for streamlined coin operations.
    • Added a method to the BankKeeper interface for transferring coins between modules.
    • Introduced a new StakingKeeper interface for staking operations in tests.
    • Implemented epoched minting through a configurable MintFn in the x/mint module.
    • Added new service types for event handling and message routing in integration tests.
  • Bug Fixes

    • Enhanced error handling and logic in the minting function setup.
    • Improved error handling and clarity in lockup account operations.
  • Documentation

    • Updated changelog to reflect new features and API changes in the x/mint module.
  • Refactor

    • Refactored test suite structure for improved organization and readability.
    • Updated test cases to enhance robustness and clarity in group policy handling.
  • Chores

    • Removed unnecessary module dependencies from go.mod files across multiple modules.

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Dec 18, 2024
Copy link
Contributor

coderabbitai bot commented Dec 18, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request introduces several modifications across multiple modules in the Cosmos SDK, focusing on refactoring test utilities, updating dependency management, and streamlining interfaces. The changes primarily affect the x/bank, x/distribution, x/group, x/mint, x/params, and related test utility files. Key modifications include introducing a new minimal bank keeper interface, removing local module replacements, updating test suites, and adjusting mocking capabilities for testing purposes.

Changes

File Change Summary
x/bank/testutil/helpers.go Added minimalBankKeeper interface, updated FundAccount and FundModuleAccount function signatures
x/distribution/go.mod Removed cosmossdk.io/x/protocolpool dependency and replace directive
x/group/go.mod Removed multiple module dependencies and replace directives
x/group/keeper/abci_test.go Refactored test suite, updated test method signatures
x/group/keeper/keeper_test.go Added addressCodec field to TestSuite
x/group/testutil/expected_keepers.go Updated import, added SendCoinsFromModuleToModule method, introduced StakingKeeper interface
x/group/testutil/expected_keepers_mocks.go Added mock implementations for new methods in BankKeeper and introduced MockStakingKeeper
x/mint/CHANGELOG.md Updated changelog with new features and breaking changes
x/mint/depinject.go Modified InvokeSetMintFn function signature and error handling
x/mint/go.mod Removed cosmossdk.io/x/consensus replace directive
x/params/go.mod Removed several module replacement directives
tests/integration/v2/gov/common_test.go Added handler for governance proposal submissions
tests/integration/v2/gov/keeper/fixture_test.go Registered custom message handler for MsgExecLegacyContent
tests/integration/v2/services.go Introduced new service types and methods for event handling and routing
x/accounts/defaults/lockup/lockup.go Enhanced error handling and logic flow in lockup methods
x/accounts/defaults/lockup/utils_test.go Added makeMockDependencies function for improved testing capabilities

Possibly related PRs

Suggested Reviewers

  • akhilkumarpilli
  • testinginprod
  • sontrinh16

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. We would love to hear your feedback on Discord.


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.

@julienrbrt julienrbrt changed the title refactor(x/group): simplify dependency graph refactor: simplify dependency graph and align 0.52 and main Dec 18, 2024
Copy link
Contributor

@akhilkumarpilli akhilkumarpilli left a comment

Choose a reason for hiding this comment

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

ACK

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 (8)
x/group/keeper/msg_server_test.go (2)

2058-2058: Ensure consistent state for minted or transferred coins.
Double-check that repeated calls to SendCoinsFromModuleToAccount won't create unexpected balances in subsequent tests.


2722-2722: Validate repeated fund operations if test logic is reused.
Repeatedly sending coins could inflate test accounts more than intended. Check if each test scenario starts from a known baseline and resets state properly.

x/group/testutil/expected_keepers.go (1)

38-38: New SendCoinsFromModuleToModule method supports flexible module transfers.
This expansion of the BankKeeper interface is generally good for covering more scenarios in tests. Ensure all module-to-module transfers are properly tested for error handling.

x/mint/depinject.go (1)

91-95: Consider simplifying the nested conditional logic.

The current implementation uses nested if-else statements which could be simplified for better readability.

Consider this alternative structure:

-if mintFn == nil {
-  if inflationCalculationFn != nil && stakingKeeper != nil {
-    mintFn = keeper.DefaultMintFn(inflationCalculationFn, stakingKeeper, mintKeeper)
-  } else {
-    mintFn = keeper.DefaultMintFn(types.DefaultInflationCalculationFn, stakingKeeper, mintKeeper)
-  }
+if mintFn == nil {
+  calculationFn := types.DefaultInflationCalculationFn
+  if inflationCalculationFn != nil {
+    calculationFn = inflationCalculationFn
+  }
+  mintFn = keeper.DefaultMintFn(calculationFn, stakingKeeper, mintKeeper)
}
x/group/keeper/keeper_test.go (1)

49-49: LGTM! Consider extracting test data setup.

The test suite setup is well-structured with proper mock initialization and error handling. Consider extracting the test data setup (addresses, weights) into test constants or helper functions for better maintainability.

Also applies to: 60-74

x/group/keeper/abci_test.go (3)

Line range hint 16-313: Consider more descriptive test case names.

While the test coverage is comprehensive, some test case names could be more descriptive. For example, "proposal pruned after executor result success" could be "should_prune_proposal_when_execution_succeeds".

🧰 Tools
🪛 golangci-lint (1.62.2)

6-6: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

(gci)


11-11: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

(gci)


Line range hint 502-540: Add documentation for helper functions.

Consider adding documentation comments for the helper functions to explain their purpose, parameters, and return values.

Example:

// submitProposalHelper submits a proposal with the given messages and proposers.
// It returns the proposal ID and any error encountered.
func submitProposalHelper(...)

11-12: Fix import ordering.

The imports should be ordered according to the project's gci configuration:

  • standard library
  • default packages
  • prefix(cosmossdk.io)
  • prefix(github.com/cosmos/cosmos-sdk)
🧰 Tools
🪛 golangci-lint (1.62.2)

11-11: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

(gci)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cb56c6e and c1abab5.

⛔ Files ignored due to path filters (1)
  • x/group/go.sum is excluded by !**/*.sum
📒 Files selected for processing (13)
  • x/bank/testutil/helpers.go (2 hunks)
  • x/distribution/go.mod (0 hunks)
  • x/group/go.mod (1 hunks)
  • x/group/keeper/abci_test.go (27 hunks)
  • x/group/keeper/keeper_test.go (5 hunks)
  • x/group/keeper/msg_server_test.go (3 hunks)
  • x/group/testutil/app_config.go (0 hunks)
  • x/group/testutil/expected_keepers.go (2 hunks)
  • x/group/testutil/expected_keepers_mocks.go (2 hunks)
  • x/mint/CHANGELOG.md (1 hunks)
  • x/mint/depinject.go (1 hunks)
  • x/mint/go.mod (0 hunks)
  • x/params/go.mod (0 hunks)
💤 Files with no reviewable changes (4)
  • x/distribution/go.mod
  • x/mint/go.mod
  • x/params/go.mod
  • x/group/testutil/app_config.go
🧰 Additional context used
📓 Path-based instructions (8)
x/bank/testutil/helpers.go (1)

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

x/mint/depinject.go (1)

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

x/mint/CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

x/group/testutil/expected_keepers.go (1)

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

x/group/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/group/testutil/expected_keepers_mocks.go (1)

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

x/group/keeper/msg_server_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/group/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"

🪛 golangci-lint (1.62.2)
x/group/keeper/abci_test.go

11-11: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

(gci)

🔇 Additional comments (14)
x/group/keeper/msg_server_test.go (2)

20-20: No issues identified with the new import.
This import for "github.com/cosmos/cosmos-sdk/testutil" seems consistent and does not introduce any observable problem.


2057-2057: Confirm mock usage logic for multiple calls.
Using .AnyTimes() in the mock setup is acceptable for repeated calls; ensure it's not masking unexpected repeated invocations that might indicate a latent bug.

x/group/testutil/expected_keepers.go (2)

8-8: Slight import alias change is fine.
The import "cosmossdk.io/core/address" is properly referenced as is; no concerns seen.


42-45: Introduction of StakingKeeper interface.
This separate interface for staking–specific calls is a clean separation of concerns. It's recommended to provide thorough test coverage to verify edge cases (e.g., a nonexistent bond denom).

x/bank/testutil/helpers.go (3)

11-17: New minimalBankKeeper interface clarifies required capabilities for tests.
This is a valuable refactor that ensures tests rely on a narrower set of methods, reducing coupling.


25-25: FundAccount now depends on minimalBankKeeper.
Switching to minimalBankKeeper keeps the function signature aligned with the new, slimmer testing interface. The logic remains unchanged.


39-39: FundModuleAccount now also uses minimalBankKeeper.
Similar to FundAccount, this maintains consistency. Confirm that existing test cases cover scenarios for module funding thoroughly.

x/mint/CHANGELOG.md (1)

42-42: Document updated signatures for DefaultMintFn.
This clarifies that DefaultMintFn now needs StakingKeeper and MintKeeper. The changelog effectively communicates the breaking change and required migration steps.

x/mint/depinject.go (1)

80-89: LGTM: Robust error handling for function parameters.

The error handling is comprehensive, properly validating the mutual exclusivity of mintFn and inflationCalculationFn while ensuring at least one required parameter is provided.

x/group/go.mod (1)

37-37: LGTM: Appropriate dependency management.

The addition of cosmossdk.io/x/staking as an indirect dependency is correctly marked and follows Go module conventions.

x/group/testutil/expected_keepers_mocks.go (2)

223-235: LGTM: Well-structured mock implementation.

The SendCoinsFromModuleToModule mock implementation follows the established patterns and includes proper helper method usage.


281-318: LGTM: Comprehensive StakingKeeper mock implementation.

The MockStakingKeeper implementation is well-structured and follows the gomock conventions consistently.

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

78-79: LGTM! Mock expectations are properly configured.

The bank keeper mock setup is correct with appropriate expectations for coin operations.

Also applies to: 136-141


Line range hint 314-538: LGTM! Comprehensive test coverage for tally scenarios.

The test cases thoroughly cover various voting scenarios and edge cases, with proper assertions and error handling.

@julienrbrt julienrbrt enabled auto-merge December 18, 2024 12:18
@julienrbrt julienrbrt changed the title refactor: simplify dependency graph and align 0.52 and main refactor: simplify group dependency graph and align 0.52 and main Dec 18, 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: 0

🧹 Nitpick comments (4)
x/group/keeper/abci_test.go (2)

17-19: Consider using more precise mock expectations

Using AnyTimes() for mock expectations could potentially mask issues by being too permissive. Consider setting specific expectations for the number of times Send should be called in each test case.

-s.bankKeeper.EXPECT().Send(gomock.Any(), gomock.Any()).Return(&banktypes.MsgSendResponse{}, nil).AnyTimes()
+s.bankKeeper.EXPECT().Send(gomock.Any(), gomock.Any()).Return(&banktypes.MsgSendResponse{}, nil).Times(1)

Line range hint 503-541: Add function documentation

Consider adding documentation to explain the purpose and parameters of these helper functions. This would improve maintainability and make it easier for other developers to understand their usage.

+// submitProposalHelper creates and submits a proposal with the given messages and proposers
+// Returns the proposal ID and any error encountered
 func submitProposalHelper(s *TestSuite, ctx context.Context, msgs []sdk.Msg, proposers []string, groupPolicyAddr sdk.AccAddress) (uint64, error) {

+// submitProposalAndVoteHelper creates a proposal and submits a vote with the specified option
+// Returns the proposal ID and any error encountered
 func submitProposalAndVoteHelper(
tests/integration/v2/services.go (2)

Line range hint 221-232: BranchService struct: evaluate potential concurrency scenario
Since the integrationContext is mutated directly (gasMeter assignment, restoration), concurrency could lead to conflicting states if multiple tests run concurrently. Ensure in your test harness that each test uses an isolated context, or add synchronization if concurrency is desired.


Line range hint 305-331: RouterService: consider thread-safety on handler registrations
The current approach relies on a map of message type URLs to handlers without locking. For integration tests, this is usually acceptable. If you ever parallelize the message dispatch or add dynamic registrations at runtime, locking or concurrency guarantees might be needed.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c1abab5 and 621b526.

📒 Files selected for processing (6)
  • tests/integration/v2/gov/common_test.go (0 hunks)
  • tests/integration/v2/gov/keeper/fixture_test.go (0 hunks)
  • tests/integration/v2/services.go (1 hunks)
  • x/accounts/defaults/lockup/lockup.go (0 hunks)
  • x/accounts/defaults/lockup/utils_test.go (0 hunks)
  • x/group/keeper/abci_test.go (27 hunks)
💤 Files with no reviewable changes (4)
  • tests/integration/v2/gov/keeper/fixture_test.go
  • tests/integration/v2/gov/common_test.go
  • x/accounts/defaults/lockup/utils_test.go
  • x/accounts/defaults/lockup/lockup.go
🧰 Additional context used
📓 Path-based instructions (2)
x/group/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"

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"

🔇 Additional comments (8)
x/group/keeper/abci_test.go (3)

7-13: LGTM: Import changes align with test suite refactoring

The addition of gomock and updated imports properly support the transition to the new test suite structure.


315-317: Same mock expectation issue as in TestEndBlockerPruning

The mock expectations should be more specific to each test case.


Line range hint 315-500: LGTM: Comprehensive test coverage

The test cases thoroughly cover various scenarios including:

  • Tally updates after voting period
  • Voting within the period
  • Different voting outcomes
  • Withdrawn proposal handling
tests/integration/v2/services.go (5)

Line range hint 173-183: Review of eventService struct and EventManager creation
The introduction of a dedicated eventService struct returning an EventManager is clear and consistent with the rest of the code.


Line range hint 185-211: Suggestion: Ensure concurrency safety if multiple goroutines emit events
The eventManager stores events in a slice within integrationContext. If there's any chance these tests run concurrently, consider synchronizing access (via a mutex or concurrency-safe structure). Otherwise, the single-threaded usage in an integration test context is likely sufficient.


Line range hint 234-266: ExecuteWithGasLimit: confirm gas logic validity
Reassigning iCtx.gasMeter to a new meter and then partially refilling the originalGasMeter is clever, but be mindful that if originalGasMeter doesn’t have enough remaining gas to consume this additional usage, it could silently cause issues. Consider either checking for an overflow or returning an error if originalGasMeter is insufficient.


Line range hint 333-340: HeaderService: usage is straightforward
The HeaderService simply returns header information from the integration context. This is fine for an integration test environment and meets the Uber Go style recommendations of short, straightforward methods.


Line range hint 345-352: GasService: usage is appropriate
The GasService retrieves the gas meter and config from the context with minimal overhead. This is aligned with the code’s pattern and consistent with the style guidelines.

@julienrbrt julienrbrt added this pull request to the merge queue Dec 18, 2024
Merged via the queue into main with commit 4d6c991 Dec 18, 2024
87 of 88 checks passed
@julienrbrt julienrbrt deleted the julien/group-deps branch December 18, 2024 14:17
mergify bot pushed a commit that referenced this pull request Dec 18, 2024
…2978)

(cherry picked from commit 4d6c991)

# Conflicts:
#	tests/integration/v2/gov/common_test.go
#	tests/integration/v2/gov/keeper/fixture_test.go
#	x/distribution/go.mod
#	x/group/go.mod
#	x/group/go.sum
#	x/mint/go.mod
#	x/params/go.mod
julienrbrt added a commit that referenced this pull request Dec 18, 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:x/accounts/lockup C:x/accounts C:x/bank C:x/distribution distribution module related C:x/group C:x/mint C:x/params
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants