-
Notifications
You must be signed in to change notification settings - Fork 1
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
test: add x/services simulation tests #162
Conversation
x/rewards/keeper/invariants.go
Outdated
return false, nil | ||
}, | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
broken := count != expected | ||
broken := elements > 0 && count != expected |
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.
When the simulation test starts, this invariant fails due to the presence of services while PoolHistoricalRewards
is empty. I can't figure out how to resolve this issue properly. Any tips on how to address this would be greatly appreciated, @hallazzang.
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.
I guess this logic is incorrect: we should check
- the targets of pool delegations vs the pool historical rewards
- the targets of service delegation vs the service historical rewards
- the targets of operator delegations vs the operators historical rewards
But instead everything is checked against the pool historical rewards. Why is this the case @hallazzang?
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.
Also, if we need to make sure that there's an entry for each target, we should add a hook for AfterServiceCreated
, AfterPoolCreated
and AfterOperatorCreated
to make sure that we create the first entry for each one of them there. Otherwise, inside a genesis file having some services but not yet delegations, this invariant might fail.
This is the same thing that the Cosmos SDK does:
func (h Hooks) AfterValidatorCreated(ctx context.Context, valAddr sdk.ValAddress) error {
val, err := h.k.stakingKeeper.Validator(ctx, valAddr)
if err != nil {
return err
}
return h.k.initializeValidator(ctx, val)
}
I think we should have the same logic. Let me take care of adding this and fixing the invariant as well as adding unit tests.
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.
But instead everything is checked against the pool historical rewards. Why is this the case @hallazzang?
Sorry guys this absolutely seems a bug 😅
Otherwise, inside a genesis file having some services but not yet delegations, this invariant might fail.
Oh that's also true. I don't know why the invariant wasn't broken already? FYI, in our code, we're initializing each delegation target when the first delegation is being created.
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.
I have now completely changed how this works. Instead of initializing the delegation target when a delegation is created, I have added some hooks to the x/pools
, x/operators
and x/services
modules to make sure we initialize the x/rewards
data when these are created.
I have also added some hooks to make sure we clear the store data when a service/operator is deleted (it was missing as well).
Finally, I fixed the invariant and added the missing unit tests to make sure it breaks only when expected.
04e90b0
to
54bd043
Compare
Description
Depends-On: #161
Closes: MILK-130
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change