Skip to content

fix: ensure feetokens cannot be initialized as new#316

Merged
Thaleszh merged 3 commits into
mainfrom
fix/nil-feetoken
Apr 2, 2026
Merged

fix: ensure feetokens cannot be initialized as new#316
Thaleszh merged 3 commits into
mainfrom
fix/nil-feetoken

Conversation

@Thaleszh

@Thaleszh Thaleszh commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Description

Ensure that feetokens on genesis cannot be nil

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Regression test

PR Checklist:

Make sure each step was done:

  • Updated changelog with PR's intent
  • Lint with make lint-fix

@Thaleszh Thaleszh requested a review from jhelison as a code owner April 2, 2026 16:03
@coderabbitai

coderabbitai Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request adds nil-safety checks for FeeTokens at genesis initialization. The changes introduce explicit validation to reject nil FeeTokens in GenesisState.Validate(), modify Keeper.InitGenesis to safely handle nil values by treating them as empty collections, add corresponding test coverage for the nil case, and update the changelog to document the fix.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: preventing feeTokens from being initialized as nil at genesis, which aligns with the primary fix across genesis.go and types/genesis.go.
Description check ✅ Passed The description accurately relates to the changeset by stating the intent to ensure feetokens cannot be nil at genesis, matching the modifications in validation and initialization logic.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/nil-feetoken

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 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 rejects nil FeeTokens, 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

📥 Commits

Reviewing files that changed from the base of the PR and between cc35d9a and a8dd08e.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • x/feeabstraction/keeper/genesis.go
  • x/feeabstraction/types/genesis.go
  • x/feeabstraction/types/genesis_test.go

@codecov

codecov Bot commented Apr 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
x/feeabstraction/keeper/genesis.go 0.00% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Thaleszh Thaleszh merged commit 988d05f into main Apr 2, 2026
9 of 10 checks passed
@Thaleszh Thaleszh deleted the fix/nil-feetoken branch April 2, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants