chore: gofumpt (#11839)
* fumpt using main not master... * be more descriptive * fumpt * fix nits Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
co-authored by
Julien Robert
parent
bc2d553f77
commit
55054282d2
@@ -26,7 +26,6 @@ func checkDelegation(
|
||||
t *testing.T, app *simapp.SimApp, delegatorAddr sdk.AccAddress,
|
||||
validatorAddr sdk.ValAddress, expFound bool, expShares sdk.Dec,
|
||||
) {
|
||||
|
||||
ctxCheck := app.BaseApp.NewContext(true, tmproto.Header{})
|
||||
delegation, found := app.StakingKeeper.GetDelegation(ctxCheck, delegatorAddr, validatorAddr)
|
||||
if expFound {
|
||||
|
||||
@@ -549,7 +549,6 @@ func PrepareConfigForTxCreateValidator(flagSet *flag.FlagSet, moniker, nodeID, c
|
||||
func BuildCreateValidatorMsg(clientCtx client.Context, config TxCreateValidatorConfig, txBldr tx.Factory, generateOnly bool) (tx.Factory, sdk.Msg, error) {
|
||||
amounstStr := config.Amount
|
||||
amount, err := sdk.ParseCoinNormalized(amounstStr)
|
||||
|
||||
if err != nil {
|
||||
return txBldr, nil, err
|
||||
}
|
||||
@@ -568,7 +567,6 @@ func BuildCreateValidatorMsg(clientCtx client.Context, config TxCreateValidatorC
|
||||
maxRateStr := config.CommissionMaxRate
|
||||
maxChangeRateStr := config.CommissionMaxChangeRate
|
||||
commissionRates, err := buildCommissionRates(rateStr, maxRateStr, maxChangeRateStr)
|
||||
|
||||
if err != nil {
|
||||
return txBldr, nil, err
|
||||
}
|
||||
|
||||
@@ -43,25 +43,29 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {
|
||||
return
|
||||
},
|
||||
expectedCfg: mkTxValCfg(defaultAmount, "0.1", "0.2", "0.01", "1"),
|
||||
}, {
|
||||
},
|
||||
{
|
||||
name: "Custom amount",
|
||||
fsModify: func(fs *pflag.FlagSet) {
|
||||
fs.Set(FlagAmount, "2000stake")
|
||||
},
|
||||
expectedCfg: mkTxValCfg("2000stake", "0.1", "0.2", "0.01", "1"),
|
||||
}, {
|
||||
},
|
||||
{
|
||||
name: "Custom commission rate",
|
||||
fsModify: func(fs *pflag.FlagSet) {
|
||||
fs.Set(FlagCommissionRate, "0.54")
|
||||
},
|
||||
expectedCfg: mkTxValCfg(defaultAmount, "0.54", "0.2", "0.01", "1"),
|
||||
}, {
|
||||
},
|
||||
{
|
||||
name: "Custom commission max rate",
|
||||
fsModify: func(fs *pflag.FlagSet) {
|
||||
fs.Set(FlagCommissionMaxRate, "0.89")
|
||||
},
|
||||
expectedCfg: mkTxValCfg(defaultAmount, "0.1", "0.89", "0.01", "1"),
|
||||
}, {
|
||||
},
|
||||
{
|
||||
name: "Custom commission max change rate",
|
||||
fsModify: func(fs *pflag.FlagSet) {
|
||||
fs.Set(FlagCommissionMaxChangeRate, "0.55")
|
||||
|
||||
@@ -18,9 +18,7 @@ var commonArgs = []string{
|
||||
}
|
||||
|
||||
// MsgRedelegateExec creates a redelegate message.
|
||||
func MsgRedelegateExec(clientCtx client.Context, from, src, dst, amount fmt.Stringer,
|
||||
extraArgs ...string) (testutil.BufferWriter, error) {
|
||||
|
||||
func MsgRedelegateExec(clientCtx client.Context, from, src, dst, amount fmt.Stringer, extraArgs ...string) (testutil.BufferWriter, error) {
|
||||
args := []string{
|
||||
src.String(),
|
||||
dst.String(),
|
||||
@@ -36,8 +34,8 @@ func MsgRedelegateExec(clientCtx client.Context, from, src, dst, amount fmt.Stri
|
||||
|
||||
// MsgUnbondExec creates a unbond message.
|
||||
func MsgUnbondExec(clientCtx client.Context, from fmt.Stringer, valAddress,
|
||||
amount fmt.Stringer, extraArgs ...string) (testutil.BufferWriter, error) {
|
||||
|
||||
amount fmt.Stringer, extraArgs ...string,
|
||||
) (testutil.BufferWriter, error) {
|
||||
args := []string{
|
||||
valAddress.String(),
|
||||
amount.String(),
|
||||
|
||||
@@ -114,7 +114,8 @@ func (k Keeper) Delegation(ctx sdk.Context, addrDel sdk.AccAddress, addrVal sdk.
|
||||
|
||||
// iterate through all of the delegations from a delegator
|
||||
func (k Keeper) IterateDelegations(ctx sdk.Context, delAddr sdk.AccAddress,
|
||||
fn func(index int64, del types.DelegationI) (stop bool)) {
|
||||
fn func(index int64, del types.DelegationI) (stop bool),
|
||||
) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
delegatorPrefixKey := types.GetDelegationsKey(delAddr)
|
||||
|
||||
|
||||
@@ -13,9 +13,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
var (
|
||||
PKs = simapp.CreateTestPubKeys(500)
|
||||
)
|
||||
var PKs = simapp.CreateTestPubKeys(500)
|
||||
|
||||
func init() {
|
||||
sdk.DefaultPowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))
|
||||
|
||||
@@ -11,8 +11,7 @@ import (
|
||||
)
|
||||
|
||||
// GetDelegation returns a specific delegation.
|
||||
func (k Keeper) GetDelegation(ctx sdk.Context,
|
||||
delAddr sdk.AccAddress, valAddr sdk.ValAddress) (delegation types.Delegation, found bool) {
|
||||
func (k Keeper) GetDelegation(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (delegation types.Delegation, found bool) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
key := types.GetDelegationKey(delAddr, valAddr)
|
||||
|
||||
@@ -71,8 +70,7 @@ func (k Keeper) GetValidatorDelegations(ctx sdk.Context, valAddr sdk.ValAddress)
|
||||
|
||||
// GetDelegatorDelegations returns a given amount of all the delegations from a
|
||||
// delegator.
|
||||
func (k Keeper) GetDelegatorDelegations(ctx sdk.Context, delegator sdk.AccAddress,
|
||||
maxRetrieve uint16) (delegations []types.Delegation) {
|
||||
func (k Keeper) GetDelegatorDelegations(ctx sdk.Context, delegator sdk.AccAddress, maxRetrieve uint16) (delegations []types.Delegation) {
|
||||
delegations = make([]types.Delegation, maxRetrieve)
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
delegatorPrefixKey := types.GetDelegationsKey(delegator)
|
||||
@@ -119,8 +117,7 @@ func (k Keeper) RemoveDelegation(ctx sdk.Context, delegation types.Delegation) e
|
||||
}
|
||||
|
||||
// GetUnbondingDelegations returns a given amount of all the delegator unbonding-delegations.
|
||||
func (k Keeper) GetUnbondingDelegations(ctx sdk.Context, delegator sdk.AccAddress,
|
||||
maxRetrieve uint16) (unbondingDelegations []types.UnbondingDelegation) {
|
||||
func (k Keeper) GetUnbondingDelegations(ctx sdk.Context, delegator sdk.AccAddress, maxRetrieve uint16) (unbondingDelegations []types.UnbondingDelegation) {
|
||||
unbondingDelegations = make([]types.UnbondingDelegation, maxRetrieve)
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
@@ -140,9 +137,7 @@ func (k Keeper) GetUnbondingDelegations(ctx sdk.Context, delegator sdk.AccAddres
|
||||
}
|
||||
|
||||
// GetUnbondingDelegation returns a unbonding delegation.
|
||||
func (k Keeper) GetUnbondingDelegation(
|
||||
ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress,
|
||||
) (ubd types.UnbondingDelegation, found bool) {
|
||||
func (k Keeper) GetUnbondingDelegation(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (ubd types.UnbondingDelegation, found bool) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
key := types.GetUBDKey(delAddr, valAddr)
|
||||
value := store.Get(key)
|
||||
@@ -269,8 +264,7 @@ func (k Keeper) IterateDelegatorRedelegations(ctx sdk.Context, delegator sdk.Acc
|
||||
}
|
||||
|
||||
// HasMaxUnbondingDelegationEntries - check if unbonding delegation has maximum number of entries.
|
||||
func (k Keeper) HasMaxUnbondingDelegationEntries(ctx sdk.Context,
|
||||
delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) bool {
|
||||
func (k Keeper) HasMaxUnbondingDelegationEntries(ctx sdk.Context, delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) bool {
|
||||
ubd, found := k.GetUnbondingDelegation(ctx, delegatorAddr, validatorAddr)
|
||||
if !found {
|
||||
return false
|
||||
@@ -359,8 +353,7 @@ func (k Keeper) SetUBDQueueTimeSlice(ctx sdk.Context, timestamp time.Time, keys
|
||||
|
||||
// InsertUBDQueue inserts an unbonding delegation to the appropriate timeslice
|
||||
// in the unbonding queue.
|
||||
func (k Keeper) InsertUBDQueue(ctx sdk.Context, ubd types.UnbondingDelegation,
|
||||
completionTime time.Time) {
|
||||
func (k Keeper) InsertUBDQueue(ctx sdk.Context, ubd types.UnbondingDelegation, completionTime time.Time) {
|
||||
dvPair := types.DVPair{DelegatorAddress: ubd.DelegatorAddress, ValidatorAddress: ubd.ValidatorAddress}
|
||||
|
||||
timeSlice := k.GetUBDQueueTimeSlice(ctx, completionTime)
|
||||
@@ -402,8 +395,7 @@ func (k Keeper) DequeueAllMatureUBDQueue(ctx sdk.Context, currTime time.Time) (m
|
||||
}
|
||||
|
||||
// GetRedelegations returns a given amount of all the delegator redelegations.
|
||||
func (k Keeper) GetRedelegations(ctx sdk.Context, delegator sdk.AccAddress,
|
||||
maxRetrieve uint16) (redelegations []types.Redelegation) {
|
||||
func (k Keeper) GetRedelegations(ctx sdk.Context, delegator sdk.AccAddress, maxRetrieve uint16) (redelegations []types.Redelegation) {
|
||||
redelegations = make([]types.Redelegation, maxRetrieve)
|
||||
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
@@ -423,8 +415,7 @@ func (k Keeper) GetRedelegations(ctx sdk.Context, delegator sdk.AccAddress,
|
||||
}
|
||||
|
||||
// GetRedelegation returns a redelegation.
|
||||
func (k Keeper) GetRedelegation(ctx sdk.Context,
|
||||
delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress) (red types.Redelegation, found bool) {
|
||||
func (k Keeper) GetRedelegation(ctx sdk.Context, delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress) (red types.Redelegation, found bool) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
key := types.GetREDKey(delAddr, valSrcAddr, valDstAddr)
|
||||
|
||||
@@ -457,8 +448,7 @@ func (k Keeper) GetRedelegationsFromSrcValidator(ctx sdk.Context, valAddr sdk.Va
|
||||
}
|
||||
|
||||
// HasReceivingRedelegation checks if validator is receiving a redelegation.
|
||||
func (k Keeper) HasReceivingRedelegation(ctx sdk.Context,
|
||||
delAddr sdk.AccAddress, valDstAddr sdk.ValAddress) bool {
|
||||
func (k Keeper) HasReceivingRedelegation(ctx sdk.Context, delAddr sdk.AccAddress, valDstAddr sdk.ValAddress) bool {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
prefix := types.GetREDsByDelToValDstIndexKey(delAddr, valDstAddr)
|
||||
|
||||
@@ -469,9 +459,7 @@ func (k Keeper) HasReceivingRedelegation(ctx sdk.Context,
|
||||
}
|
||||
|
||||
// HasMaxRedelegationEntries checks if redelegation has maximum number of entries.
|
||||
func (k Keeper) HasMaxRedelegationEntries(ctx sdk.Context,
|
||||
delegatorAddr sdk.AccAddress, validatorSrcAddr,
|
||||
validatorDstAddr sdk.ValAddress) bool {
|
||||
func (k Keeper) HasMaxRedelegationEntries(ctx sdk.Context, delegatorAddr sdk.AccAddress, validatorSrcAddr, validatorDstAddr sdk.ValAddress) bool {
|
||||
red, found := k.GetRedelegation(ctx, delegatorAddr, validatorSrcAddr, validatorDstAddr)
|
||||
if !found {
|
||||
return false
|
||||
@@ -509,7 +497,8 @@ func (k Keeper) SetRedelegationEntry(ctx sdk.Context,
|
||||
delegatorAddr sdk.AccAddress, validatorSrcAddr,
|
||||
validatorDstAddr sdk.ValAddress, creationHeight int64,
|
||||
minTime time.Time, balance sdk.Int,
|
||||
sharesSrc, sharesDst sdk.Dec) types.Redelegation {
|
||||
sharesSrc, sharesDst sdk.Dec,
|
||||
) types.Redelegation {
|
||||
red, found := k.GetRedelegation(ctx, delegatorAddr, validatorSrcAddr, validatorDstAddr)
|
||||
if found {
|
||||
red.AddEntry(creationHeight, minTime, balance, sharesDst)
|
||||
@@ -588,13 +577,13 @@ func (k Keeper) SetRedelegationQueueTimeSlice(ctx sdk.Context, timestamp time.Ti
|
||||
|
||||
// InsertRedelegationQueue insert an redelegation delegation to the appropriate
|
||||
// timeslice in the redelegation queue.
|
||||
func (k Keeper) InsertRedelegationQueue(ctx sdk.Context, red types.Redelegation,
|
||||
completionTime time.Time) {
|
||||
func (k Keeper) InsertRedelegationQueue(ctx sdk.Context, red types.Redelegation, completionTime time.Time) {
|
||||
timeSlice := k.GetRedelegationQueueTimeSlice(ctx, completionTime)
|
||||
dvvTriplet := types.DVVTriplet{
|
||||
DelegatorAddress: red.DelegatorAddress,
|
||||
ValidatorSrcAddress: red.ValidatorSrcAddress,
|
||||
ValidatorDstAddress: red.ValidatorDstAddress}
|
||||
ValidatorDstAddress: red.ValidatorDstAddress,
|
||||
}
|
||||
|
||||
if len(timeSlice) == 0 {
|
||||
k.SetRedelegationQueueTimeSlice(ctx, completionTime, []types.DVVTriplet{dvvTriplet})
|
||||
|
||||
@@ -31,7 +31,7 @@ func TestDelegation(t *testing.T) {
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 3, sdk.NewInt(10000))
|
||||
valAddrs := simapp.ConvertAddrsToValAddrs(addrDels)
|
||||
|
||||
//construct the validators
|
||||
// construct the validators
|
||||
amts := []sdk.Int{sdk.NewInt(9), sdk.NewInt(8), sdk.NewInt(7)}
|
||||
var validators [3]types.Validator
|
||||
for i, amt := range amts {
|
||||
@@ -325,7 +325,7 @@ func TestUndelegateSelfDelegationBelowMinSelfDelegation(t *testing.T) {
|
||||
delTokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 10)
|
||||
delCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), delTokens))
|
||||
|
||||
//create a validator with a self-delegation
|
||||
// create a validator with a self-delegation
|
||||
validator := teststaking.NewValidator(t, addrVals[0], PKs[0])
|
||||
|
||||
validator.MinSelfDelegation = delTokens
|
||||
@@ -385,7 +385,7 @@ func TestUndelegateFromUnbondingValidator(t *testing.T) {
|
||||
addrDels := simapp.AddTestAddrsIncremental(app, ctx, 2, sdk.NewInt(0))
|
||||
addrVals := simapp.ConvertAddrsToValAddrs(addrDels)
|
||||
|
||||
//create a validator with a self-delegation
|
||||
// create a validator with a self-delegation
|
||||
validator := teststaking.NewValidator(t, addrVals[0], PKs[0])
|
||||
app.StakingKeeper.SetValidatorByConsAddr(ctx, validator)
|
||||
|
||||
@@ -557,7 +557,7 @@ func TestUnbondingAllDelegationFromValidator(t *testing.T) {
|
||||
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), delCoins))
|
||||
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
|
||||
|
||||
//create a validator with a self-delegation
|
||||
// create a validator with a self-delegation
|
||||
validator := teststaking.NewValidator(t, addrVals[0], PKs[0])
|
||||
app.StakingKeeper.SetValidatorByConsAddr(ctx, validator)
|
||||
|
||||
@@ -806,7 +806,7 @@ func TestRedelegateSelfDelegation(t *testing.T) {
|
||||
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), startCoins))
|
||||
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
|
||||
|
||||
//create a validator with a self-delegation
|
||||
// create a validator with a self-delegation
|
||||
validator := teststaking.NewValidator(t, addrVals[0], PKs[0])
|
||||
app.StakingKeeper.SetValidatorByConsAddr(ctx, validator)
|
||||
|
||||
@@ -862,7 +862,7 @@ func TestRedelegateFromUnbondingValidator(t *testing.T) {
|
||||
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), startCoins))
|
||||
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
|
||||
|
||||
//create a validator with a self-delegation
|
||||
// create a validator with a self-delegation
|
||||
validator := teststaking.NewValidator(t, addrVals[0], PKs[0])
|
||||
app.StakingKeeper.SetValidatorByConsAddr(ctx, validator)
|
||||
|
||||
@@ -909,7 +909,7 @@ func TestRedelegateFromUnbondingValidator(t *testing.T) {
|
||||
params := app.StakingKeeper.GetParams(ctx)
|
||||
require.True(t, blockTime.Add(params.UnbondingTime).Equal(validator.UnbondingTime))
|
||||
|
||||
//change the context
|
||||
// change the context
|
||||
header = ctx.BlockHeader()
|
||||
blockHeight2 := int64(20)
|
||||
header.Height = blockHeight2
|
||||
@@ -944,7 +944,7 @@ func TestRedelegateFromUnbondedValidator(t *testing.T) {
|
||||
require.NoError(t, testutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), startCoins))
|
||||
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
|
||||
|
||||
//create a validator with a self-delegation
|
||||
// create a validator with a self-delegation
|
||||
validator := teststaking.NewValidator(t, addrVals[0], PKs[0])
|
||||
app.StakingKeeper.SetValidatorByConsAddr(ctx, validator)
|
||||
|
||||
|
||||
@@ -53,7 +53,6 @@ func (k Querier) Validators(c context.Context, req *types.QueryValidatorsRequest
|
||||
|
||||
return true, nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
@@ -129,7 +128,8 @@ func (k Querier) ValidatorDelegations(c context.Context, req *types.QueryValidat
|
||||
}
|
||||
|
||||
return &types.QueryValidatorDelegationsResponse{
|
||||
DelegationResponses: delResponses, Pagination: pageRes}, nil
|
||||
DelegationResponses: delResponses, Pagination: pageRes,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ValidatorUnbondingDelegations queries unbonding delegations of a validator
|
||||
@@ -287,7 +287,6 @@ func (k Querier) DelegatorDelegations(c context.Context, req *types.QueryDelegat
|
||||
}
|
||||
|
||||
return &types.QueryDelegatorDelegationsResponse{DelegationResponses: delegationResps, Pagination: pageRes}, nil
|
||||
|
||||
}
|
||||
|
||||
// DelegatorValidator queries validator info for given delegator validator pair
|
||||
@@ -354,7 +353,8 @@ func (k Querier) DelegatorUnbondingDelegations(c context.Context, req *types.Que
|
||||
}
|
||||
|
||||
return &types.QueryDelegatorUnbondingDelegationsResponse{
|
||||
UnbondingResponses: unbondingDelegations, Pagination: pageRes}, nil
|
||||
UnbondingResponses: unbondingDelegations, Pagination: pageRes,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// HistoricalInfo queries the historical info for given height
|
||||
@@ -439,7 +439,6 @@ func (k Querier) DelegatorValidators(c context.Context, req *types.QueryDelegato
|
||||
validators = append(validators, validator)
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
@@ -471,7 +470,6 @@ func (k Querier) Params(c context.Context, _ *types.QueryParamsRequest) (*types.
|
||||
}
|
||||
|
||||
func queryRedelegation(ctx sdk.Context, k Querier, req *types.QueryRedelegationsRequest) (redels types.Redelegations, err error) {
|
||||
|
||||
delAddr, err := sdk.AccAddressFromBech32(req.DelegatorAddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -56,8 +56,10 @@ func (suite *KeeperTestSuite) TestGRPCQueryValidators() {
|
||||
{
|
||||
"valid request",
|
||||
func() {
|
||||
req = &types.QueryValidatorsRequest{Status: types.Bonded.String(),
|
||||
Pagination: &query.PageRequest{Limit: 1, CountTotal: true}}
|
||||
req = &types.QueryValidatorsRequest{
|
||||
Status: types.Bonded.String(),
|
||||
Pagination: &query.PageRequest{Limit: 1, CountTotal: true},
|
||||
}
|
||||
},
|
||||
true,
|
||||
1,
|
||||
@@ -149,7 +151,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryDelegatorValidators() {
|
||||
func() {
|
||||
req = &types.QueryDelegatorValidatorsRequest{
|
||||
DelegatorAddr: addrs[0].String(),
|
||||
Pagination: &query.PageRequest{Limit: 1, CountTotal: true}}
|
||||
Pagination: &query.PageRequest{Limit: 1, CountTotal: true},
|
||||
}
|
||||
},
|
||||
true,
|
||||
},
|
||||
@@ -321,8 +324,10 @@ func (suite *KeeperTestSuite) TestGRPCQueryDelegatorDelegations() {
|
||||
{
|
||||
"valid request",
|
||||
func() {
|
||||
req = &types.QueryDelegatorDelegationsRequest{DelegatorAddr: addrAcc.String(),
|
||||
Pagination: &query.PageRequest{Limit: 1, CountTotal: true}}
|
||||
req = &types.QueryDelegatorDelegationsRequest{
|
||||
DelegatorAddr: addrAcc.String(),
|
||||
Pagination: &query.PageRequest{Limit: 1, CountTotal: true},
|
||||
}
|
||||
},
|
||||
func(suite *KeeperTestSuite, response *types.QueryDelegatorDelegationsResponse) {
|
||||
suite.Equal(uint64(2), response.Pagination.Total)
|
||||
@@ -384,8 +389,10 @@ func (suite *KeeperTestSuite) TestGRPCQueryValidatorDelegations() {
|
||||
{
|
||||
"valid request",
|
||||
func() {
|
||||
req = &types.QueryValidatorDelegationsRequest{ValidatorAddr: addrVal1,
|
||||
Pagination: &query.PageRequest{Limit: 1, CountTotal: true}}
|
||||
req = &types.QueryValidatorDelegationsRequest{
|
||||
ValidatorAddr: addrVal1,
|
||||
Pagination: &query.PageRequest{Limit: 1, CountTotal: true},
|
||||
}
|
||||
},
|
||||
true,
|
||||
false,
|
||||
@@ -451,7 +458,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryUnbondingDelegation() {
|
||||
"valid request",
|
||||
func() {
|
||||
req = &types.QueryUnbondingDelegationRequest{
|
||||
DelegatorAddr: addrAcc2.String(), ValidatorAddr: addrVal2}
|
||||
DelegatorAddr: addrAcc2.String(), ValidatorAddr: addrVal2,
|
||||
}
|
||||
},
|
||||
true,
|
||||
},
|
||||
@@ -515,8 +523,10 @@ func (suite *KeeperTestSuite) TestGRPCQueryDelegatorUnbondingDelegations() {
|
||||
{
|
||||
"valid request",
|
||||
func() {
|
||||
req = &types.QueryDelegatorUnbondingDelegationsRequest{DelegatorAddr: addrAcc.String(),
|
||||
Pagination: &query.PageRequest{Limit: 1, CountTotal: true}}
|
||||
req = &types.QueryDelegatorUnbondingDelegationsRequest{
|
||||
DelegatorAddr: addrAcc.String(),
|
||||
Pagination: &query.PageRequest{Limit: 1, CountTotal: true},
|
||||
}
|
||||
},
|
||||
true,
|
||||
false,
|
||||
@@ -657,8 +667,10 @@ func (suite *KeeperTestSuite) TestGRPCQueryRedelegations() {
|
||||
{
|
||||
"request redelegations with non existent pairs",
|
||||
func() {
|
||||
req = &types.QueryRedelegationsRequest{DelegatorAddr: addrAcc.String(), SrcValidatorAddr: val3.String(),
|
||||
DstValidatorAddr: val4.String()}
|
||||
req = &types.QueryRedelegationsRequest{
|
||||
DelegatorAddr: addrAcc.String(), SrcValidatorAddr: val3.String(),
|
||||
DstValidatorAddr: val4.String(),
|
||||
}
|
||||
},
|
||||
false,
|
||||
true,
|
||||
@@ -668,7 +680,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryRedelegations() {
|
||||
func() {
|
||||
req = &types.QueryRedelegationsRequest{
|
||||
DelegatorAddr: addrAcc1.String(), SrcValidatorAddr: val1.OperatorAddress,
|
||||
DstValidatorAddr: val2.OperatorAddress, Pagination: &query.PageRequest{}}
|
||||
DstValidatorAddr: val2.OperatorAddress, Pagination: &query.PageRequest{},
|
||||
}
|
||||
},
|
||||
true,
|
||||
false,
|
||||
@@ -678,7 +691,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryRedelegations() {
|
||||
func() {
|
||||
req = &types.QueryRedelegationsRequest{
|
||||
DelegatorAddr: addrAcc1.String(), SrcValidatorAddr: val1.OperatorAddress,
|
||||
Pagination: &query.PageRequest{}}
|
||||
Pagination: &query.PageRequest{},
|
||||
}
|
||||
},
|
||||
true,
|
||||
false,
|
||||
@@ -688,7 +702,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryRedelegations() {
|
||||
func() {
|
||||
req = &types.QueryRedelegationsRequest{
|
||||
SrcValidatorAddr: val1.GetOperator().String(),
|
||||
Pagination: &query.PageRequest{Limit: 1, CountTotal: true}}
|
||||
Pagination: &query.PageRequest{Limit: 1, CountTotal: true},
|
||||
}
|
||||
},
|
||||
true,
|
||||
false,
|
||||
@@ -746,7 +761,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryValidatorUnbondingDelegations() {
|
||||
func() {
|
||||
req = &types.QueryValidatorUnbondingDelegationsRequest{
|
||||
ValidatorAddr: val1.GetOperator().String(),
|
||||
Pagination: &query.PageRequest{Limit: 1, CountTotal: true}}
|
||||
Pagination: &query.PageRequest{Limit: 1, CountTotal: true},
|
||||
}
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
||||
@@ -53,17 +53,18 @@ func (suite *KeeperTestSuite) SetupTest() {
|
||||
|
||||
suite.app, suite.ctx, suite.queryClient, suite.addrs, suite.vals = app, ctx, queryClient, addrs, validators
|
||||
}
|
||||
|
||||
func TestParams(t *testing.T) {
|
||||
app := simapp.Setup(t, false)
|
||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
||||
|
||||
expParams := types.DefaultParams()
|
||||
|
||||
//check that the empty keeper loads the default
|
||||
// check that the empty keeper loads the default
|
||||
resParams := app.StakingKeeper.GetParams(ctx)
|
||||
require.True(t, expParams.Equal(resParams))
|
||||
|
||||
//modify a params, save, and retrieve
|
||||
// modify a params, save, and retrieve
|
||||
expParams.MaxValidators = 777
|
||||
app.StakingKeeper.SetParams(ctx, expParams)
|
||||
resParams = app.StakingKeeper.GetParams(ctx)
|
||||
|
||||
@@ -190,7 +190,6 @@ func queryDelegatorDelegations(ctx sdk.Context, req abci.RequestQuery, k Keeper,
|
||||
|
||||
delegations := k.GetAllDelegatorDelegations(ctx, params.DelegatorAddr)
|
||||
delegationResps, err := DelegationsToDelegationResponses(ctx, k, delegations)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -165,7 +165,8 @@ func (k Keeper) Unjail(ctx sdk.Context, consAddr sdk.ConsAddress) {
|
||||
// (the amount actually slashed may be less if there's
|
||||
// insufficient stake remaining)
|
||||
func (k Keeper) SlashUnbondingDelegation(ctx sdk.Context, unbondingDelegation types.UnbondingDelegation,
|
||||
infractionHeight int64, slashFactor sdk.Dec) (totalSlashAmount sdk.Int) {
|
||||
infractionHeight int64, slashFactor sdk.Dec,
|
||||
) (totalSlashAmount sdk.Int) {
|
||||
now := ctx.BlockHeader().Time
|
||||
totalSlashAmount = sdk.ZeroInt()
|
||||
burnedAmount := sdk.ZeroInt()
|
||||
@@ -218,7 +219,8 @@ func (k Keeper) SlashUnbondingDelegation(ctx sdk.Context, unbondingDelegation ty
|
||||
// insufficient stake remaining)
|
||||
// NOTE this is only slashing for prior infractions from the source validator
|
||||
func (k Keeper) SlashRedelegation(ctx sdk.Context, srcValidator types.Validator, redelegation types.Redelegation,
|
||||
infractionHeight int64, slashFactor sdk.Dec) (totalSlashAmount sdk.Int) {
|
||||
infractionHeight int64, slashFactor sdk.Dec,
|
||||
) (totalSlashAmount sdk.Int) {
|
||||
now := ctx.BlockHeader().Time
|
||||
totalSlashAmount = sdk.ZeroInt()
|
||||
bondedBurnedAmount, notBondedBurnedAmount := sdk.ZeroInt(), sdk.ZeroInt()
|
||||
|
||||
@@ -96,7 +96,8 @@ func (k Keeper) SetNewValidatorByPowerIndex(ctx sdk.Context, validator types.Val
|
||||
|
||||
// Update the tokens of an existing validator, update the validators power index key
|
||||
func (k Keeper) AddValidatorTokensAndShares(ctx sdk.Context, validator types.Validator,
|
||||
tokensToAdd sdk.Int) (valOut types.Validator, addedShares sdk.Dec) {
|
||||
tokensToAdd sdk.Int,
|
||||
) (valOut types.Validator, addedShares sdk.Dec) {
|
||||
k.DeleteValidatorByPowerIndex(ctx, validator)
|
||||
validator, addedShares = validator.AddTokensFromDel(tokensToAdd)
|
||||
k.SetValidator(ctx, validator)
|
||||
@@ -107,7 +108,8 @@ func (k Keeper) AddValidatorTokensAndShares(ctx sdk.Context, validator types.Val
|
||||
|
||||
// Update the tokens of an existing validator, update the validators power index key
|
||||
func (k Keeper) RemoveValidatorTokensAndShares(ctx sdk.Context, validator types.Validator,
|
||||
sharesToRemove sdk.Dec) (valOut types.Validator, removedTokens sdk.Int) {
|
||||
sharesToRemove sdk.Dec,
|
||||
) (valOut types.Validator, removedTokens sdk.Int) {
|
||||
k.DeleteValidatorByPowerIndex(ctx, validator)
|
||||
validator, removedTokens = validator.RemoveDelShares(sharesToRemove)
|
||||
k.SetValidator(ctx, validator)
|
||||
@@ -118,7 +120,8 @@ func (k Keeper) RemoveValidatorTokensAndShares(ctx sdk.Context, validator types.
|
||||
|
||||
// Update the tokens of an existing validator, update the validators power index key
|
||||
func (k Keeper) RemoveValidatorTokens(ctx sdk.Context,
|
||||
validator types.Validator, tokensToRemove sdk.Int) types.Validator {
|
||||
validator types.Validator, tokensToRemove sdk.Int,
|
||||
) types.Validator {
|
||||
k.DeleteValidatorByPowerIndex(ctx, validator)
|
||||
validator = validator.RemoveTokens(tokensToRemove)
|
||||
k.SetValidator(ctx, validator)
|
||||
@@ -130,7 +133,8 @@ func (k Keeper) RemoveValidatorTokens(ctx sdk.Context,
|
||||
// UpdateValidatorCommission attempts to update a validator's commission rate.
|
||||
// An error is returned if the new commission rate is invalid.
|
||||
func (k Keeper) UpdateValidatorCommission(ctx sdk.Context,
|
||||
validator types.Validator, newRate sdk.Dec) (types.Commission, error) {
|
||||
validator types.Validator, newRate sdk.Dec,
|
||||
) (types.Commission, error) {
|
||||
commission := validator.Commission
|
||||
blockTime := ctx.BlockHeader().Time
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ import "testing"
|
||||
func BenchmarkGetValidator(b *testing.B) {
|
||||
// 900 is the max number we are allowed to use in order to avoid simapp.CreateTestPubKeys
|
||||
// panic: encoding/hex: odd length hex string
|
||||
var powersNumber = 900
|
||||
powersNumber := 900
|
||||
|
||||
var totalPower int64 = 0
|
||||
var powers = make([]int64, powersNumber)
|
||||
powers := make([]int64, powersNumber)
|
||||
for i := range powers {
|
||||
powers[i] = int64(i)
|
||||
totalPower += int64(i)
|
||||
|
||||
@@ -252,7 +252,7 @@ func TestSlashToZeroPowerRemoved(t *testing.T) {
|
||||
func TestValidatorBasics(t *testing.T) {
|
||||
app, ctx, _, addrVals := bootstrapValidatorTest(t, 1000, 20)
|
||||
|
||||
//construct the validators
|
||||
// construct the validators
|
||||
var validators [3]types.Validator
|
||||
powers := []int64{9, 8, 7}
|
||||
for i, power := range powers {
|
||||
@@ -357,7 +357,8 @@ func TestGetValidatorSortingUnmixed(t *testing.T) {
|
||||
app.StakingKeeper.PowerReduction(ctx).MulRaw(100),
|
||||
app.StakingKeeper.PowerReduction(ctx),
|
||||
app.StakingKeeper.PowerReduction(ctx).MulRaw(400),
|
||||
app.StakingKeeper.PowerReduction(ctx).MulRaw(200)}
|
||||
app.StakingKeeper.PowerReduction(ctx).MulRaw(200),
|
||||
}
|
||||
n := len(amts)
|
||||
var validators [5]types.Validator
|
||||
for i, amt := range amts {
|
||||
@@ -450,7 +451,8 @@ func TestGetValidatorSortingMixed(t *testing.T) {
|
||||
app.StakingKeeper.PowerReduction(ctx).MulRaw(100),
|
||||
app.StakingKeeper.PowerReduction(ctx),
|
||||
app.StakingKeeper.PowerReduction(ctx).MulRaw(400),
|
||||
app.StakingKeeper.PowerReduction(ctx).MulRaw(200)}
|
||||
app.StakingKeeper.PowerReduction(ctx).MulRaw(200),
|
||||
}
|
||||
|
||||
var validators [5]types.Validator
|
||||
for i, amt := range amts {
|
||||
|
||||
@@ -97,7 +97,8 @@ func TestRandomizedGenState1(t *testing.T) {
|
||||
Accounts: simtypes.RandomAccounts(r, 3),
|
||||
InitialStake: sdkmath.NewInt(1000),
|
||||
GenState: make(map[string]json.RawMessage),
|
||||
}, "invalid memory address or nil pointer dereference"},
|
||||
}, "invalid memory address or nil pointer dereference",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
@@ -46,7 +46,8 @@ func TestWeightedOperations(t *testing.T) {
|
||||
weight int
|
||||
opMsgRoute string
|
||||
opMsgName string
|
||||
}{{simappparams.DefaultWeightMsgCreateValidator, types.ModuleName, types.TypeMsgCreateValidator},
|
||||
}{
|
||||
{simappparams.DefaultWeightMsgCreateValidator, types.ModuleName, types.TypeMsgCreateValidator},
|
||||
{simappparams.DefaultWeightMsgEditValidator, types.ModuleName, types.TypeMsgEditValidator},
|
||||
{simappparams.DefaultWeightMsgDelegate, types.ModuleName, types.TypeMsgDelegate},
|
||||
{simappparams.DefaultWeightMsgUndelegate, types.ModuleName, types.TypeMsgUndelegate},
|
||||
@@ -380,5 +381,4 @@ func setupValidatorRewards(app *simapp.SimApp, ctx sdk.Context, valAddress sdk.V
|
||||
// setup current revards
|
||||
currentRewards := distrtypes.NewValidatorCurrentRewards(decCoins, 3)
|
||||
app.DistrKeeper.SetValidatorCurrentRewards(ctx, valAddress, currentRewards)
|
||||
|
||||
}
|
||||
|
||||
@@ -10,9 +10,7 @@ import (
|
||||
// Tracking issues https://github.com/cosmos/cosmos-sdk/issues/9054, https://github.com/cosmos/cosmos-sdk/discussions/9072
|
||||
const gasCostPerIteration = uint64(10)
|
||||
|
||||
var (
|
||||
_ authz.Authorization = &StakeAuthorization{}
|
||||
)
|
||||
var _ authz.Authorization = &StakeAuthorization{}
|
||||
|
||||
// NewStakeAuthorization creates a new StakeAuthorization object.
|
||||
func NewStakeAuthorization(allowed []sdk.ValAddress, denied []sdk.ValAddress, authzType AuthorizationType, amount *sdk.Coin) (*StakeAuthorization, error) {
|
||||
@@ -98,8 +96,10 @@ func (a StakeAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.AcceptRe
|
||||
}
|
||||
|
||||
if a.MaxTokens == nil {
|
||||
return authz.AcceptResponse{Accept: true, Delete: false,
|
||||
Updated: &StakeAuthorization{Validators: a.GetValidators(), AuthorizationType: a.GetAuthorizationType()}}, nil
|
||||
return authz.AcceptResponse{
|
||||
Accept: true, Delete: false,
|
||||
Updated: &StakeAuthorization{Validators: a.GetValidators(), AuthorizationType: a.GetAuthorizationType()},
|
||||
}, nil
|
||||
}
|
||||
|
||||
limitLeft, err := a.MaxTokens.SafeSub(amount)
|
||||
@@ -109,8 +109,10 @@ func (a StakeAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.AcceptRe
|
||||
if limitLeft.IsZero() {
|
||||
return authz.AcceptResponse{Accept: true, Delete: true}, nil
|
||||
}
|
||||
return authz.AcceptResponse{Accept: true, Delete: false,
|
||||
Updated: &StakeAuthorization{Validators: a.GetValidators(), AuthorizationType: a.GetAuthorizationType(), MaxTokens: &limitLeft}}, nil
|
||||
return authz.AcceptResponse{
|
||||
Accept: true, Delete: false,
|
||||
Updated: &StakeAuthorization{Validators: a.GetValidators(), AuthorizationType: a.GetAuthorizationType(), MaxTokens: &limitLeft},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func validateAllowAndDenyValidators(allowed []sdk.ValAddress, denied []sdk.ValAddress) ([]string, []string, error) {
|
||||
|
||||
@@ -94,7 +94,8 @@ func TestAuthzAuthorizations(t *testing.T) {
|
||||
&stakingtypes.StakeAuthorization{
|
||||
Validators: &stakingtypes.StakeAuthorization_AllowList{
|
||||
AllowList: &stakingtypes.StakeAuthorization_Validators{Address: validators1_2},
|
||||
}, MaxTokens: &coin50, AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE},
|
||||
}, MaxTokens: &coin50, AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE,
|
||||
},
|
||||
},
|
||||
{
|
||||
"delegate: testing with invalid validator",
|
||||
@@ -119,7 +120,8 @@ func TestAuthzAuthorizations(t *testing.T) {
|
||||
&stakingtypes.StakeAuthorization{
|
||||
Validators: &stakingtypes.StakeAuthorization_AllowList{
|
||||
AllowList: &stakingtypes.StakeAuthorization_Validators{Address: validators1_2},
|
||||
}, MaxTokens: nil, AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE},
|
||||
}, MaxTokens: nil, AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE,
|
||||
},
|
||||
},
|
||||
{
|
||||
"delegate: fail validator denied",
|
||||
@@ -144,7 +146,8 @@ func TestAuthzAuthorizations(t *testing.T) {
|
||||
&stakingtypes.StakeAuthorization{
|
||||
Validators: &stakingtypes.StakeAuthorization_DenyList{
|
||||
DenyList: &stakingtypes.StakeAuthorization_Validators{Address: []string{val1.String()}},
|
||||
}, MaxTokens: nil, AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE},
|
||||
}, MaxTokens: nil, AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE,
|
||||
},
|
||||
},
|
||||
{
|
||||
"undelegate: expect 0 remaining coins",
|
||||
@@ -169,7 +172,8 @@ func TestAuthzAuthorizations(t *testing.T) {
|
||||
&stakingtypes.StakeAuthorization{
|
||||
Validators: &stakingtypes.StakeAuthorization_AllowList{
|
||||
AllowList: &stakingtypes.StakeAuthorization_Validators{Address: validators1_2},
|
||||
}, MaxTokens: &coin50, AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_UNDELEGATE},
|
||||
}, MaxTokens: &coin50, AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_UNDELEGATE,
|
||||
},
|
||||
},
|
||||
{
|
||||
"undelegate: testing with invalid validator",
|
||||
@@ -194,7 +198,8 @@ func TestAuthzAuthorizations(t *testing.T) {
|
||||
&stakingtypes.StakeAuthorization{
|
||||
Validators: &stakingtypes.StakeAuthorization_AllowList{
|
||||
AllowList: &stakingtypes.StakeAuthorization_Validators{Address: validators1_2},
|
||||
}, MaxTokens: nil, AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_UNDELEGATE},
|
||||
}, MaxTokens: nil, AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_UNDELEGATE,
|
||||
},
|
||||
},
|
||||
{
|
||||
"undelegate: fail cannot undelegate, permission denied",
|
||||
@@ -231,7 +236,8 @@ func TestAuthzAuthorizations(t *testing.T) {
|
||||
&stakingtypes.StakeAuthorization{
|
||||
Validators: &stakingtypes.StakeAuthorization_AllowList{
|
||||
AllowList: &stakingtypes.StakeAuthorization_Validators{Address: validators1_2},
|
||||
}, MaxTokens: &coin50, AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_REDELEGATE},
|
||||
}, MaxTokens: &coin50, AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_REDELEGATE,
|
||||
},
|
||||
},
|
||||
{
|
||||
"redelegate: testing with invalid validator",
|
||||
@@ -256,7 +262,8 @@ func TestAuthzAuthorizations(t *testing.T) {
|
||||
&stakingtypes.StakeAuthorization{
|
||||
Validators: &stakingtypes.StakeAuthorization_AllowList{
|
||||
AllowList: &stakingtypes.StakeAuthorization_Validators{Address: validators1_2},
|
||||
}, MaxTokens: nil, AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_REDELEGATE},
|
||||
}, MaxTokens: nil, AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_REDELEGATE,
|
||||
},
|
||||
},
|
||||
{
|
||||
"redelegate: fail cannot undelegate, permission denied",
|
||||
|
||||
@@ -66,6 +66,7 @@ func (d Delegation) GetDelegatorAddr() sdk.AccAddress {
|
||||
}
|
||||
return delAddr
|
||||
}
|
||||
|
||||
func (d Delegation) GetValidatorAddr() sdk.ValAddress {
|
||||
addr, err := sdk.ValAddressFromBech32(d.ValidatorAddress)
|
||||
if err != nil {
|
||||
@@ -350,7 +351,8 @@ func NewRedelegationResponse(
|
||||
|
||||
// NewRedelegationEntryResponse creates a new RedelegationEntryResponse instance.
|
||||
func NewRedelegationEntryResponse(
|
||||
creationHeight int64, completionTime time.Time, sharesDst sdk.Dec, initialBalance, balance sdk.Int) RedelegationEntryResponse {
|
||||
creationHeight int64, completionTime time.Time, sharesDst sdk.Dec, initialBalance, balance sdk.Int,
|
||||
) RedelegationEntryResponse {
|
||||
return RedelegationEntryResponse{
|
||||
RedelegationEntry: NewRedelegationEntry(creationHeight, completionTime, initialBalance, sharesDst),
|
||||
Balance: balance,
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package types_test
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/codec/legacy"
|
||||
"math/rand"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/codec/legacy"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ func (h MultiStakingHooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.Va
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h MultiStakingHooks) BeforeValidatorModified(ctx sdk.Context, valAddr sdk.ValAddress) error {
|
||||
for i := range h {
|
||||
if err := h[i].BeforeValidatorModified(ctx, valAddr); err != nil {
|
||||
@@ -30,6 +31,7 @@ func (h MultiStakingHooks) BeforeValidatorModified(ctx sdk.Context, valAddr sdk.
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h MultiStakingHooks) AfterValidatorRemoved(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) error {
|
||||
for i := range h {
|
||||
if err := h[i].AfterValidatorRemoved(ctx, consAddr, valAddr); err != nil {
|
||||
@@ -38,6 +40,7 @@ func (h MultiStakingHooks) AfterValidatorRemoved(ctx sdk.Context, consAddr sdk.C
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h MultiStakingHooks) AfterValidatorBonded(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) error {
|
||||
for i := range h {
|
||||
if err := h[i].AfterValidatorBonded(ctx, consAddr, valAddr); err != nil {
|
||||
@@ -46,6 +49,7 @@ func (h MultiStakingHooks) AfterValidatorBonded(ctx sdk.Context, consAddr sdk.Co
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h MultiStakingHooks) AfterValidatorBeginUnbonding(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) error {
|
||||
for i := range h {
|
||||
if err := h[i].AfterValidatorBeginUnbonding(ctx, consAddr, valAddr); err != nil {
|
||||
@@ -54,6 +58,7 @@ func (h MultiStakingHooks) AfterValidatorBeginUnbonding(ctx sdk.Context, consAdd
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h MultiStakingHooks) BeforeDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
|
||||
for i := range h {
|
||||
if err := h[i].BeforeDelegationCreated(ctx, delAddr, valAddr); err != nil {
|
||||
@@ -62,6 +67,7 @@ func (h MultiStakingHooks) BeforeDelegationCreated(ctx sdk.Context, delAddr sdk.
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h MultiStakingHooks) BeforeDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
|
||||
for i := range h {
|
||||
if err := h[i].BeforeDelegationSharesModified(ctx, delAddr, valAddr); err != nil {
|
||||
@@ -70,6 +76,7 @@ func (h MultiStakingHooks) BeforeDelegationSharesModified(ctx sdk.Context, delAd
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h MultiStakingHooks) BeforeDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
|
||||
for i := range h {
|
||||
if err := h[i].BeforeDelegationRemoved(ctx, delAddr, valAddr); err != nil {
|
||||
@@ -78,6 +85,7 @@ func (h MultiStakingHooks) BeforeDelegationRemoved(ctx sdk.Context, delAddr sdk.
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h MultiStakingHooks) AfterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
|
||||
for i := range h {
|
||||
if err := h[i].AfterDelegationModified(ctx, delAddr, valAddr); err != nil {
|
||||
@@ -86,6 +94,7 @@ func (h MultiStakingHooks) AfterDelegationModified(ctx sdk.Context, delAddr sdk.
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h MultiStakingHooks) BeforeValidatorSlashed(ctx sdk.Context, valAddr sdk.ValAddress, fraction sdk.Dec) error {
|
||||
for i := range h {
|
||||
if err := h[i].BeforeValidatorSlashed(ctx, valAddr, fraction); err != nil {
|
||||
|
||||
@@ -56,12 +56,18 @@ func TestGetREDByValDstIndexKey(t *testing.T) {
|
||||
valDstAddr sdk.ValAddress
|
||||
wantHex string
|
||||
}{
|
||||
{sdk.AccAddress(keysAddr1), sdk.ValAddress(keysAddr1), sdk.ValAddress(keysAddr1),
|
||||
"361463d771218209d8bd03c482f69dfba57310f086091463d771218209d8bd03c482f69dfba57310f086091463d771218209d8bd03c482f69dfba57310f08609"},
|
||||
{sdk.AccAddress(keysAddr1), sdk.ValAddress(keysAddr2), sdk.ValAddress(keysAddr3),
|
||||
"36143ab62f0d93849be495e21e3e9013a517038f45bd1463d771218209d8bd03c482f69dfba57310f08609145ef3b5f25c54946d4a89fc0d09d2f126614540f2"},
|
||||
{sdk.AccAddress(keysAddr2), sdk.ValAddress(keysAddr1), sdk.ValAddress(keysAddr3),
|
||||
"36143ab62f0d93849be495e21e3e9013a517038f45bd145ef3b5f25c54946d4a89fc0d09d2f126614540f21463d771218209d8bd03c482f69dfba57310f08609"},
|
||||
{
|
||||
sdk.AccAddress(keysAddr1), sdk.ValAddress(keysAddr1), sdk.ValAddress(keysAddr1),
|
||||
"361463d771218209d8bd03c482f69dfba57310f086091463d771218209d8bd03c482f69dfba57310f086091463d771218209d8bd03c482f69dfba57310f08609",
|
||||
},
|
||||
{
|
||||
sdk.AccAddress(keysAddr1), sdk.ValAddress(keysAddr2), sdk.ValAddress(keysAddr3),
|
||||
"36143ab62f0d93849be495e21e3e9013a517038f45bd1463d771218209d8bd03c482f69dfba57310f08609145ef3b5f25c54946d4a89fc0d09d2f126614540f2",
|
||||
},
|
||||
{
|
||||
sdk.AccAddress(keysAddr2), sdk.ValAddress(keysAddr1), sdk.ValAddress(keysAddr3),
|
||||
"36143ab62f0d93849be495e21e3e9013a517038f45bd145ef3b5f25c54946d4a89fc0d09d2f126614540f21463d771218209d8bd03c482f69dfba57310f08609",
|
||||
},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
got := hex.EncodeToString(types.GetREDByValDstIndexKey(tt.delAddr, tt.valSrcAddr, tt.valDstAddr))
|
||||
@@ -77,12 +83,18 @@ func TestGetREDByValSrcIndexKey(t *testing.T) {
|
||||
valDstAddr sdk.ValAddress
|
||||
wantHex string
|
||||
}{
|
||||
{sdk.AccAddress(keysAddr1), sdk.ValAddress(keysAddr1), sdk.ValAddress(keysAddr1),
|
||||
"351463d771218209d8bd03c482f69dfba57310f086091463d771218209d8bd03c482f69dfba57310f086091463d771218209d8bd03c482f69dfba57310f08609"},
|
||||
{sdk.AccAddress(keysAddr1), sdk.ValAddress(keysAddr2), sdk.ValAddress(keysAddr3),
|
||||
"35145ef3b5f25c54946d4a89fc0d09d2f126614540f21463d771218209d8bd03c482f69dfba57310f08609143ab62f0d93849be495e21e3e9013a517038f45bd"},
|
||||
{sdk.AccAddress(keysAddr2), sdk.ValAddress(keysAddr1), sdk.ValAddress(keysAddr3),
|
||||
"351463d771218209d8bd03c482f69dfba57310f08609145ef3b5f25c54946d4a89fc0d09d2f126614540f2143ab62f0d93849be495e21e3e9013a517038f45bd"},
|
||||
{
|
||||
sdk.AccAddress(keysAddr1), sdk.ValAddress(keysAddr1), sdk.ValAddress(keysAddr1),
|
||||
"351463d771218209d8bd03c482f69dfba57310f086091463d771218209d8bd03c482f69dfba57310f086091463d771218209d8bd03c482f69dfba57310f08609",
|
||||
},
|
||||
{
|
||||
sdk.AccAddress(keysAddr1), sdk.ValAddress(keysAddr2), sdk.ValAddress(keysAddr3),
|
||||
"35145ef3b5f25c54946d4a89fc0d09d2f126614540f21463d771218209d8bd03c482f69dfba57310f08609143ab62f0d93849be495e21e3e9013a517038f45bd",
|
||||
},
|
||||
{
|
||||
sdk.AccAddress(keysAddr2), sdk.ValAddress(keysAddr1), sdk.ValAddress(keysAddr3),
|
||||
"351463d771218209d8bd03c482f69dfba57310f08609145ef3b5f25c54946d4a89fc0d09d2f126614540f2143ab62f0d93849be495e21e3e9013a517038f45bd",
|
||||
},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
got := hex.EncodeToString(types.GetREDByValSrcIndexKey(tt.delAddr, tt.valSrcAddr, tt.valDstAddr))
|
||||
|
||||
@@ -32,10 +32,8 @@ const (
|
||||
DefaultHistoricalEntries uint32 = 10000
|
||||
)
|
||||
|
||||
var (
|
||||
// DefaultMinCommissionRate is set to 0%
|
||||
DefaultMinCommissionRate = sdk.ZeroDec()
|
||||
)
|
||||
// DefaultMinCommissionRate is set to 0%
|
||||
var DefaultMinCommissionRate = sdk.ZeroDec()
|
||||
|
||||
var (
|
||||
KeyUnbondingTime = []byte("UnbondingTime")
|
||||
|
||||
@@ -452,7 +452,6 @@ func (v *Validator) MinEqual(other *Validator) bool {
|
||||
v.Jailed == other.Jailed &&
|
||||
v.MinSelfDelegation.Equal(other.MinSelfDelegation) &&
|
||||
v.ConsensusPubkey.Equal(other.ConsensusPubkey)
|
||||
|
||||
}
|
||||
|
||||
// Equal checks if the receiver equals the parameter
|
||||
@@ -484,7 +483,6 @@ func (v Validator) ConsPubKey() (cryptotypes.PubKey, error) {
|
||||
}
|
||||
|
||||
return pk, nil
|
||||
|
||||
}
|
||||
|
||||
// TmConsPublicKey casts Validator.ConsensusPubkey to tmprotocrypto.PubKey.
|
||||
|
||||
@@ -121,7 +121,6 @@ func TestAddTokensValidatorUnbonding(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAddTokensValidatorUnbonded(t *testing.T) {
|
||||
|
||||
validator := newValidator(t, valAddr1, pk1)
|
||||
validator = validator.UpdateStatus(types.Unbonded)
|
||||
validator, delShares := validator.AddTokensFromDel(sdk.NewInt(10))
|
||||
|
||||
Reference in New Issue
Block a user