fix: ensure feetokens cannot be initialized as new#316
Conversation
WalkthroughThis pull request adds nil-safety checks for Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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.
🧹 Nitpick comments (1)
x/feeabstraction/keeper/genesis.go (1)
21-26: Remove unreachable nil-normalization to keep behavior consistent.
gs.Validate()on Line 12 already rejectsnilFeeTokens, so this block never handles a nil case in practice. Keeping both “reject nil” and “normalize nil” semantics in the same path is confusing for future maintenance.♻️ Suggested simplification
- // Set the fee tokens (treat nil as an empty collection) - feeTokens := types.FeeTokenMetadataCollection{} - if gs.FeeTokens != nil { - feeTokens = *gs.FeeTokens - } - return k.FeeTokens.Set(ctx, feeTokens) + // Set the fee tokens (validated as non-nil above) + return k.FeeTokens.Set(ctx, *gs.FeeTokens)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@x/feeabstraction/keeper/genesis.go` around lines 21 - 26, The code currently defensively normalizes nil FeeTokens even though gs.Validate() already rejects nil FeeTokens; remove the unreachable nil-normalization and directly set the stored fee tokens from the provided genesis data. Replace the conditional that builds feeTokens := types.FeeTokenMetadataCollection{} / if gs.FeeTokens != nil ... with a direct use of the validated pointer (i.e., pass *gs.FeeTokens into k.FeeTokens.Set), referencing gs.Validate(), gs.FeeTokens, types.FeeTokenMetadataCollection, and k.FeeTokens.Set(ctx, ...) to locate the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@x/feeabstraction/keeper/genesis.go`:
- Around line 21-26: The code currently defensively normalizes nil FeeTokens
even though gs.Validate() already rejects nil FeeTokens; remove the unreachable
nil-normalization and directly set the stored fee tokens from the provided
genesis data. Replace the conditional that builds feeTokens :=
types.FeeTokenMetadataCollection{} / if gs.FeeTokens != nil ... with a direct
use of the validated pointer (i.e., pass *gs.FeeTokens into k.FeeTokens.Set),
referencing gs.Validate(), gs.FeeTokens, types.FeeTokenMetadataCollection, and
k.FeeTokens.Set(ctx, ...) to locate the change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 767a9bb1-f496-48ee-bd23-455a5e9c4a51
📒 Files selected for processing (4)
CHANGELOG.mdx/feeabstraction/keeper/genesis.gox/feeabstraction/types/genesis.gox/feeabstraction/types/genesis_test.go
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Description
Ensure that feetokens on genesis cannot be nil
Type of change
How Has This Been Tested?
Regression test
PR Checklist:
Make sure each step was done:
make lint-fix