Skip to content

Commit

Permalink
fix errors for GetDelegation
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic committed May 21, 2024
1 parent 7c213f8 commit c780c73
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion x/superfluid/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func (q Querier) EstimateSuperfluidDelegatedAmountByValidatorDenom(goCtx context

delegation, err := q.Keeper.sk.GetDelegation(ctx, intermediaryAcc.GetAccAddress(), valAddr)
if err != nil {
return nil, stakingtypes.ErrNoDelegation
return nil, err
}

syntheticOsmoAmt := delegation.Shares.Quo(val.DelegatorShares).MulInt(val.Tokens)
Expand Down
14 changes: 7 additions & 7 deletions x/superfluid/keeper/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (s *KeeperTestSuite) TestRouteLockedBalancerToConcentratedMigration() {

// The delegation from the balancer intermediary account holder should not exist.
delegation, error := stakingKeeper.GetDelegation(s.Ctx, balancerIntermediaryAcc.GetAccAddress(), valAddr)
s.Require().Error(error, "expected no delegation, found delegation w/ %d shares", delegation.Shares)
s.Require().Error(error, "expected error, found delegation w/ %d shares", delegation.Shares)

// Check that the original gamm lockup is deleted.
_, err := s.App.LockupKeeper.GetLockByID(s.Ctx, originalGammLockId)
Expand All @@ -212,7 +212,7 @@ func (s *KeeperTestSuite) TestRouteLockedBalancerToConcentratedMigration() {

// The delegation from the balancer intermediary account holder should still exist.
delegation, err := stakingKeeper.GetDelegation(s.Ctx, balancerIntermediaryAcc.GetAccAddress(), valAddr)
s.Require().NoError(err, "expected delegation, found delegation no delegation")
s.Require().NoError(err, "expected delegation, got error instead")
s.Require().Equal(balancerDelegationPre.Shares.Sub(balancerDelegationPre.Shares.Mul(tc.percentOfSharesToMigrate)).RoundInt().String(), delegation.Shares.RoundInt().String(), "expected %d shares, found %d shares", balancerDelegationPre.Shares.Mul(tc.percentOfSharesToMigrate).RoundInt().String(), delegation.Shares.String())

// Check what is remaining in the original gamm lock.
Expand All @@ -223,7 +223,7 @@ func (s *KeeperTestSuite) TestRouteLockedBalancerToConcentratedMigration() {
// Check the new superfluid staked amount.
clIntermediaryAcc := superfluidKeeper.GetLockIdIntermediaryAccountConnection(s.Ctx, concentratedLockId)
delegation, err := stakingKeeper.GetDelegation(s.Ctx, clIntermediaryAcc, valAddr)
s.Require().NoError(err, "expected delegation, found delegation no delegation")
s.Require().NoError(err, "expected delegation, got error instead")
s.Require().Equal(balancerDelegationPre.Shares.Mul(tc.percentOfSharesToMigrate).RoundInt().Sub(osmomath.OneInt()).String(), delegation.Shares.RoundInt().String(), "expected %d shares, found %d shares", balancerDelegationPre.Shares.Mul(tc.percentOfSharesToMigrate).RoundInt().String(), delegation.Shares.String())
}

Expand All @@ -241,7 +241,7 @@ func (s *KeeperTestSuite) TestRouteLockedBalancerToConcentratedMigration() {

// The delegation from the intermediary account holder does not exist.
delegation, err := stakingKeeper.GetDelegation(s.Ctx, balancerIntermediaryAcc.GetAccAddress(), valAddr)
s.Require().Error(err, "expected no delegation, found delegation w/ %d shares", delegation.Shares)
s.Require().Error(err, "expected error, found delegation w/ %d shares", delegation.Shares)
}

// Run slashing logic if the test case involves locks and check if the new and old locks are slashed.
Expand Down Expand Up @@ -356,7 +356,7 @@ func (s *KeeperTestSuite) TestMigrateSuperfluidBondedBalancerToConcentrated() {

// The delegation from the intermediary account holder should not exist.
delegation, err := stakingKeeper.GetDelegation(s.Ctx, balancerIntermediaryAcc.GetAccAddress(), valAddr)
s.Require().Error(err, "expected no delegation, found delegation w/ %d shares", delegation.Shares)
s.Require().Error(err, "expected error, found delegation w/ %d shares", delegation.Shares)

// Check that the original gamm lockup is deleted.
_, err = s.App.LockupKeeper.GetLockByID(s.Ctx, originalGammLockId)
Expand All @@ -375,7 +375,7 @@ func (s *KeeperTestSuite) TestMigrateSuperfluidBondedBalancerToConcentrated() {

// The delegation from the intermediary account holder should still exist.
_, err = stakingKeeper.GetDelegation(s.Ctx, balancerIntermediaryAcc.GetAccAddress(), valAddr)
s.Require().NoError(err, "expected delegation, found delegation no delegation")
s.Require().NoError(err, "expected delegation, got error instead")

// Check what is remaining in the original gamm lock.
lock, err := s.App.LockupKeeper.GetLockByID(s.Ctx, originalGammLockId)
Expand All @@ -385,7 +385,7 @@ func (s *KeeperTestSuite) TestMigrateSuperfluidBondedBalancerToConcentrated() {
// Check the new superfluid staked amount.
clIntermediaryAcc := superfluidKeeper.GetLockIdIntermediaryAccountConnection(s.Ctx, concentratedLockId)
delegation, err := stakingKeeper.GetDelegation(s.Ctx, clIntermediaryAcc, valAddr)
s.Require().NoError(err, "expected delegation, found delegation no delegation")
s.Require().NoError(err, "expected delegation, got error instead")
s.Require().Equal(balancerDelegationPre.Shares.Mul(tc.percentOfSharesToMigrate).RoundInt().Sub(osmomath.OneInt()).String(), delegation.Shares.RoundInt().String(), "expected %d shares, found %d shares", balancerDelegationPre.Shares.Mul(tc.percentOfSharesToMigrate).RoundInt().String(), delegation.Shares.String())

// Check if the new intermediary account connection was created.
Expand Down
5 changes: 2 additions & 3 deletions x/superfluid/keeper/stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ func (k Keeper) RefreshIntermediaryDelegationAmounts(context context.Context, ac
currentAmount := osmomath.NewInt(0)
delegation, err := k.sk.GetDelegation(ctx, mAddr, valAddress)
if err != nil {
// continue if current delegation is 0, in case its really a dust delegation
// continue if current delegation return an error, in case its really a dust delegation
// that becomes worth something after refresh.
// TODO: We have a correct explanation for this in some github issue, lets amend this correctly.
k.Logger(ctx).Debug(fmt.Sprintf("Existing delegation not found for %s with %s during superfluid refresh."+
" It may have been previously bonded, but now unbonded.", mAddr.String(), acc.ValAddr))
k.Logger(ctx).Debug(err.Error())
} else {
currentAmount = validator.TokensFromShares(delegation.Shares).RoundInt()
}
Expand Down
8 changes: 4 additions & 4 deletions x/superfluid/keeper/stake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func (s *KeeperTestSuite) TestSuperfluidUndelegate() {
s.Require().NoError(err)
delegation, err := s.App.StakingKeeper.GetDelegation(s.Ctx, acc.GetAccAddress(), valAddr)
if expDelegation.IsZero() {
s.Require().Error(err, "expected no delegation, found delegation w/ %d shares", delegation.Shares)
s.Require().Error(err, "expected error, found delegation w/ %d shares", delegation.Shares)
} else {
s.Require().NoError(err)
s.Require().Equal(expDelegation, delegation.Shares)
Expand Down Expand Up @@ -611,7 +611,7 @@ func (s *KeeperTestSuite) TestSuperfluidUndelegateToConcentratedPosition() {
s.Require().NoError(err)
delegation, err := s.App.StakingKeeper.GetDelegation(s.Ctx, acc.GetAccAddress(), valAddr)
if expDelegation.IsZero() {
s.Require().Error(err, "expected no delegation, found delegation w/ %d shares", delegation.Shares)
s.Require().Error(err, "expected error, found delegation w/ %d shares", delegation.Shares)
} else {
s.Require().NoError(err)
s.Require().Equal(expDelegation, delegation.Shares)
Expand Down Expand Up @@ -1931,8 +1931,8 @@ func (s *KeeperTestSuite) getExpectedBondDenomPoolAmtAfterConvert(sender sdk.Acc
// s.Require().Equal(intAcc.String(), expAcc.GetAccAddress().String())

// // check delegation from intermediary account to validator
// _, found := s.App.StakingKeeper.GetDelegation(s.Ctx, expAcc.GetAccAddress(), valAddrs[srd.newValIndex])
// s.Require().True(found)
// _, err := s.App.StakingKeeper.GetDelegation(s.Ctx, expAcc.GetAccAddress(), valAddrs[srd.newValIndex])
// s.Require().NoError(err)
// }

// // try redelegating twice
Expand Down
2 changes: 1 addition & 1 deletion x/superfluid/keeper/unpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (s *KeeperTestSuite) TestUnpool() {

// check if delegation has reduced from intermediary account
delegation, err := stakingKeeper.GetDelegation(ctx, intermediaryAcc.GetAccAddress(), valAddr)
s.Require().Error(err, "expected no delegation, found delegation w/ %d shares", delegation.Shares)
s.Require().Error(err, "expected err, instead found delegation w/ %d shares", delegation.Shares)
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions x/valset-pref/simulation/sim_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func RandomMsgUnDelegateFromValSet(k valsetkeeper.Keeper, sim *osmosimtypes.SimC
// check if the user has delegated tokens to the valset
del, err := sim.SDKStakingKeeper().GetDelegation(ctx, delAddr, val)
if err != nil {
return nil, fmt.Errorf("user hasn't delegated tokens to the validator, %s", val.String())
return nil, err
}

totalBond := validator.TokensFromShares(del.GetShares()).TruncateInt()
Expand Down Expand Up @@ -129,7 +129,7 @@ func RandomMsgReDelegateToValSet(k valsetkeeper.Keeper, sim *osmosimtypes.SimCtx
// check if the user has delegated tokens to the valset
_, err = sim.SDKStakingKeeper().GetDelegation(ctx, delAddr, val)
if err != nil {
return nil, fmt.Errorf("user hasn't delegated tokens to the validator, %s", val.String())
return nil, err
}
}

Expand Down
6 changes: 3 additions & 3 deletions x/valset-pref/validator_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (k Keeper) UndelegateFromRebalancedValidatorSet(ctx sdk.Context, delegatorA
// in the event some rounding issue increases our calculated undelegation amount.
delegation, err := k.stakingKeeper.GetDelegation(ctx, delegator, val.ValAddr)
if err != nil {
return fmt.Errorf("No delegation found for delegator %s to validator %s\n", delegator, val.ValAddr)
return err
}
delegationToVal := delegation.Shares.TruncateInt()
calculatedUndelegationAmt := undelegation.Amount.Sub(totalUnDelAmt).ToLegacyDec().TruncateInt()
Expand Down Expand Up @@ -335,7 +335,7 @@ func (k Keeper) getValsetRatios(ctx sdk.Context, delegator sdk.AccAddress,

delegation, err := k.stakingKeeper.GetDelegation(ctx, delegator, valAddr)
if err != nil {
return nil, map[string]stakingtypes.Validator{}, osmomath.ZeroDec(), fmt.Errorf("No delegation found for delegator %s to validator %s\n", delegator, valAddr)
return nil, map[string]stakingtypes.Validator{}, osmomath.ZeroDec(), err
}

undelegateSharesAmt, err := validator.SharesFromTokens(amountToUnDelegate)
Expand Down Expand Up @@ -388,7 +388,7 @@ func (k Keeper) PreformRedelegation(ctx sdk.Context, delegator sdk.AccAddress, e
// check if the user has delegated tokens to the valset
delegation, err := k.stakingKeeper.GetDelegation(ctx, delegator, valAddr)
if err != nil {
return fmt.Errorf("No delegation found")
return err
}

tokenFromShares := validator.TokensFromShares(delegation.Shares)
Expand Down

0 comments on commit c780c73

Please sign in to comment.