-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: find avail for all validators, not just those with delegations (#…
…975)
- Loading branch information
Joe Bowman
authored
Dec 29, 2023
1 parent
385906d
commit 3c0ae1d
Showing
2 changed files
with
104 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package keeper_test | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/quicksilver-zone/quicksilver/x/interchainstaking/types" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestGetUnlockedTokensForZoneAllHaveDelegation() { | ||
suite.SetupTest() | ||
suite.setupTestZones() | ||
|
||
quicksilver := suite.GetQuicksilverApp(suite.chainA) | ||
ctx := suite.chainA.GetContext() | ||
|
||
zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) | ||
vals := quicksilver.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId) | ||
suite.True(found) | ||
|
||
quicksilver.InterchainstakingKeeper.SetDelegation(ctx, zone.ChainId, types.NewDelegation(zone.DelegationAddress.Address, vals[0].ValoperAddress, sdk.NewCoin(zone.BaseDenom, sdk.NewInt(100)))) | ||
quicksilver.InterchainstakingKeeper.SetDelegation(ctx, zone.ChainId, types.NewDelegation(zone.DelegationAddress.Address, vals[1].ValoperAddress, sdk.NewCoin(zone.BaseDenom, sdk.NewInt(100)))) | ||
quicksilver.InterchainstakingKeeper.SetDelegation(ctx, zone.ChainId, types.NewDelegation(zone.DelegationAddress.Address, vals[2].ValoperAddress, sdk.NewCoin(zone.BaseDenom, sdk.NewInt(100)))) | ||
quicksilver.InterchainstakingKeeper.SetDelegation(ctx, zone.ChainId, types.NewDelegation(zone.DelegationAddress.Address, vals[3].ValoperAddress, sdk.NewCoin(zone.BaseDenom, sdk.NewInt(100)))) | ||
|
||
availPerVal, total, err := quicksilver.InterchainstakingKeeper.GetUnlockedTokensForZone(ctx, &zone) | ||
suite.NoError(err) | ||
suite.Equal(sdk.NewInt(400), total) | ||
for _, x := range availPerVal { | ||
suite.Equal(sdk.NewInt(100), x) | ||
} | ||
} | ||
|
||
func (suite *KeeperTestSuite) TestGetUnlockedTokensForZoneNotAllHaveDelegation() { | ||
suite.SetupTest() | ||
suite.setupTestZones() | ||
|
||
quicksilver := suite.GetQuicksilverApp(suite.chainA) | ||
ctx := suite.chainA.GetContext() | ||
|
||
zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) | ||
vals := quicksilver.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId) | ||
suite.True(found) | ||
|
||
quicksilver.InterchainstakingKeeper.SetDelegation(ctx, zone.ChainId, types.NewDelegation(zone.DelegationAddress.Address, vals[0].ValoperAddress, sdk.NewCoin(zone.BaseDenom, sdk.NewInt(100)))) | ||
quicksilver.InterchainstakingKeeper.SetDelegation(ctx, zone.ChainId, types.NewDelegation(zone.DelegationAddress.Address, vals[1].ValoperAddress, sdk.NewCoin(zone.BaseDenom, sdk.NewInt(100)))) | ||
quicksilver.InterchainstakingKeeper.SetDelegation(ctx, zone.ChainId, types.NewDelegation(zone.DelegationAddress.Address, vals[2].ValoperAddress, sdk.NewCoin(zone.BaseDenom, sdk.NewInt(100)))) | ||
|
||
availPerVal, total, err := quicksilver.InterchainstakingKeeper.GetUnlockedTokensForZone(ctx, &zone) | ||
suite.NoError(err) | ||
suite.Equal(sdk.NewInt(300), total) | ||
|
||
// ensure all vals exist in list, even if no delegation | ||
for _, v := range vals { | ||
_, found := availPerVal[v.ValoperAddress] | ||
suite.True(found) | ||
} | ||
} | ||
|
||
func (suite *KeeperTestSuite) TestGetUnlockedTokensForZoneWithRedelegation() { | ||
suite.SetupTest() | ||
suite.setupTestZones() | ||
|
||
quicksilver := suite.GetQuicksilverApp(suite.chainA) | ||
ctx := suite.chainA.GetContext() | ||
|
||
zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID) | ||
vals := quicksilver.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId) | ||
suite.True(found) | ||
|
||
quicksilver.InterchainstakingKeeper.SetDelegation(ctx, zone.ChainId, types.NewDelegation(zone.DelegationAddress.Address, vals[0].ValoperAddress, sdk.NewCoin(zone.BaseDenom, sdk.NewInt(100)))) | ||
quicksilver.InterchainstakingKeeper.SetDelegation(ctx, zone.ChainId, types.NewDelegation(zone.DelegationAddress.Address, vals[1].ValoperAddress, sdk.NewCoin(zone.BaseDenom, sdk.NewInt(100)))) | ||
quicksilver.InterchainstakingKeeper.SetDelegation(ctx, zone.ChainId, types.NewDelegation(zone.DelegationAddress.Address, vals[2].ValoperAddress, sdk.NewCoin(zone.BaseDenom, sdk.NewInt(100)))) | ||
quicksilver.InterchainstakingKeeper.SetDelegation(ctx, zone.ChainId, types.NewDelegation(zone.DelegationAddress.Address, vals[3].ValoperAddress, sdk.NewCoin(zone.BaseDenom, sdk.NewInt(100)))) | ||
|
||
quicksilver.InterchainstakingKeeper.SetRedelegationRecord(ctx, types.RedelegationRecord{ChainId: zone.ChainId, EpochNumber: 1, Source: vals[0].ValoperAddress, Destination: vals[2].ValoperAddress, Amount: 5}) | ||
quicksilver.InterchainstakingKeeper.SetRedelegationRecord(ctx, types.RedelegationRecord{ChainId: zone.ChainId, EpochNumber: 2, Source: vals[0].ValoperAddress, Destination: vals[2].ValoperAddress, Amount: 5}) | ||
quicksilver.InterchainstakingKeeper.SetRedelegationRecord(ctx, types.RedelegationRecord{ChainId: zone.ChainId, EpochNumber: 2, Source: vals[1].ValoperAddress, Destination: vals[2].ValoperAddress, Amount: 5}) | ||
|
||
availPerVal, total, err := quicksilver.InterchainstakingKeeper.GetUnlockedTokensForZone(ctx, &zone) | ||
suite.NoError(err) | ||
suite.Equal(sdk.NewInt(385), total) | ||
suite.Equal(sdk.NewInt(85), availPerVal[vals[2].ValoperAddress]) | ||
} |