fix: poa emit post-create validator tokens#139
Conversation
📝 WalkthroughWalkthrough
ChangesPost-Creation Token Emission
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions 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 |
1b853c5 to
83a8653
Compare
AdriaCarrera
left a comment
There was a problem hiding this comment.
It's better to remove the event attribute itself
There was a problem hiding this comment.
🧹 Nitpick comments (1)
x/poa/keeper/keeper_test.go (1)
418-423: ⚡ Quick winAvoid asserting on the last event index directly.
Using
events[len(events)-1]makes this test fragile if any later event is added. Search fortypes.EventTypeAddValidatorin the emitted events and assert on that match instead.Suggested test hardening
- event := events[len(events)-1] - require.Equal(t, types.EventTypeAddValidator, event.Type) - - attribute, ok := event.GetAttribute(types.AttributeStakingTokens) + var event sdk.Event + found := false + for i := len(events) - 1; i >= 0; i-- { + if events[i].Type == types.EventTypeAddValidator { + event = events[i] + found = true + break + } + } + require.True(t, found, "add_validator event not found") + + attribute, ok := event.GetAttribute(types.AttributeStakingTokens) require.True(t, ok) require.Equal(t, fmt.Sprintf("%d", sdk.DefaultPowerReduction), attribute.Value)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@x/poa/keeper/keeper_test.go` around lines 418 - 423, The test currently assumes the EventTypeAddValidator is the last emitted event by using events[len(events)-1]; instead, iterate or search the events slice for an event with Type == types.EventTypeAddValidator (e.g., loop over events or use a helper to find the first matching event), assert that such an event exists, then call event.GetAttribute(types.AttributeStakingTokens) and check the attribute.Value equals fmt.Sprintf("%d", sdk.DefaultPowerReduction); update the assertions in keeper_test.go to reference the found event rather than the last index to avoid fragility.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@x/poa/keeper/keeper_test.go`:
- Around line 418-423: The test currently assumes the EventTypeAddValidator is
the last emitted event by using events[len(events)-1]; instead, iterate or
search the events slice for an event with Type == types.EventTypeAddValidator
(e.g., loop over events or use a helper to find the first matching event),
assert that such an event exists, then call
event.GetAttribute(types.AttributeStakingTokens) and check the attribute.Value
equals fmt.Sprintf("%d", sdk.DefaultPowerReduction); update the assertions in
keeper_test.go to reference the found event rather than the last index to avoid
fragility.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5655b91c-1fb1-4f71-ac78-f3a5ddb7fccd
📒 Files selected for processing (1)
x/poa/keeper/keeper_test.go
fix: poa emit post-create validator tokens
Motivation 💡
ExecuteAddValidatoremittedstaking_tokensusing the validator state fetched beforeMsgCreateValidatorexecuted. That pre-create validator state has zero tokens, so theadd_validatorevent did not reflect the validator created in staking state.Changes 🛠
MsgCreateValidatorhandler succeeds.AttributeStakingTokensfrom the post-create validator state.add_validatorevent token value.Summary by CodeRabbit
Bug Fixes
Tests