2021-06-21 21:05:17 +00:00
|
|
|
package keeper_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
2024-08-03 09:51:56 +00:00
|
|
|
"github.com/0glabs/0g-chain/x/incentive/types"
|
2021-06-21 21:05:17 +00:00
|
|
|
)
|
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
// SynchronizeDelegatorRewardTests runs unit tests for the keeper.SynchronizeDelegatorReward method
|
2021-06-21 21:05:17 +00:00
|
|
|
//
|
|
|
|
// inputs
|
|
|
|
// - claim in store if it exists (only claim.DelegatorRewardIndexes and claim.Reward)
|
|
|
|
// - global index in store
|
|
|
|
// - function args: delegator address, validator address, shouldIncludeValidator flag
|
|
|
|
// - delegator's delegations and the corresponding validators
|
|
|
|
//
|
|
|
|
// outputs
|
|
|
|
// - sets or creates a claim
|
2021-07-07 16:50:14 +00:00
|
|
|
type SynchronizeDelegatorRewardTests struct {
|
2021-06-21 21:05:17 +00:00
|
|
|
unitTester
|
|
|
|
}
|
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
func TestSynchronizeDelegatorReward(t *testing.T) {
|
|
|
|
suite.Run(t, new(SynchronizeDelegatorRewardTests))
|
2021-06-21 21:05:17 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
func (suite *SynchronizeDelegatorRewardTests) storeGlobalDelegatorFactor(multiRewardIndexes types.MultiRewardIndexes) {
|
|
|
|
multiRewardIndex, _ := multiRewardIndexes.GetRewardIndex(types.BondDenom)
|
|
|
|
suite.keeper.SetDelegatorRewardIndexes(suite.ctx, types.BondDenom, multiRewardIndex.RewardIndexes)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *SynchronizeDelegatorRewardTests) TestClaimIndexesAreUnchangedWhenGlobalFactorUnchanged() {
|
2021-06-21 21:05:17 +00:00
|
|
|
delegator := arbitraryAddress()
|
|
|
|
|
2021-07-22 12:53:18 +00:00
|
|
|
stakingKeeper := &fakeStakingKeeper{} // use an empty staking keeper that returns no delegations
|
2022-09-23 16:38:22 +00:00
|
|
|
suite.keeper = suite.NewKeeper(&fakeParamSubspace{}, nil, nil, nil, nil, stakingKeeper, nil, nil, nil, nil)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
claim := types.DelegatorClaim{
|
2021-06-21 21:05:17 +00:00
|
|
|
BaseMultiClaim: types.BaseMultiClaim{
|
|
|
|
Owner: delegator,
|
|
|
|
},
|
2021-07-07 16:50:14 +00:00
|
|
|
RewardIndexes: arbitraryDelegatorRewardIndexes,
|
2021-06-21 21:05:17 +00:00
|
|
|
}
|
2021-07-07 16:50:14 +00:00
|
|
|
suite.storeDelegatorClaim(claim)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
suite.storeGlobalDelegatorFactor(claim.RewardIndexes)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
suite.keeper.SynchronizeDelegatorRewards(suite.ctx, claim.Owner, nil, false)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
syncedClaim, _ := suite.keeper.GetDelegatorClaim(suite.ctx, claim.Owner)
|
|
|
|
suite.Equal(claim.RewardIndexes, syncedClaim.RewardIndexes)
|
2021-06-21 21:05:17 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
func (suite *SynchronizeDelegatorRewardTests) TestClaimIndexesAreUpdatedWhenGlobalFactorIncreased() {
|
2021-06-21 21:05:17 +00:00
|
|
|
delegator := arbitraryAddress()
|
|
|
|
|
2022-09-23 16:38:22 +00:00
|
|
|
suite.keeper = suite.NewKeeper(&fakeParamSubspace{}, nil, nil, nil, nil, &fakeStakingKeeper{}, nil, nil, nil, nil)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
claim := types.DelegatorClaim{
|
2021-06-21 21:05:17 +00:00
|
|
|
BaseMultiClaim: types.BaseMultiClaim{
|
|
|
|
Owner: delegator,
|
|
|
|
},
|
2021-07-07 16:50:14 +00:00
|
|
|
RewardIndexes: arbitraryDelegatorRewardIndexes,
|
2021-06-21 21:05:17 +00:00
|
|
|
}
|
2021-07-07 16:50:14 +00:00
|
|
|
suite.storeDelegatorClaim(claim)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
rewardIndexes, _ := claim.RewardIndexes.Get(types.BondDenom)
|
2021-07-05 22:01:25 +00:00
|
|
|
globalIndexes := increaseRewardFactors(rewardIndexes)
|
|
|
|
|
|
|
|
// Update the claim object with the new global factor
|
2021-07-07 16:50:14 +00:00
|
|
|
bondIndex, _ := claim.RewardIndexes.GetRewardIndexIndex(types.BondDenom)
|
|
|
|
claim.RewardIndexes[bondIndex].RewardIndexes = globalIndexes
|
|
|
|
suite.storeGlobalDelegatorFactor(claim.RewardIndexes)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
suite.keeper.SynchronizeDelegatorRewards(suite.ctx, claim.Owner, nil, false)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
syncedClaim, _ := suite.keeper.GetDelegatorClaim(suite.ctx, claim.Owner)
|
|
|
|
suite.Equal(globalIndexes, syncedClaim.RewardIndexes[bondIndex].RewardIndexes)
|
2021-06-21 21:05:17 +00:00
|
|
|
}
|
2021-07-05 22:01:25 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
func (suite *SynchronizeDelegatorRewardTests) TestRewardIsUnchangedWhenGlobalFactorUnchanged() {
|
2021-06-21 21:05:17 +00:00
|
|
|
delegator := arbitraryAddress()
|
|
|
|
validatorAddress := arbitraryValidatorAddress()
|
2021-07-22 12:53:18 +00:00
|
|
|
stakingKeeper := &fakeStakingKeeper{
|
2021-06-21 21:05:17 +00:00
|
|
|
delegations: stakingtypes.Delegations{
|
|
|
|
{
|
2022-01-08 00:39:27 +00:00
|
|
|
DelegatorAddress: delegator.String(),
|
|
|
|
ValidatorAddress: validatorAddress.String(),
|
2021-06-21 21:05:17 +00:00
|
|
|
Shares: d("1000"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validators: stakingtypes.Validators{
|
|
|
|
unslashedBondedValidator(validatorAddress),
|
|
|
|
},
|
|
|
|
}
|
2022-09-23 16:38:22 +00:00
|
|
|
suite.keeper = suite.NewKeeper(&fakeParamSubspace{}, nil, nil, nil, nil, stakingKeeper, nil, nil, nil, nil)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
claim := types.DelegatorClaim{
|
2021-06-21 21:05:17 +00:00
|
|
|
BaseMultiClaim: types.BaseMultiClaim{
|
|
|
|
Owner: delegator,
|
|
|
|
Reward: arbitraryCoins(),
|
|
|
|
},
|
2021-07-07 16:50:14 +00:00
|
|
|
RewardIndexes: types.MultiRewardIndexes{{
|
2021-06-21 21:05:17 +00:00
|
|
|
CollateralType: types.BondDenom,
|
2021-07-05 22:01:25 +00:00
|
|
|
RewardIndexes: types.RewardIndexes{
|
|
|
|
{
|
|
|
|
CollateralType: "hard", RewardFactor: d("0.1"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CollateralType: "swp", RewardFactor: d("0.2"),
|
|
|
|
},
|
|
|
|
},
|
2021-06-21 21:05:17 +00:00
|
|
|
}},
|
|
|
|
}
|
2021-07-07 16:50:14 +00:00
|
|
|
suite.storeDelegatorClaim(claim)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
suite.storeGlobalDelegatorFactor(claim.RewardIndexes)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
suite.keeper.SynchronizeDelegatorRewards(suite.ctx, claim.Owner, nil, false)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
syncedClaim, _ := suite.keeper.GetDelegatorClaim(suite.ctx, claim.Owner)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
|
|
|
suite.Equal(claim.Reward, syncedClaim.Reward)
|
|
|
|
}
|
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
func (suite *SynchronizeDelegatorRewardTests) TestRewardIsIncreasedWhenNewRewardAdded() {
|
2021-06-21 21:05:17 +00:00
|
|
|
delegator := arbitraryAddress()
|
|
|
|
validatorAddress := arbitraryValidatorAddress()
|
2021-07-22 12:53:18 +00:00
|
|
|
stakingKeeper := &fakeStakingKeeper{
|
2021-06-21 21:05:17 +00:00
|
|
|
delegations: stakingtypes.Delegations{
|
|
|
|
{
|
2022-01-08 00:39:27 +00:00
|
|
|
DelegatorAddress: delegator.String(),
|
|
|
|
ValidatorAddress: validatorAddress.String(),
|
2021-06-21 21:05:17 +00:00
|
|
|
Shares: d("1000"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validators: stakingtypes.Validators{
|
|
|
|
unslashedBondedValidator(validatorAddress),
|
|
|
|
},
|
|
|
|
}
|
2022-09-23 16:38:22 +00:00
|
|
|
suite.keeper = suite.NewKeeper(&fakeParamSubspace{}, nil, nil, nil, nil, stakingKeeper, nil, nil, nil, nil)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
claim := types.DelegatorClaim{
|
2021-06-21 21:05:17 +00:00
|
|
|
BaseMultiClaim: types.BaseMultiClaim{
|
|
|
|
Owner: delegator,
|
|
|
|
Reward: arbitraryCoins(),
|
|
|
|
},
|
2021-07-07 16:50:14 +00:00
|
|
|
RewardIndexes: types.MultiRewardIndexes{},
|
2021-06-21 21:05:17 +00:00
|
|
|
}
|
2021-07-07 16:50:14 +00:00
|
|
|
suite.storeDelegatorClaim(claim)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-05 22:01:25 +00:00
|
|
|
newGlobalIndexes := types.MultiRewardIndexes{{
|
2021-06-21 21:05:17 +00:00
|
|
|
CollateralType: types.BondDenom,
|
2021-07-05 22:01:25 +00:00
|
|
|
RewardIndexes: types.RewardIndexes{
|
|
|
|
{
|
|
|
|
CollateralType: "hard", RewardFactor: d("0.1"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CollateralType: "swp", RewardFactor: d("0.2"),
|
|
|
|
},
|
|
|
|
},
|
2021-06-21 21:05:17 +00:00
|
|
|
}}
|
2021-07-07 13:23:06 +00:00
|
|
|
suite.storeGlobalDelegatorIndexes(newGlobalIndexes)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
suite.keeper.SynchronizeDelegatorRewards(suite.ctx, claim.Owner, nil, false)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
syncedClaim, _ := suite.keeper.GetDelegatorClaim(suite.ctx, claim.Owner)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
suite.Equal(newGlobalIndexes, syncedClaim.RewardIndexes)
|
2021-06-21 21:05:17 +00:00
|
|
|
suite.Equal(
|
2021-07-15 14:05:54 +00:00
|
|
|
cs(c("hard", 100), c("swp", 200)).Add(claim.Reward...),
|
2021-06-21 21:05:17 +00:00
|
|
|
syncedClaim.Reward,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
func (suite *SynchronizeDelegatorRewardTests) TestRewardIsIncreasedWhenGlobalFactorIncreased() {
|
2021-06-21 21:05:17 +00:00
|
|
|
delegator := arbitraryAddress()
|
|
|
|
validatorAddress := arbitraryValidatorAddress()
|
2021-07-22 12:53:18 +00:00
|
|
|
stakingKeeper := &fakeStakingKeeper{
|
2021-06-21 21:05:17 +00:00
|
|
|
delegations: stakingtypes.Delegations{
|
|
|
|
{
|
2022-01-08 00:39:27 +00:00
|
|
|
DelegatorAddress: delegator.String(),
|
|
|
|
ValidatorAddress: validatorAddress.String(),
|
2021-06-21 21:05:17 +00:00
|
|
|
Shares: d("1000"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validators: stakingtypes.Validators{
|
|
|
|
unslashedBondedValidator(validatorAddress),
|
|
|
|
},
|
|
|
|
}
|
2022-09-23 16:38:22 +00:00
|
|
|
suite.keeper = suite.NewKeeper(&fakeParamSubspace{}, nil, nil, nil, nil, stakingKeeper, nil, nil, nil, nil)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
claim := types.DelegatorClaim{
|
2021-06-21 21:05:17 +00:00
|
|
|
BaseMultiClaim: types.BaseMultiClaim{
|
|
|
|
Owner: delegator,
|
|
|
|
Reward: arbitraryCoins(),
|
|
|
|
},
|
2021-07-07 16:50:14 +00:00
|
|
|
RewardIndexes: types.MultiRewardIndexes{{
|
2021-06-21 21:05:17 +00:00
|
|
|
CollateralType: types.BondDenom,
|
2021-07-05 22:01:25 +00:00
|
|
|
RewardIndexes: types.RewardIndexes{
|
|
|
|
{
|
|
|
|
CollateralType: "hard", RewardFactor: d("0.1"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CollateralType: "swp", RewardFactor: d("0.2"),
|
|
|
|
},
|
|
|
|
},
|
2021-06-21 21:05:17 +00:00
|
|
|
}},
|
|
|
|
}
|
2021-07-07 16:50:14 +00:00
|
|
|
suite.storeDelegatorClaim(claim)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-07 13:23:06 +00:00
|
|
|
suite.storeGlobalDelegatorIndexes(
|
2021-07-05 22:01:25 +00:00
|
|
|
types.MultiRewardIndexes{
|
|
|
|
types.NewMultiRewardIndex(
|
|
|
|
types.BondDenom,
|
|
|
|
types.RewardIndexes{
|
|
|
|
{
|
|
|
|
CollateralType: "hard", RewardFactor: d("0.2"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
CollateralType: "swp", RewardFactor: d("0.4"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
2021-06-21 21:05:17 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
suite.keeper.SynchronizeDelegatorRewards(suite.ctx, claim.Owner, nil, false)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
syncedClaim, _ := suite.keeper.GetDelegatorClaim(suite.ctx, claim.Owner)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
|
|
|
suite.Equal(
|
2021-07-15 14:05:54 +00:00
|
|
|
cs(c("hard", 100), c("swp", 200)).Add(claim.Reward...),
|
2021-06-21 21:05:17 +00:00
|
|
|
syncedClaim.Reward,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func unslashedBondedValidator(address sdk.ValAddress) stakingtypes.Validator {
|
|
|
|
return stakingtypes.Validator{
|
2022-01-08 00:39:27 +00:00
|
|
|
OperatorAddress: address.String(),
|
|
|
|
Status: stakingtypes.Bonded,
|
2021-06-21 21:05:17 +00:00
|
|
|
|
|
|
|
// Set the tokens and shares equal so then
|
|
|
|
// a _delegator's_ token amount is equal to their shares amount
|
|
|
|
Tokens: i(1e12),
|
2023-04-04 00:08:45 +00:00
|
|
|
DelegatorShares: sdk.NewDec(1e12),
|
2021-06-21 21:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-09 18:37:36 +00:00
|
|
|
|
2021-06-21 21:05:17 +00:00
|
|
|
func unslashedNotBondedValidator(address sdk.ValAddress) stakingtypes.Validator {
|
|
|
|
return stakingtypes.Validator{
|
2022-01-08 00:39:27 +00:00
|
|
|
OperatorAddress: address.String(),
|
|
|
|
Status: stakingtypes.Unbonding,
|
2021-06-21 21:05:17 +00:00
|
|
|
|
|
|
|
// Set the tokens and shares equal so then
|
|
|
|
// a _delegator's_ token amount is equal to their shares amount
|
|
|
|
Tokens: i(1e12),
|
2023-04-04 00:08:45 +00:00
|
|
|
DelegatorShares: sdk.NewDec(1e12),
|
2021-06-21 21:05:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
func (suite *SynchronizeDelegatorRewardTests) TestGetDelegatedWhenValAddrIsNil() {
|
2021-06-21 21:05:17 +00:00
|
|
|
// when valAddr is nil, get total delegated to bonded validators
|
|
|
|
delegator := arbitraryAddress()
|
|
|
|
validatorAddresses := generateValidatorAddresses(4)
|
2021-07-22 12:53:18 +00:00
|
|
|
stakingKeeper := &fakeStakingKeeper{
|
2021-06-21 21:05:17 +00:00
|
|
|
delegations: stakingtypes.Delegations{
|
2022-05-09 18:37:36 +00:00
|
|
|
// bonded
|
2021-06-21 21:05:17 +00:00
|
|
|
{
|
2022-01-08 00:39:27 +00:00
|
|
|
DelegatorAddress: delegator.String(),
|
|
|
|
ValidatorAddress: validatorAddresses[0].String(),
|
2021-06-21 21:05:17 +00:00
|
|
|
Shares: d("1"),
|
|
|
|
},
|
|
|
|
{
|
2022-01-08 00:39:27 +00:00
|
|
|
DelegatorAddress: delegator.String(),
|
|
|
|
ValidatorAddress: validatorAddresses[1].String(),
|
2021-06-21 21:05:17 +00:00
|
|
|
Shares: d("10"),
|
|
|
|
},
|
|
|
|
// not bonded
|
|
|
|
{
|
2022-01-08 00:39:27 +00:00
|
|
|
DelegatorAddress: delegator.String(),
|
|
|
|
ValidatorAddress: validatorAddresses[2].String(),
|
2021-06-21 21:05:17 +00:00
|
|
|
Shares: d("100"),
|
|
|
|
},
|
|
|
|
{
|
2022-01-08 00:39:27 +00:00
|
|
|
DelegatorAddress: delegator.String(),
|
|
|
|
ValidatorAddress: validatorAddresses[3].String(),
|
2021-06-21 21:05:17 +00:00
|
|
|
Shares: d("1000"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validators: stakingtypes.Validators{
|
|
|
|
unslashedBondedValidator(validatorAddresses[0]),
|
|
|
|
unslashedBondedValidator(validatorAddresses[1]),
|
|
|
|
unslashedNotBondedValidator(validatorAddresses[2]),
|
|
|
|
unslashedNotBondedValidator(validatorAddresses[3]),
|
|
|
|
},
|
|
|
|
}
|
2022-09-23 16:38:22 +00:00
|
|
|
suite.keeper = suite.NewKeeper(&fakeParamSubspace{}, nil, nil, nil, nil, stakingKeeper, nil, nil, nil, nil)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
|
|
|
suite.Equal(
|
|
|
|
d("11"), // delegation to bonded validators
|
|
|
|
suite.keeper.GetTotalDelegated(suite.ctx, delegator, nil, false),
|
|
|
|
)
|
|
|
|
}
|
2022-05-09 18:37:36 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
func (suite *SynchronizeDelegatorRewardTests) TestGetDelegatedWhenExcludingAValidator() {
|
2021-06-21 21:05:17 +00:00
|
|
|
// when valAddr is x, get total delegated to bonded validators excluding those to x
|
|
|
|
delegator := arbitraryAddress()
|
|
|
|
validatorAddresses := generateValidatorAddresses(4)
|
2021-07-22 12:53:18 +00:00
|
|
|
stakingKeeper := &fakeStakingKeeper{
|
2021-06-21 21:05:17 +00:00
|
|
|
delegations: stakingtypes.Delegations{
|
2022-05-09 18:37:36 +00:00
|
|
|
// bonded
|
2021-06-21 21:05:17 +00:00
|
|
|
{
|
2022-01-08 00:39:27 +00:00
|
|
|
DelegatorAddress: delegator.String(),
|
|
|
|
ValidatorAddress: validatorAddresses[0].String(),
|
2021-06-21 21:05:17 +00:00
|
|
|
Shares: d("1"),
|
|
|
|
},
|
|
|
|
{
|
2022-01-08 00:39:27 +00:00
|
|
|
DelegatorAddress: delegator.String(),
|
|
|
|
ValidatorAddress: validatorAddresses[1].String(),
|
2021-06-21 21:05:17 +00:00
|
|
|
Shares: d("10"),
|
|
|
|
},
|
|
|
|
// not bonded
|
|
|
|
{
|
2022-01-08 00:39:27 +00:00
|
|
|
DelegatorAddress: delegator.String(),
|
|
|
|
ValidatorAddress: validatorAddresses[2].String(),
|
2021-06-21 21:05:17 +00:00
|
|
|
Shares: d("100"),
|
|
|
|
},
|
|
|
|
{
|
2022-01-08 00:39:27 +00:00
|
|
|
DelegatorAddress: delegator.String(),
|
|
|
|
ValidatorAddress: validatorAddresses[3].String(),
|
2021-06-21 21:05:17 +00:00
|
|
|
Shares: d("1000"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validators: stakingtypes.Validators{
|
|
|
|
unslashedBondedValidator(validatorAddresses[0]),
|
|
|
|
unslashedBondedValidator(validatorAddresses[1]),
|
|
|
|
unslashedNotBondedValidator(validatorAddresses[2]),
|
|
|
|
unslashedNotBondedValidator(validatorAddresses[3]),
|
|
|
|
},
|
|
|
|
}
|
2022-09-23 16:38:22 +00:00
|
|
|
suite.keeper = suite.NewKeeper(&fakeParamSubspace{}, nil, nil, nil, nil, stakingKeeper, nil, nil, nil, nil)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
|
|
|
suite.Equal(
|
|
|
|
d("10"),
|
|
|
|
suite.keeper.GetTotalDelegated(suite.ctx, delegator, validatorAddresses[0], false),
|
|
|
|
)
|
|
|
|
}
|
2022-05-09 18:37:36 +00:00
|
|
|
|
2021-07-07 16:50:14 +00:00
|
|
|
func (suite *SynchronizeDelegatorRewardTests) TestGetDelegatedWhenIncludingAValidator() {
|
2021-06-21 21:05:17 +00:00
|
|
|
// when valAddr is x, get total delegated to bonded validators including those to x
|
|
|
|
delegator := arbitraryAddress()
|
|
|
|
validatorAddresses := generateValidatorAddresses(4)
|
2021-07-22 12:53:18 +00:00
|
|
|
stakingKeeper := &fakeStakingKeeper{
|
2021-06-21 21:05:17 +00:00
|
|
|
delegations: stakingtypes.Delegations{
|
2022-05-09 18:37:36 +00:00
|
|
|
// bonded
|
2021-06-21 21:05:17 +00:00
|
|
|
{
|
2022-01-08 00:39:27 +00:00
|
|
|
DelegatorAddress: delegator.String(),
|
|
|
|
ValidatorAddress: validatorAddresses[0].String(),
|
2021-06-21 21:05:17 +00:00
|
|
|
Shares: d("1"),
|
|
|
|
},
|
|
|
|
{
|
2022-01-08 00:39:27 +00:00
|
|
|
DelegatorAddress: delegator.String(),
|
|
|
|
ValidatorAddress: validatorAddresses[1].String(),
|
2021-06-21 21:05:17 +00:00
|
|
|
Shares: d("10"),
|
|
|
|
},
|
|
|
|
// not bonded
|
|
|
|
{
|
2022-01-08 00:39:27 +00:00
|
|
|
DelegatorAddress: delegator.String(),
|
|
|
|
ValidatorAddress: validatorAddresses[2].String(),
|
2021-06-21 21:05:17 +00:00
|
|
|
Shares: d("100"),
|
|
|
|
},
|
|
|
|
{
|
2022-01-08 00:39:27 +00:00
|
|
|
DelegatorAddress: delegator.String(),
|
|
|
|
ValidatorAddress: validatorAddresses[3].String(),
|
2021-06-21 21:05:17 +00:00
|
|
|
Shares: d("1000"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
validators: stakingtypes.Validators{
|
|
|
|
unslashedBondedValidator(validatorAddresses[0]),
|
|
|
|
unslashedBondedValidator(validatorAddresses[1]),
|
|
|
|
unslashedNotBondedValidator(validatorAddresses[2]),
|
|
|
|
unslashedNotBondedValidator(validatorAddresses[3]),
|
|
|
|
},
|
|
|
|
}
|
2022-09-23 16:38:22 +00:00
|
|
|
suite.keeper = suite.NewKeeper(&fakeParamSubspace{}, nil, nil, nil, nil, stakingKeeper, nil, nil, nil, nil)
|
2021-06-21 21:05:17 +00:00
|
|
|
|
|
|
|
suite.Equal(
|
|
|
|
d("111"),
|
|
|
|
suite.keeper.GetTotalDelegated(suite.ctx, delegator, validatorAddresses[2], true),
|
|
|
|
)
|
|
|
|
}
|