Skip to content

Conversation

Forostovec
Copy link

@Forostovec Forostovec commented Sep 4, 2025

Description

Removed duplicate distributionKeeper.EXPECT().FundCommunityPool(...).Return(nil).AnyTimes() in setupGovKeeper, keeping only the balance-aware DoAndReturn from trackMockBalances.

Removed redundant trackMockBalances calls in tests that already use setupGovKeeper, and adjusted unused return bindings.

Rationale: duplicated gomock expectations for the same method increase brittleness and ambiguity—order-dependent matching can mask mistakes and confuse future maintainers. Retaining a single expectation with explicit balance mutations matches test intentions and reduces risk. Cleaning redundant calls avoids unnecessary state duplication and keeps tests clearer.

Summary by CodeRabbit

  • Tests
    • Simplified governance deposit tests by removing unnecessary dependencies, reducing setup complexity and improving maintainability.
    • Eliminated brittle mock expectations to make tests more robust and less flaky.
    • Ensured test coverage remains intact without changing test logic or scenarios.
    • No user-facing changes; runtime behavior and features remain unaffected.

Copy link
Contributor

coderabbitai bot commented Sep 4, 2025

📝 Walkthrough

Walkthrough

Test scaffolding for the gov keeper was simplified by removing the FundCommunityPool gomock expectation and eliminating distribution keeper usage in deposit-related tests. The setup function no longer asserts FundCommunityPool calls, and deposit tests stop tracking mock balances via the distribution keeper.

Changes

Cohort / File(s) Summary of changes
Gov keeper test setup
x/gov/keeper/common_test.go
Removed gomock expectation for distributionKeeper.FundCommunityPool(...) in setupGovKeeper; no longer asserts or stubs this call.
Gov deposit tests
x/gov/keeper/deposit_test.go
Updated tests to ignore distribution keeper return values from setupGovKeeper; removed trackMockBalances(bankKeeper, distKeeper) usage; no other test logic changed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
x/gov/keeper/deposit_test.go (1)

445-447: Bug: wrong ratio used for cancellation charge expectation

The test computes cancellationCharges with MinInitialDepositRatio instead of ProposalCancelRatio, which will silently zero out expected charges unless MinInitialDepositRatio is set. Fix to align with the exercised parameter.

-                            burnAmount := sdkmath.LegacyNewDecFromInt(deposit.Amount).Mul(sdkmath.LegacyMustNewDecFromStr(params.MinInitialDepositRatio)).TruncateInt()
+                            burnAmount := sdkmath.LegacyNewDecFromInt(deposit.Amount).Mul(sdkmath.LegacyMustNewDecFromStr(params.ProposalCancelRatio)).TruncateInt()
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 13d51f0 and c24035d.

📒 Files selected for processing (2)
  • x/gov/keeper/common_test.go (0 hunks)
  • x/gov/keeper/deposit_test.go (2 hunks)
💤 Files with no reviewable changes (1)
  • x/gov/keeper/common_test.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Summary
🔇 Additional comments (2)
x/gov/keeper/deposit_test.go (2)

209-209: LGTM: removed dist keeper binding in TestDepositAmount

Same rationale as above; the test doesn’t observe community-pool effects, so dropping dist keeper plumbing is fine.


376-388: Switch to classic for-loop or confirm Go ≥1.22
for i := range 3 requires Go 1.22+ (and changes closure-capture); if your CI isn’t on 1.22+, revert to:

-for i := range 3 {
+for i := 0; i < 3; i++ {
+    i := i // capture for the closure on older Go versions

Ensure your go.mod’s go directive is ≥ 1.22 (and update CI) or use the above loop.

@@ -38,8 +38,7 @@ func TestDeposits(t *testing.T) {

for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
govKeeper, authKeeper, bankKeeper, stakingKeeper, distKeeper, _, ctx := setupGovKeeper(t)
trackMockBalances(bankKeeper, distKeeper)
govKeeper, authKeeper, bankKeeper, stakingKeeper, _, _, ctx := setupGovKeeper(t)
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

LGTM: removed dist keeper binding in TestDeposits

Ignoring the 5th/6th returns from setupGovKeeper aligns with deduping FundCommunityPool expectations and removing redundant balance tracking.

Run to ensure no leftover redundant tracking calls remain:


🏁 Script executed:

#!/bin/bash
# Find redundant balance tracking helpers still present in gov tests
rg -nP 'trackMockBalances\s*\(' x/gov -g '**/*_test.go'

Length of output: 292


Remove leftover redundant balance-tracking helper calls

  • x/gov/keeper/common_test.go: delete the trackMockBalances(bankKeeper, distributionKeeper) invocation at line 90 and the trackMockBalances helper definition at line 122.
🤖 Prompt for AI Agents
In x/gov/keeper/deposit_test.go around line 41, and specifically in
x/gov/keeper/common_test.go at lines 90 and 122, there are leftover redundant
balance-tracking helper usages: remove the call to trackMockBalances(bankKeeper,
distributionKeeper) at line 90 and delete the entire trackMockBalances helper
definition at line 122; after removal, run tests and remove any now-unused
imports related to that helper (or references) to keep the file clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants