-
Notifications
You must be signed in to change notification settings - Fork 40
fix: correctly export policy in genesis #269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds genesis initialization for MultiCoinDistributionPolicy in x/multi_coin_rewards, updates related tests to verify empty policy state instead of retrieval errors after invalid updates, and amends CHANGELOG with scoped module notation and a bug fix entry. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant App
participant Module as x/multi_coin_rewards
participant Keeper
participant Store
App->>Module: InitGenesis(genState)
Module->>Keeper: SetQueueState(...)
Module->>Keeper: Set(MultiCoinDistributionPolicy from genState)
alt policy provided
Keeper->>Store: Write policy
Store-->>Keeper: OK
Keeper-->>Module: nil error
else policy missing / nil
Module->>Module: Potential nil deref (panic)
end
Module-->>App: Init complete (or panic)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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/multi_coin_rewards/keeper/msg_server_distribution_policy_test.go (1)
211-219: “Zero weights” test uses -1 instead of 0 — fix to actually test zero.The scenario name says “Zero weights” but the data sets the weight to -1 again. Set it to "0" so the test covers the intended case.
Apply this diff:
- Weight: math.LegacyMustNewDecFromStr("-1"), + Weight: math.LegacyMustNewDecFromStr("0"),
🧹 Nitpick comments (6)
x/multi_coin_rewards/genesis.go (1)
42-47: Optional: make ExportGenesis resilient to missing policy.Right now, export panics on any
Geterror. With the InitGenesis fix this should be fine, but if ExportGenesis can be called in tests before policy is set, consider treating “not found” as an empty policy while still panicking on other errors. This is optional since the InitGenesis guard already ensures presence in normal flows.x/multi_coin_rewards/keeper/msg_server_distribution_policy_test.go (5)
129-134: Strengthen assertion: check error presence before inspecting message; keep state assertion.Prevent potential nil dereference if the tx unexpectedly succeeds by asserting
HaveOccurred()first.Apply this diff:
- // ASSERT - Expect(err.Error()).To(Equal("duplicate entry for denom acoin")) + // ASSERT + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(Equal("duplicate entry for denom acoin")) policy, err := s.App().MultiCoinRewardsKeeper.MultiCoinDistributionPolicy.Get(s.Ctx()) Expect(err).To(BeNil()) Expect(policy.Entries).To(HaveLen(0))
171-174: Repeat the nil-safety assertion for duplicate pool entries case.Same reasoning as above.
Apply this diff:
- // ASSERT - Expect(err.Error()).To(Equal("duplicate distribution weight for pool id 0")) + // ASSERT + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(Equal("duplicate distribution weight for pool id 0")) policy, err := s.App().MultiCoinRewardsKeeper.MultiCoinDistributionPolicy.Get(s.Ctx()) Expect(err).To(BeNil()) Expect(policy.Entries).To(HaveLen(0))
199-202: Repeat the nil-safety assertion for negative weights case.Same reasoning as above.
Apply this diff:
- // ASSERT - Expect(err.Error()).To(Equal("invalid weight for pool id 0")) + // ASSERT + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(Equal("invalid weight for pool id 0")) policy, err := s.App().MultiCoinRewardsKeeper.MultiCoinDistributionPolicy.Get(s.Ctx()) Expect(err).To(BeNil()) Expect(policy.Entries).To(HaveLen(0))
225-230: Repeat the nil-safety assertion for zero weights case.Same reasoning as the other invalid policy tests.
Apply this diff:
- // ASSERT - Expect(err.Error()).To(Equal("invalid weight for pool id 0")) + // ASSERT + Expect(err).To(HaveOccurred()) + Expect(err.Error()).To(Equal("invalid weight for pool id 0")) policy, err := s.App().MultiCoinRewardsKeeper.MultiCoinDistributionPolicy.Get(s.Ctx()) Expect(err).To(BeNil()) Expect(policy.Entries).To(HaveLen(0))
56-94: Nice: post-update verification checks the normalized distribution map.Valid-case assertions look good and exercise the parsing logic. Consider also asserting a couple of exact per-denom totals to catch future normalization regressions (optional).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
CHANGELOG.md(1 hunks)x/multi_coin_rewards/genesis.go(1 hunks)x/multi_coin_rewards/keeper/msg_server_distribution_policy_test.go(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
x/multi_coin_rewards/genesis.go (1)
x/multi_coin_rewards/types/types.pb.go (3)
MultiCoinDistributionPolicy(162-164)MultiCoinDistributionPolicy(168-168)MultiCoinDistributionPolicy(169-171)
x/multi_coin_rewards/keeper/msg_server_distribution_policy_test.go (2)
app/app.go (1)
App(116-165)x/multi_coin_rewards/types/types.pb.go (3)
MultiCoinDistributionPolicy(162-164)MultiCoinDistributionPolicy(168-168)MultiCoinDistributionPolicy(169-171)
⏰ 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). (3)
- GitHub Check: Summary
- GitHub Check: lint / golangci
- GitHub Check: test / test
🔇 Additional comments (1)
CHANGELOG.md (1)
21-26: Changelog entry scope and placement look correct.
- Scoped the storage payout improvement to
x/bundles.- Added a clear Bug Fix entry for
x/multi_coin_rewards.Nothing else to change here.
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests