diff --git a/x/interchainstaking/keeper/delegation.go b/x/interchainstaking/keeper/delegation.go index 5ca0d2716..b7e61f9b3 100644 --- a/x/interchainstaking/keeper/delegation.go +++ b/x/interchainstaking/keeper/delegation.go @@ -168,6 +168,15 @@ func (k *Keeper) RemoveDelegation(ctx sdk.Context, chainID string, delegation ty return nil } +// RemovePerformanceDelegation removes a performance delegation. +func (k *Keeper) RemovePerformanceDelegation(ctx sdk.Context, chainID string, delegation types.Delegation) error { + delegatorAddress := delegation.GetDelegatorAddr() + + store := ctx.KVStore(k.storeKey) + store.Delete(types.GetPerformanceDelegationKey(chainID, delegatorAddress, delegation.GetValidatorAddr())) + return nil +} + // IterateDelegatorDelegations iterates through one delegator's delegations. func (k *Keeper) IterateDelegatorDelegations(ctx sdk.Context, chainID string, delegator sdk.AccAddress, cb func(delegation types.Delegation) (stop bool)) { store := ctx.KVStore(k.storeKey) diff --git a/x/interchainstaking/keeper/delegation_test.go b/x/interchainstaking/keeper/delegation_test.go index 6fd91d726..6f017c570 100644 --- a/x/interchainstaking/keeper/delegation_test.go +++ b/x/interchainstaking/keeper/delegation_test.go @@ -9,6 +9,7 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/quicksilver-zone/quicksilver/app" "github.com/quicksilver-zone/quicksilver/utils/addressutils" @@ -630,6 +631,70 @@ func (suite *KeeperTestSuite) TestFlushOutstandingDelegations() { } } +func (suite *KeeperTestSuite) TestPerformanceDelegation() { + quicksilver := suite.GetQuicksilverApp(suite.chainA) + ctx := suite.chainA.GetContext() + chainID := "quicksilver-1" + + // Set zone + quicksilver.InterchainstakingKeeper.SetZone(ctx, &icstypes.Zone{ + ConnectionId: "connection-test", + ChainId: chainID, + LocalDenom: "uqck", + BaseDenom: "qck", + DelegationAddress: &icstypes.ICAAccount{ + Address: addressutils.GenerateAddressForTestWithPrefix("quicksilver"), + }, + PerformanceAddress: &icstypes.ICAAccount{ + Address: addressutils.GenerateAddressForTestWithPrefix("quicksilver"), + }, + }) + // Check set zone + zone, ok := quicksilver.InterchainstakingKeeper.GetZone(ctx, chainID) + suite.True(ok, "expected to retrieve a zone") + suite.NotEqual(icstypes.Zone{}, zone, "Expecting a non-blank zone") + + // set val + val0 := icstypes.Validator{ValoperAddress: "cosmosvaloper1sjllsnramtg3ewxqwwrwjxfgc4n4ef9u2lcnj0", CommissionRate: sdk.MustNewDecFromStr("1"), VotingPower: sdk.NewInt(2000), Status: stakingtypes.BondStatusBonded} + err := quicksilver.InterchainstakingKeeper.SetValidator(ctx, zone.ChainId, val0) + suite.NoError(err) + + val1 := icstypes.Validator{ValoperAddress: "cosmosvaloper156gqf9837u7d4c4678yt3rl4ls9c5vuursrrzf", CommissionRate: sdk.MustNewDecFromStr("1"), VotingPower: sdk.NewInt(2000), Status: stakingtypes.BondStatusBonded} + err = quicksilver.InterchainstakingKeeper.SetValidator(ctx, zone.ChainId, val1) + suite.NoError(err) + + val2 := icstypes.Validator{ValoperAddress: "cosmosvaloper14lultfckehtszvzw4ehu0apvsr77afvyju5zzy", CommissionRate: sdk.MustNewDecFromStr("1"), VotingPower: sdk.NewInt(2000), Status: stakingtypes.BondStatusBonded} + err = quicksilver.InterchainstakingKeeper.SetValidator(ctx, zone.ChainId, val2) + suite.NoError(err) + + val3 := icstypes.Validator{ValoperAddress: "cosmosvaloper1z8zjv3lntpwxua0rtpvgrcwl0nm0tltgpgs6l7", CommissionRate: sdk.MustNewDecFromStr("1"), VotingPower: sdk.NewInt(2000), Status: stakingtypes.BondStatusBonded} + err = quicksilver.InterchainstakingKeeper.SetValidator(ctx, zone.ChainId, val3) + suite.NoError(err) + + vals := quicksilver.InterchainstakingKeeper.GetValidators(ctx, chainID) + + // create perf delegation + performanceAddress := zone.PerformanceAddress + perfDelegation := icstypes.Delegation{ + DelegationAddress: performanceAddress.Address, + ValidatorAddress: vals[1].ValoperAddress, + Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000)), + } + + // set and check get perf delegation + quicksilver.InterchainstakingKeeper.SetPerformanceDelegation(ctx, zone.ChainId, perfDelegation) + _, found := quicksilver.InterchainstakingKeeper.GetPerformanceDelegation(ctx, chainID, performanceAddress, perfDelegation.ValidatorAddress) + suite.True(found) + + // Handle remove perf delegation + err = quicksilver.InterchainstakingKeeper.RemovePerformanceDelegation(ctx, chainID, perfDelegation) + suite.NoError(err) + + // check perf delegation + _, found = quicksilver.InterchainstakingKeeper.GetPerformanceDelegation(ctx, chainID, performanceAddress, perfDelegation.ValidatorAddress) + suite.False(found, "Not found pert delegation stored in the keeper") +} + func (suite *KeeperTestSuite) TestDelegationPlan() { jsonDelegations, _ := base64.RawStdEncoding.DecodeString(delegationFixture) quicksilver := suite.GetQuicksilverApp(suite.chainA) diff --git a/x/interchainstaking/keeper/zones.go b/x/interchainstaking/keeper/zones.go index 3894b41b0..bd672b507 100644 --- a/x/interchainstaking/keeper/zones.go +++ b/x/interchainstaking/keeper/zones.go @@ -460,7 +460,7 @@ func (k *Keeper) RemoveZoneAndAssociatedRecords(ctx sdk.Context, chainID string) // remove performance delegation records k.IterateAllPerformanceDelegations(ctx, chainID, func(delegation types.Delegation) (stop bool) { - err := k.RemoveDelegation(ctx, chainID, delegation) + err := k.RemovePerformanceDelegation(ctx, chainID, delegation) if err != nil { panic(err) }