test(integration): port x/staking tests to server v2 (#22813)
This commit is contained in:
@@ -263,7 +263,7 @@ func (k Keeper) GetBlockConsPubKeyRotationHistory(ctx context.Context) ([]types.
|
||||
}
|
||||
|
||||
// GetValidatorConsPubKeyRotationHistory iterates over all the rotated history objects in the state with the given valAddr and returns.
|
||||
func (k Keeper) GetValidatorConsPubKeyRotationHistory(ctx sdk.Context, operatorAddress sdk.ValAddress) ([]types.ConsPubKeyRotationHistory, error) {
|
||||
func (k Keeper) GetValidatorConsPubKeyRotationHistory(ctx context.Context, operatorAddress sdk.ValAddress) ([]types.ConsPubKeyRotationHistory, error) {
|
||||
var historyObjects []types.ConsPubKeyRotationHistory
|
||||
|
||||
rng := collections.NewPrefixedPairRange[[]byte, uint64](operatorAddress.Bytes())
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
"cosmossdk.io/x/staking/types"
|
||||
|
||||
@@ -76,3 +77,61 @@ func TestingUpdateValidator(keeper *Keeper, ctx sdk.Context, validator types.Val
|
||||
|
||||
return validator
|
||||
}
|
||||
|
||||
// TestingUpdateValidatorV2 updates a validator in v2 for testing
|
||||
func TestingUpdateValidatorV2(keeper *Keeper, ctx context.Context, validator types.Validator, apply bool) (types.Validator, []appmodulev2.ValidatorUpdate) {
|
||||
err := keeper.SetValidator(ctx, validator)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Remove any existing power key for validator.
|
||||
store := keeper.KVStoreService.OpenKVStore(ctx)
|
||||
deleted := false
|
||||
|
||||
iterator, err := store.Iterator(types.ValidatorsByPowerIndexKey, storetypes.PrefixEndBytes(types.ValidatorsByPowerIndexKey))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer iterator.Close()
|
||||
|
||||
bz, err := keeper.validatorAddressCodec.StringToBytes(validator.GetOperator())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for ; iterator.Valid(); iterator.Next() {
|
||||
valAddr := types.ParseValidatorPowerRankKey(iterator.Key())
|
||||
if bytes.Equal(valAddr, bz) {
|
||||
if deleted {
|
||||
panic("found duplicate power index key")
|
||||
} else {
|
||||
deleted = true
|
||||
}
|
||||
|
||||
if err = store.Delete(iterator.Key()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err = keeper.SetValidatorByPowerIndex(ctx, validator); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var updates []appmodulev2.ValidatorUpdate
|
||||
|
||||
if apply {
|
||||
updates, err = keeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
validator, err = keeper.GetValidator(ctx, sdk.ValAddress(bz))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return validator, updates
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user