fix: improve reward genesis validation and reward pool validation#323
Conversation
WalkthroughThe PR adds denom consistency validation to the rewards module's genesis handling. It updates Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
x/rewards/types/genesis_test.go (1)
84-91: Isolate this case to only the field under test.For the “mismatched total amount denom” case, mutate only
TotalAmount.Denomand keepReleasedAmountaligned withTokenDenom. This makes the test prove the intended validation path unambiguously.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@x/rewards/types/genesis_test.go` around lines 84 - 91, Test mutates too many fields; narrow the "mismatched total amount denom" case to only change TotalAmount.Denom. In the modifyFn for the ReleaseSchedule test case update only TotalAmount to use "notkii" while keeping ReleasedAmount (and any TokenDenom references) using the expected token denom (e.g., sdk.NewCoin(TokenDenom, math.NewInt(0))) and leave EndTime and Active as-is so the validation failure is attributable solely to the mismatched TotalAmount denom.x/rewards/types/reward_pool_test.go (1)
75-83: Strengthen negative-case assertions with error content checks.Right now, any error satisfies failing cases. Consider adding per-case
errContainsand usingrequire.ErrorContainsso regressions fail for the right reason.Proposed test hardening
testCases := []struct { name string pool types.RewardPool expectErr bool + errContains string }{ { name: "negative amount", pool: ..., expectErr: true, + errContains: "negative", }, { name: "duplicate denoms", pool: ..., expectErr: true, + errContains: "duplicate", }, } ... if tc.expectErr { require.Error(t, err) + if tc.errContains != "" { + require.ErrorContains(t, err, tc.errContains) + } } else { require.NoError(t, err) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@x/rewards/types/reward_pool_test.go` around lines 75 - 83, The test's negative cases accept any error; augment the test table entries in testCases with an errContains string for expected error substrings and, inside the t.Run loop where ValidateGenesis() is called, replace require.Error(...) with require.ErrorContains(t, err, tc.errContains) when tc.expectErr is true (keep require.NoError for the non-error branch). Ensure testCases entries that expect failures populate errContains with the specific message fragment to assert the correct failure reason for ValidateGenesis.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@x/rewards/types/genesis.go`:
- Around line 39-51: GenesisState denom consistency checks in Validate() can be
bypassed because AppModule.InitGenesis calls keeper.InitGenesis without
validating; update the module initialization to enforce validation by calling
GenesisState.Validate() from AppModule.InitGenesis before invoking
keeper.InitGenesis (or alternatively move the denom checks into
keeper.InitGenesis if you prefer validation inside the keeper). Locate
AppModule.InitGenesis and add a validation step that invokes
GenesisState.Validate() (handling/returning the error) for the incoming gs,
referencing GenesisState.Validate(), AppModule.InitGenesis, and
keeper.InitGenesis to ensure invalid genesis is rejected before state is
applied.
---
Nitpick comments:
In `@x/rewards/types/genesis_test.go`:
- Around line 84-91: Test mutates too many fields; narrow the "mismatched total
amount denom" case to only change TotalAmount.Denom. In the modifyFn for the
ReleaseSchedule test case update only TotalAmount to use "notkii" while keeping
ReleasedAmount (and any TokenDenom references) using the expected token denom
(e.g., sdk.NewCoin(TokenDenom, math.NewInt(0))) and leave EndTime and Active
as-is so the validation failure is attributable solely to the mismatched
TotalAmount denom.
In `@x/rewards/types/reward_pool_test.go`:
- Around line 75-83: The test's negative cases accept any error; augment the
test table entries in testCases with an errContains string for expected error
substrings and, inside the t.Run loop where ValidateGenesis() is called, replace
require.Error(...) with require.ErrorContains(t, err, tc.errContains) when
tc.expectErr is true (keep require.NoError for the non-error branch). Ensure
testCases entries that expect failures populate errContains with the specific
message fragment to assert the correct failure reason for ValidateGenesis.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 00089e97-ec0a-40e0-8424-bac668ed29da
📒 Files selected for processing (5)
CHANGELOG.mdx/rewards/types/genesis.gox/rewards/types/genesis_test.gox/rewards/types/reward_pool.gox/rewards/types/reward_pool_test.go
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Description
DecCoins.Validate()onRewardPool.ValidateGenesisto catch malformed denom formats, duplicate denoms, bad orderingGenesisState.ValidatewithParams.TokenDenomType of change
How Has This Been Tested?
Added regression tests
PR Checklist:
Make sure each step was done:
make lint-fix