fix: deduct region delegate interest when settlement interest#1394
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughKYC reward settlement now rejects insufficient DelegateInterest before payout in three keeper paths. Two tests also initialize staking block state before asserting next-block delegation behavior. ChangesKYC Reward Interest Guard
Staking BeginBlock in region transfer test
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
x/wstaking/keeper/kyc_reward.go (1)
113-114: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueNormalize the new error strings to Uber Go style.
These new errors start with function/camel-case names. Prefer lower-case, message-oriented strings.
Example wording update
- return fmt.Errorf("RemoveKycReward err,region(%s) total interest not enough.need pay %s,only have %s", + return fmt.Errorf("remove kyc reward: region %s total interest not enough: need %s, have %s", - return fmt.Errorf("sendKycRewards err,region(%s) total interest not enough.need pay %s,only have %s", + return fmt.Errorf("send kyc rewards: region %s total interest not enough: need %s, have %s", - return amount, fmt.Errorf("transferUnRegisterMeid err,region(%s) total interest not enough.need pay %s,only have %s", + return amount, fmt.Errorf("transfer unregister meid: region %s total interest not enough: need %s, have %s",As per path instructions, "
**/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations."Also applies to: 196-198, 445-446
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@x/wstaking/keeper/kyc_reward.go` around lines 113 - 114, The new error string in RemoveKycReward should be normalized to Uber Go style by removing the function/camel-case prefix and making it a lower-case, message-oriented sentence. Update the fmt.Errorf message in RemoveKycReward, and apply the same style cleanup to the other newly added error strings at the referenced locations so all errors read naturally and consistently.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@x/wstaking/keeper/kyc_reward.go`:
- Around line 110-115: The RemoveKycReward flow is subtracting the same rewards
twice from region.DelegateInterest, first in the guarded block and again later
after the transfer. Update RemoveKycReward in kyc_reward.go so the deduction
happens only once, and remove or refactor the later DelegateInterest subtraction
path to reuse the already-updated balance while keeping the existing GTE balance
check.
---
Nitpick comments:
In `@x/wstaking/keeper/kyc_reward.go`:
- Around line 113-114: The new error string in RemoveKycReward should be
normalized to Uber Go style by removing the function/camel-case prefix and
making it a lower-case, message-oriented sentence. Update the fmt.Errorf message
in RemoveKycReward, and apply the same style cleanup to the other newly added
error strings at the referenced locations so all errors read naturally and
consistently.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro Plus
Run ID: a3632d19-1e36-4405-b1d7-5ae921180e73
📒 Files selected for processing (1)
x/wstaking/keeper/kyc_reward.go
There was a problem hiding this comment.
🧹 Nitpick comments (1)
x/wstaking/keeper/kyc_region_test.go (1)
63-64: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a guard-failure test for insufficient
DelegateInterest.This covers the happy path after
wstaking.BeginBlock, but not the new insufficient-interest failure contract. Add a companion case that skips interest accrual (or forces low interest), expectsTransferKycRegionto fail, and verifies no state mutation.Proposed test shape
func (s *KeeperTestSuite) TestTransferKycRegion() { + s.Run("fails when source region interest is insufficient", func() { + s.SetupTest() + // Arrange identical setup, but do NOT call wstaking.BeginBlock on the transfer block. + // Act: call TransferKycRegion(...) + // Assert: require.Error(err) and delegation/region balances unchanged. + }) + // existing happy-path test... }As per path instructions, "
**/*_test.go: Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request."🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@x/wstaking/keeper/kyc_region_test.go` around lines 63 - 64, Add a companion test in kyc_region_test.go around wstaking.BeginBlock that exercises the insufficient DelegateInterest path: set up the same TransferKycRegion scenario but skip interest accrual or force the balance below the required threshold, then assert TransferKycRegion returns an error and that no state changes occurred. Use the existing kyc region test helpers and the relevant TransferKycRegion / BeginBlock flow to locate the coverage gap.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@x/wstaking/keeper/kyc_region_test.go`:
- Around line 63-64: Add a companion test in kyc_region_test.go around
wstaking.BeginBlock that exercises the insufficient DelegateInterest path: set
up the same TransferKycRegion scenario but skip interest accrual or force the
balance below the required threshold, then assert TransferKycRegion returns an
error and that no state changes occurred. Use the existing kyc region test
helpers and the relevant TransferKycRegion / BeginBlock flow to locate the
coverage gap.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro Plus
Run ID: 02ee3a9d-5b24-4d07-b2e0-9960cfda11c3
📒 Files selected for processing (1)
x/wstaking/keeper/kyc_region_test.go
Summary by CodeRabbit
Bug Fixes
Tests