-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix bugs in calculation of pool-service total delegator shares (#38
) ## Description This PR fixes a bug that pool-service total delegator shares were miscalculated by ignoring user preferences when a user modifies the delegation. This PR also implements the logic that clears total shares state when a service is deleted. Also, with #26 we changed the user preferences but didn't update `PoolServiceTotalDelegatorShares` accordingly. Normally this should've been done by hooks but since we don't call hooks in store migrations we need to do this manually. The best place to do this would be inside the fork handler. Please note that we might need to apply the same thing when upgrading the testnet in the future. <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### 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... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/milkyway-labs/milkyway/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://docs.cosmos.network/v0.44/building-modules/intro.html) - [ ] included the necessary unit and integration [tests](https://github.com/milkyway-labs/milkyway/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### 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... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
- Loading branch information
1 parent
e0ad42a
commit 1addfbe
Showing
6 changed files
with
254 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"github.com/milkyway-labs/milkyway/v7/app/testutil" | ||
"github.com/milkyway-labs/milkyway/v7/utils" | ||
restakingtypes "github.com/milkyway-labs/milkyway/v7/x/restaking/types" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestPoolServiceTotalDelegatorShares() { | ||
// Cache the context to avoid test conflicts | ||
ctx, _ := suite.ctx.CacheContext() | ||
|
||
suite.RegisterCurrency(ctx, "umilk", "umilk", 6, utils.MustParseDec("1")) | ||
|
||
// Create a service. | ||
serviceAdmin := testutil.TestAddress(10000) | ||
service := suite.CreateService(ctx, "Service", serviceAdmin.String()) | ||
|
||
// Alice by default trusts all services through all pools, so when Alice delegates | ||
// it increments pool-service total delegator shares of the pool. | ||
aliceAddr := testutil.TestAddress(1) | ||
suite.DelegatePool(ctx, utils.MustParseCoin("10_000000umilk"), aliceAddr.String(), true) | ||
|
||
shares, err := suite.keeper.GetPoolServiceTotalDelegatorShares(ctx, 1, service.ID) | ||
suite.Require().NoError(err) | ||
suite.Require().Equal(utils.MustParseDecCoins("10_000000pool/1/umilk"), shares) | ||
|
||
// Bob doesn't trust the service through the pool, so when Bob delegates it | ||
// doesn't increment pool-service total delegator shares of the pool. | ||
bobAddr := testutil.TestAddress(2) | ||
suite.SetUserPreferences(ctx, bobAddr.String(), []restakingtypes.TrustedServiceEntry{ | ||
restakingtypes.NewTrustedServiceEntry(1, []uint32{2}), | ||
}) | ||
suite.DelegatePool(ctx, utils.MustParseCoin("10_000000umilk"), bobAddr.String(), true) | ||
|
||
shares, err = suite.keeper.GetPoolServiceTotalDelegatorShares(ctx, 1, service.ID) | ||
suite.Require().NoError(err) | ||
suite.Require().Equal(utils.MustParseDecCoins("10_000000pool/1/umilk"), shares) | ||
|
||
// But when Bob decides to trust the service through the pool, it increments | ||
// the total shares. | ||
|
||
suite.SetUserPreferences(ctx, bobAddr.String(), []restakingtypes.TrustedServiceEntry{ | ||
restakingtypes.NewTrustedServiceEntry(1, []uint32{service.ID}), | ||
}) | ||
shares, err = suite.keeper.GetPoolServiceTotalDelegatorShares(ctx, 1, service.ID) | ||
suite.Require().NoError(err) | ||
suite.Require().Equal(utils.MustParseDecCoins("20_000000pool/1/umilk"), shares) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters