fix(oracle): fix wrong nil check in ValidateFeeder function#255
Conversation
WalkthroughThis pull request corrects a logic error in the ValidateFeeder function within the oracle module's keeper. The fix changes a nil check from validating Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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: 2
🤖 Fix all issues with AI agents
In `@CHANGELOG.md`:
- Around line 128-129: The changelog bug fix entry "* **oracle:** fix wrong nil
check in ValidateFeeder function
([`#250`](https://github.com/KiiChain/kiichain/issues/250))" is currently under
v2.0.0's "### Changed" section; move that exact entry out of lines shown and add
it into the existing "## Fixed" subsection under "## UNRELEASED" (place it after
the other entries in that section) so the fix is recorded in the unreleased
fixed list.
In `@x/oracle/validate_feeder_test.go`:
- Around line 38-39: The test misrepresents the original buggy pattern in
ValidateFeeder: update the test so keeperPattern mirrors the actual buggy
conditional used in ValidateFeeder (which directly calls validator.IsBonded()
without a nil check) by removing the guarded check involving validator != nil
and making the condition use valAddr and validator.IsBonded() exactly as in the
bug; reference the ValidateFeeder logic, the keeperPattern variable, valAddr and
validator.IsBonded() so the test will reproduce the nil-validator panic scenario
and fail when validator is nil.
🧹 Nitpick comments (1)
x/oracle/validate_feeder_test.go (1)
14-31: Tests document the bug but don't provide regression protection.These tests demonstrate the bug conceptually but don't actually invoke
ValidateFeederwith a mockStakingKeeperthat returns(nil, nil). Consider adding an integration test that:
- Sets up a keeper with a mock
StakingKeeper- Configures the mock to return
(nil, nil)for a validvalAddr- Calls
ValidateFeederand asserts it returnsErrNoValidatorFoundThis would catch regressions if the nil check is accidentally reverted.
de58ccc to
5a6d79b
Compare
Fixes KiiChain#250 - Change valAddr == nil to validator == nil check - Add test case to verify fix and demonstrate bug - valAddr is function parameter, never nil - validator can be nil from StakingKeeper.Validator() - Update CHANGELOG.md with proper UNRELEASED entry - Address CodeRabbit actionable comments
3006b63 to
9df1e34
Compare
Thaleszh
left a comment
There was a problem hiding this comment.
Good to merge once AI test is removed
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Description
Fixed wrong nil check in ValidateFeeder function.
The bug: code checks
valAddr == nilbut this never happens because valAddr is a function parameter. Should checkvalidator == nilinstead.Changed line 188 in
x/oracle/keeper/keeper.gofrom checking valAddr to checking validator.Fixes #250
Type of change
How Has This Been Tested?
TestValidateFeederNilCheckBugtest case to verify the bug existsTest configuration: Go 1.23, kiichain v6.1.1
PR Checklist: