* Revert "feat: staking config (#10988)"
This reverts commit 5e9656f363.
* remove docs
This commit is contained in:
parent
d7ba5d2d9c
commit
66ca3e88aa
@ -140,10 +140,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
* [\#11124](https://github.com/cosmos/cosmos-sdk/pull/11124) Add `GetAllVersions` to application store
|
||||
* (x/authz) [\#10447](https://github.com/cosmos/cosmos-sdk/pull/10447) authz `NewGrant` takes a new argument: block time, to correctly validate expire time.
|
||||
* [\#10961](https://github.com/cosmos/cosmos-sdk/pull/10961) Support third-party modules to add extension snapshots to state-sync.
|
||||
* [\#10988](https://github.com/cosmos/cosmos-sdk/pull/10988) Removes sdk.PowerReduction as a global and pass it directly to the staking keeper on creation.
|
||||
- Deletes `types/staking.go` and moves the functions to `x/staking/types/power_reduction.go`
|
||||
* [\#11274](https://github.com/cosmos/cosmos-sdk/pull/11274) `types/errors.New` now is an alias for `types/errors.Register` and should only be used in initialization code.
|
||||
|
||||
|
||||
### Client Breaking Changes
|
||||
|
||||
* [\#11089](https://github.com/cosmos/cosmos-sdk/pull/11089]) interacting with the node through `grpc.Dial` requires clients to pass a codec refer to [doc](docs/run-node/interact-node.md).
|
||||
|
||||
@ -267,14 +267,8 @@ func NewSimApp(
|
||||
app.BankKeeper = bankkeeper.NewBaseKeeper(
|
||||
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.ModuleAccountAddrs(),
|
||||
)
|
||||
|
||||
stakingConfig := stakingtypes.DefaultConfig()
|
||||
/*
|
||||
Example of setting staking params:
|
||||
stakingConfig.PowerReduction = sdk.NewIntFromUint64(10)
|
||||
*/
|
||||
stakingKeeper := stakingkeeper.NewKeeper(
|
||||
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName), stakingConfig,
|
||||
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName),
|
||||
)
|
||||
app.MintKeeper = mintkeeper.NewKeeper(
|
||||
appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper,
|
||||
|
||||
@ -282,8 +282,8 @@ func initTestnetFiles(
|
||||
return err
|
||||
}
|
||||
|
||||
accTokens := sdk.NewIntFromUint64(1000_000_000)
|
||||
accStakingTokens := sdk.NewIntFromUint64(500_000_000)
|
||||
accTokens := sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction)
|
||||
accStakingTokens := sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction)
|
||||
coins := sdk.Coins{
|
||||
sdk.NewCoin("testtoken", accTokens),
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, accStakingTokens),
|
||||
@ -292,7 +292,7 @@ func initTestnetFiles(
|
||||
genBalances = append(genBalances, banktypes.Balance{Address: addr.String(), Coins: coins.Sort()})
|
||||
genAccounts = append(genAccounts, authtypes.NewBaseAccount(addr, nil, 0, 0))
|
||||
|
||||
valTokens := sdk.NewIntFromUint64(100_000_000)
|
||||
valTokens := sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)
|
||||
createValMsg, err := stakingtypes.NewMsgCreateValidator(
|
||||
sdk.ValAddress(addr),
|
||||
valPubKeys[i],
|
||||
|
||||
@ -154,7 +154,7 @@ func genesisStateWithValSet(t *testing.T,
|
||||
validators := make([]stakingtypes.Validator, 0, len(valSet.Validators))
|
||||
delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators))
|
||||
|
||||
bondAmt := stakingtypes.DefaultConfig().PowerReduction
|
||||
bondAmt := sdk.DefaultPowerReduction
|
||||
|
||||
for _, val := range valSet.Validators {
|
||||
pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey)
|
||||
|
||||
@ -116,9 +116,9 @@ func DefaultConfig() Config {
|
||||
NumValidators: 4,
|
||||
BondDenom: sdk.DefaultBondDenom,
|
||||
MinGasPrices: fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom),
|
||||
AccountTokens: sdk.NewIntFromUint64(1000_000_000),
|
||||
StakingTokens: sdk.NewIntFromUint64(500_000_000),
|
||||
BondedTokens: sdk.NewIntFromUint64(100_000_000),
|
||||
AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction),
|
||||
StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction),
|
||||
BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction),
|
||||
PruningStrategy: storetypes.PruningOptionNothing,
|
||||
CleanupDir: true,
|
||||
SigningAlgo: string(hd.Secp256k1Type),
|
||||
|
||||
@ -1,28 +0,0 @@
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
var DefaultpowerReduction = sdk.NewInt(1_000_000)
|
||||
|
||||
// TokensToConsensusPower - convert input tokens to Power
|
||||
func TokensToConsensusPower(tokens sdk.Int, powerReduction sdk.Int) int64 {
|
||||
if tokens.IsNil() || powerReduction.IsNil() || powerReduction.IsZero() {
|
||||
return 0
|
||||
}
|
||||
|
||||
power := tokens.Quo(powerReduction)
|
||||
|
||||
if power.GT(sdk.NewIntFromUint64(math.MaxInt64)) {
|
||||
return 0
|
||||
}
|
||||
return power.Int64()
|
||||
}
|
||||
|
||||
// TokensFromConsensusPower - convert input power to tokens
|
||||
func TokensFromConsensusPower(power int64, powerReduction sdk.Int) sdk.Int {
|
||||
return sdk.NewInt(power).Mul(powerReduction)
|
||||
}
|
||||
@ -335,7 +335,7 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData
|
||||
|
||||
// a chain must initialize with a non-empty validator set
|
||||
if len(validatorUpdates) == 0 {
|
||||
panic(fmt.Sprintf("validator set is empty after InitGenesis, please ensure at least one validator is initialized with a delegation greater than or equal to the DefaultPowerReduction, found in x/staking/types/config.go"))
|
||||
panic(fmt.Sprintf("validator set is empty after InitGenesis, please ensure at least one validator is initialized with a delegation greater than or equal to the DefaultPowerReduction (%d)", sdk.DefaultPowerReduction))
|
||||
}
|
||||
|
||||
return abci.ResponseInitChain{
|
||||
|
||||
@ -17,3 +17,16 @@ const (
|
||||
// https://tendermint.com/docs/spec/abci/apps.html#endblock
|
||||
ValidatorUpdateDelay int64 = 1
|
||||
)
|
||||
|
||||
// DefaultPowerReduction is the default amount of staking tokens required for 1 unit of consensus-engine power
|
||||
var DefaultPowerReduction = NewIntFromUint64(1000000)
|
||||
|
||||
// TokensToConsensusPower - convert input tokens to potential consensus-engine power
|
||||
func TokensToConsensusPower(tokens Int, powerReduction Int) int64 {
|
||||
return (tokens.Quo(powerReduction)).Int64()
|
||||
}
|
||||
|
||||
// TokensFromConsensusPower - convert input power to tokens
|
||||
func TokensFromConsensusPower(power int64, powerReduction Int) Int {
|
||||
return NewInt(power).Mul(powerReduction)
|
||||
}
|
||||
26
types/staking_test.go
Normal file
26
types/staking_test.go
Normal file
@ -0,0 +1,26 @@
|
||||
package types_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
type stakingTestSuite struct {
|
||||
suite.Suite
|
||||
}
|
||||
|
||||
func TestStakingTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(stakingTestSuite))
|
||||
}
|
||||
|
||||
func (s *stakingTestSuite) SetupSuite() {
|
||||
s.T().Parallel()
|
||||
}
|
||||
|
||||
func (s *stakingTestSuite) TestTokensToConsensusPower() {
|
||||
s.Require().Equal(int64(0), sdk.TokensToConsensusPower(sdk.NewInt(999_999), sdk.DefaultPowerReduction))
|
||||
s.Require().Equal(int64(1), sdk.TokensToConsensusPower(sdk.NewInt(1_000_000), sdk.DefaultPowerReduction))
|
||||
}
|
||||
@ -648,7 +648,7 @@ func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {
|
||||
account, err := val1.ClientCtx.Keyring.Key("newAccount")
|
||||
s.Require().NoError(err)
|
||||
|
||||
sendTokens := sdk.NewCoin(s.cfg.BondDenom, testutil.TokensFromConsensusPower(10, testutil.DefaultpowerReduction))
|
||||
sendTokens := sdk.NewCoin(s.cfg.BondDenom, sdk.TokensFromConsensusPower(10, sdk.DefaultPowerReduction))
|
||||
|
||||
addr, err := account.GetAddress()
|
||||
s.Require().NoError(err)
|
||||
@ -849,7 +849,7 @@ func (s *IntegrationTestSuite) TestCLIMultisignInsufficientCosigners() {
|
||||
func (s *IntegrationTestSuite) TestCLIEncode() {
|
||||
val1 := s.network.Validators[0]
|
||||
|
||||
sendTokens := sdk.NewCoin(s.cfg.BondDenom, testutil.TokensFromConsensusPower(10, testutil.DefaultpowerReduction))
|
||||
sendTokens := sdk.NewCoin(s.cfg.BondDenom, sdk.TokensFromConsensusPower(10, sdk.DefaultPowerReduction))
|
||||
|
||||
normalGeneratedTx, err := s.createBankMsg(
|
||||
val1, val1.Address,
|
||||
|
||||
@ -9,7 +9,6 @@ import (
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
@ -658,7 +657,7 @@ func dirtyTrackingFields(ctx sdk.Context, vesting exported.VestingAccount, app *
|
||||
}
|
||||
|
||||
func createValidator(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers int64) (sdk.AccAddress, sdk.ValAddress) {
|
||||
valTokens := testutil.TokensFromConsensusPower(powers, testutil.DefaultpowerReduction)
|
||||
valTokens := sdk.TokensFromConsensusPower(powers, sdk.DefaultPowerReduction)
|
||||
addrs := simapp.AddTestAddrsIncremental(app, ctx, 1, valTokens)
|
||||
valAddrs := simapp.ConvertAddrsToValAddrs(addrs)
|
||||
pks := simapp.CreateTestPubKeys(1)
|
||||
@ -670,7 +669,6 @@ func createValidator(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers i
|
||||
app.AccountKeeper,
|
||||
app.BankKeeper,
|
||||
app.GetSubspace(stakingtypes.ModuleName),
|
||||
stakingtypes.DefaultConfig(),
|
||||
)
|
||||
|
||||
val1, err := stakingtypes.NewValidator(valAddrs[0], pks[0], stakingtypes.Description{})
|
||||
|
||||
@ -4,7 +4,6 @@ import (
|
||||
gocontext "context"
|
||||
"fmt"
|
||||
|
||||
sdktestutil "github.com/cosmos/cosmos-sdk/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/query"
|
||||
@ -325,7 +324,7 @@ func (suite *IntegrationTestSuite) TestGRPCDenomOwners() {
|
||||
|
||||
bal := sdk.NewCoins(sdk.NewCoin(
|
||||
sdk.DefaultBondDenom,
|
||||
sdktestutil.TokensFromConsensusPower(initialPower/10, sdktestutil.DefaultpowerReduction),
|
||||
sdk.TokensFromConsensusPower(initialPower/10, sdk.DefaultPowerReduction),
|
||||
))
|
||||
suite.Require().NoError(keeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, acc.GetAddress(), bal))
|
||||
}
|
||||
|
||||
@ -12,7 +12,6 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdktestutil "github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/query"
|
||||
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
||||
@ -41,7 +40,8 @@ var (
|
||||
randomPermAcc = authtypes.NewEmptyModuleAccount(randomPerm, "random")
|
||||
|
||||
// The default power validators are initialized to have within tests
|
||||
initCoins = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdktestutil.TokensFromConsensusPower(initialPower, sdktestutil.DefaultpowerReduction)))
|
||||
initTokens = sdk.TokensFromConsensusPower(initialPower, sdk.DefaultPowerReduction)
|
||||
initCoins = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens))
|
||||
)
|
||||
|
||||
func newFooCoin(amt int64) sdk.Coin {
|
||||
|
||||
@ -7,7 +7,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
)
|
||||
@ -142,7 +141,8 @@ func TestBalance_GetAddress(t *testing.T) {
|
||||
|
||||
func TestSanitizeBalances(t *testing.T) {
|
||||
// 1. Generate balances
|
||||
coin := sdk.NewCoin("benchcoin", testutil.TokensFromConsensusPower(81, testutil.DefaultpowerReduction))
|
||||
tokens := sdk.TokensFromConsensusPower(81, sdk.DefaultPowerReduction)
|
||||
coin := sdk.NewCoin("benchcoin", tokens)
|
||||
coins := sdk.Coins{coin}
|
||||
addrs, _ := makeRandomAddressesAndPublicKeys(20)
|
||||
|
||||
@ -193,7 +193,9 @@ func BenchmarkSanitizeBalances1000(b *testing.B) {
|
||||
|
||||
func benchmarkSanitizeBalances(b *testing.B, nAddresses int) {
|
||||
b.ReportAllocs()
|
||||
coins := sdk.NewCoins(sdk.NewCoin("benchcoin", testutil.TokensFromConsensusPower(81, testutil.DefaultpowerReduction)))
|
||||
tokens := sdk.TokensFromConsensusPower(81, sdk.DefaultPowerReduction)
|
||||
coin := sdk.NewCoin("benchcoin", tokens)
|
||||
coins := sdk.Coins{coin}
|
||||
addrs, _ := makeRandomAddressesAndPublicKeys(nAddresses)
|
||||
|
||||
b.ResetTimer()
|
||||
|
||||
@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
@ -12,13 +14,11 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/evidence/exported"
|
||||
"github.com/cosmos/cosmos-sdk/x/evidence/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/evidence/types"
|
||||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -35,7 +35,7 @@ var (
|
||||
}
|
||||
|
||||
// The default power validators are initialized to have within tests
|
||||
initAmt = testutil.TokensFromConsensusPower(200, testutil.DefaultpowerReduction)
|
||||
initAmt = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction)
|
||||
initCoins = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt))
|
||||
)
|
||||
|
||||
|
||||
@ -11,7 +11,6 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
|
||||
sdktestutil "github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
|
||||
@ -39,7 +38,7 @@ func (suite *SimTestSuite) SetupTest() {
|
||||
func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Account {
|
||||
accounts := simtypes.RandomAccounts(r, n)
|
||||
|
||||
initAmt := sdktestutil.TokensFromConsensusPower(200, sdktestutil.DefaultpowerReduction)
|
||||
initAmt := sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction)
|
||||
initCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt))
|
||||
|
||||
// add coins to the accounts
|
||||
|
||||
@ -9,7 +9,6 @@ import (
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/keeper"
|
||||
@ -374,7 +373,7 @@ func createValidators(t *testing.T, stakingMsgSvr stakingtypes.MsgServer, ctx sd
|
||||
require.True(t, len(addrs) <= len(pubkeys), "Not enough pubkeys specified at top of file.")
|
||||
|
||||
for i := 0; i < len(addrs); i++ {
|
||||
valTokens := testutil.TokensFromConsensusPower(powerAmt[i], testutil.DefaultpowerReduction)
|
||||
valTokens := sdk.TokensFromConsensusPower(powerAmt[i], sdk.DefaultPowerReduction)
|
||||
valCreateMsg, err := stakingtypes.NewMsgCreateValidator(
|
||||
addrs[i], pubkeys[i], sdk.NewCoin(sdk.DefaultBondDenom, valTokens),
|
||||
TestDescription, TestCommissionRates, sdk.OneInt(),
|
||||
|
||||
@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
@ -19,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
valTokens = testutil.TokensFromConsensusPower(42, testutil.DefaultpowerReduction)
|
||||
valTokens = sdk.TokensFromConsensusPower(42, sdk.DefaultPowerReduction)
|
||||
TestProposal = v1beta1.NewTextProposal("Test", "description")
|
||||
TestDescription = stakingtypes.NewDescription("T", "E", "S", "T", "Z")
|
||||
TestCommissionRates = stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
|
||||
|
||||
@ -48,7 +48,6 @@ func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers
|
||||
app.AccountKeeper,
|
||||
app.BankKeeper,
|
||||
app.GetSubspace(stakingtypes.ModuleName),
|
||||
stakingtypes.DefaultConfig(),
|
||||
)
|
||||
|
||||
val1, err := stakingtypes.NewValidator(valAddrs[0], pks[0], stakingtypes.Description{})
|
||||
|
||||
@ -12,7 +12,6 @@ import (
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdktestutil "github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
|
||||
@ -83,7 +82,7 @@ func (suite *SimTestSuite) TestWeightedOperations() {
|
||||
func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Account {
|
||||
accounts := simtypes.RandomAccounts(r, n)
|
||||
|
||||
initAmt := sdktestutil.TokensFromConsensusPower(200, sdktestutil.DefaultpowerReduction)
|
||||
initAmt := sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction)
|
||||
initCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt))
|
||||
|
||||
// add coins to the accounts
|
||||
|
||||
@ -25,14 +25,12 @@ func TestBeginBlocker(t *testing.T) {
|
||||
addr, pk := sdk.ValAddress(pks[0].Address()), pks[0]
|
||||
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
|
||||
|
||||
InitTokens := sdk.NewIntFromUint64(200_000_000)
|
||||
// bond the validator
|
||||
power := int64(100)
|
||||
amt := tstaking.CreateValidatorWithValPower(addr, pk, power, true)
|
||||
staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
require.Equal(
|
||||
t, app.BankKeeper.GetAllBalances(ctx, sdk.AccAddress(addr)),
|
||||
|
||||
sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.GetParams(ctx).BondDenom, InitTokens.Sub(amt))),
|
||||
)
|
||||
require.Equal(t, amt, app.StakingKeeper.Validator(ctx, addr).GetBondedTokens())
|
||||
|
||||
@ -11,7 +11,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
@ -42,8 +41,8 @@ func checkValidatorSigningInfo(t *testing.T, app *simapp.SimApp, addr sdk.ConsAd
|
||||
}
|
||||
|
||||
func TestSlashingMsgs(t *testing.T) {
|
||||
genTokens := testutil.TokensFromConsensusPower(42, testutil.DefaultpowerReduction)
|
||||
bondTokens := testutil.TokensFromConsensusPower(10, testutil.DefaultpowerReduction)
|
||||
genTokens := sdk.TokensFromConsensusPower(42, sdk.DefaultPowerReduction)
|
||||
bondTokens := sdk.TokensFromConsensusPower(10, sdk.DefaultPowerReduction)
|
||||
genCoin := sdk.NewCoin(sdk.DefaultBondDenom, genTokens)
|
||||
bondCoin := sdk.NewCoin(sdk.DefaultBondDenom, bondTokens)
|
||||
|
||||
|
||||
10
x/slashing/init_test.go
Normal file
10
x/slashing/init_test.go
Normal file
@ -0,0 +1,10 @@
|
||||
package slashing_test
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
var (
|
||||
// The default power validators are initialized to have within tests
|
||||
InitTokens = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction)
|
||||
)
|
||||
8
x/slashing/keeper/common_test.go
Normal file
8
x/slashing/keeper/common_test.go
Normal file
@ -0,0 +1,8 @@
|
||||
package keeper_test
|
||||
|
||||
import sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
var (
|
||||
// The default power validators are initialized to have within tests
|
||||
InitTokens = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction)
|
||||
)
|
||||
@ -94,12 +94,10 @@ func TestHandleNewValidator(t *testing.T) {
|
||||
|
||||
// Validator created
|
||||
amt := tstaking.CreateValidatorWithValPower(addr, val, 100, true)
|
||||
InitTokens := sdk.NewIntFromUint64(200_000_000)
|
||||
|
||||
staking.EndBlocker(ctx, app.StakingKeeper)
|
||||
require.Equal(
|
||||
t, app.BankKeeper.GetAllBalances(ctx, sdk.AccAddress(addr)),
|
||||
|
||||
sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.GetParams(ctx).BondDenom, InitTokens.Sub(amt))),
|
||||
)
|
||||
require.Equal(t, amt, app.StakingKeeper.Validator(ctx, addr).GetBondedTokens())
|
||||
|
||||
@ -40,8 +40,8 @@ func checkDelegation(
|
||||
}
|
||||
|
||||
func TestStakingMsgs(t *testing.T) {
|
||||
genTokens := types.TokensFromConsensusPower(42, types.DefaultConfig().PowerReduction)
|
||||
bondTokens := types.TokensFromConsensusPower(10, types.DefaultConfig().PowerReduction)
|
||||
genTokens := sdk.TokensFromConsensusPower(42, sdk.DefaultPowerReduction)
|
||||
bondTokens := sdk.TokensFromConsensusPower(10, sdk.DefaultPowerReduction)
|
||||
genCoin := sdk.NewCoin(sdk.DefaultBondDenom, genTokens)
|
||||
bondCoin := sdk.NewCoin(sdk.DefaultBondDenom, bondTokens)
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ import (
|
||||
|
||||
// default values
|
||||
var (
|
||||
DefaultTokens = types.TokensFromConsensusPower(100, types.DefaultConfig().PowerReduction)
|
||||
DefaultTokens = sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)
|
||||
defaultAmount = DefaultTokens.String() + sdk.DefaultBondDenom
|
||||
defaultCommissionRate = "0.1"
|
||||
defaultCommissionMaxRate = "0.2"
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package staking_test
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
@ -14,6 +15,10 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
func init() {
|
||||
sdk.DefaultPowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))
|
||||
}
|
||||
|
||||
// nolint:deadcode,unused,varcheck
|
||||
var (
|
||||
priv1 = secp256k1.GenPrivKey()
|
||||
@ -43,7 +48,6 @@ func getBaseSimappWithCustomKeeper(t *testing.T) (*codec.LegacyAmino, *simapp.Si
|
||||
app.AccountKeeper,
|
||||
app.BankKeeper,
|
||||
app.GetSubspace(types.ModuleName),
|
||||
types.DefaultConfig(),
|
||||
)
|
||||
app.StakingKeeper.SetParams(ctx, types.DefaultParams())
|
||||
|
||||
|
||||
@ -17,22 +17,22 @@ var (
|
||||
PKs = simapp.CreateTestPubKeys(500)
|
||||
)
|
||||
|
||||
func init() {
|
||||
sdk.DefaultPowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))
|
||||
}
|
||||
|
||||
// createTestInput Returns a simapp with custom StakingKeeper
|
||||
// to avoid messing with the hooks.
|
||||
func createTestInput(t *testing.T) (*codec.LegacyAmino, *simapp.SimApp, sdk.Context) {
|
||||
app := simapp.Setup(t, false)
|
||||
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
||||
|
||||
stakingConfig := types.DefaultConfig()
|
||||
stakingConfig.PowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))
|
||||
|
||||
app.StakingKeeper = keeper.NewKeeper(
|
||||
app.AppCodec(),
|
||||
app.GetKey(types.StoreKey),
|
||||
app.AccountKeeper,
|
||||
app.BankKeeper,
|
||||
app.GetSubspace(types.ModuleName),
|
||||
stakingConfig,
|
||||
)
|
||||
return app.LegacyAmino(), app, ctx
|
||||
}
|
||||
|
||||
@ -780,7 +780,6 @@ func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers
|
||||
app.AccountKeeper,
|
||||
app.BankKeeper,
|
||||
app.GetSubspace(types.ModuleName),
|
||||
types.DefaultConfig(),
|
||||
)
|
||||
|
||||
val1 := teststaking.NewValidator(t, valAddrs[0], pks[0])
|
||||
|
||||
@ -26,13 +26,12 @@ type Keeper struct {
|
||||
bankKeeper types.BankKeeper
|
||||
hooks types.StakingHooks
|
||||
paramstore paramtypes.Subspace
|
||||
Config types.Config
|
||||
}
|
||||
|
||||
// NewKeeper creates a new staking Keeper instance
|
||||
func NewKeeper(
|
||||
cdc codec.BinaryCodec, key storetypes.StoreKey, ak types.AccountKeeper, bk types.BankKeeper,
|
||||
ps paramtypes.Subspace, cfg types.Config,
|
||||
ps paramtypes.Subspace,
|
||||
) Keeper {
|
||||
// set KeyTable if it has not already been set
|
||||
if !ps.HasKeyTable() {
|
||||
@ -55,7 +54,6 @@ func NewKeeper(
|
||||
bankKeeper: bk,
|
||||
paramstore: ps,
|
||||
hooks: nil,
|
||||
Config: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -40,8 +40,11 @@ func (k Keeper) BondDenom(ctx sdk.Context) (res string) {
|
||||
}
|
||||
|
||||
// PowerReduction - is the amount of staking tokens required for 1 unit of consensus-engine power.
|
||||
func (k Keeper) PowerReduction(_ sdk.Context) sdk.Int {
|
||||
return k.Config.PowerReduction
|
||||
// Currently, this returns a global variable that the app developer can tweak.
|
||||
// TODO: we might turn this into an on-chain param:
|
||||
// https://github.com/cosmos/cosmos-sdk/issues/8365
|
||||
func (k Keeper) PowerReduction(ctx sdk.Context) sdk.Int {
|
||||
return sdk.DefaultPowerReduction
|
||||
}
|
||||
|
||||
// MinCommissionRate - Minimum validator commission rate
|
||||
|
||||
@ -2,15 +2,14 @@ package keeper
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
// TokensToConsensusPower - convert input tokens to potential consensus-engine power
|
||||
func (k Keeper) TokensToConsensusPower(ctx sdk.Context, tokens sdk.Int) int64 {
|
||||
return types.TokensToConsensusPower(tokens, k.PowerReduction(ctx))
|
||||
return sdk.TokensToConsensusPower(tokens, k.PowerReduction(ctx))
|
||||
}
|
||||
|
||||
// TokensFromConsensusPower - convert input power to tokens
|
||||
func (k Keeper) TokensFromConsensusPower(ctx sdk.Context, power int64) sdk.Int {
|
||||
return types.TokensFromConsensusPower(power, k.PowerReduction(ctx))
|
||||
return sdk.TokensFromConsensusPower(power, k.PowerReduction(ctx))
|
||||
}
|
||||
|
||||
@ -5,11 +5,11 @@ import (
|
||||
)
|
||||
|
||||
func (suite *KeeperTestSuite) TestTokensToConsensusPower() {
|
||||
suite.Require().Equal(int64(0), suite.app.StakingKeeper.TokensToConsensusPower(suite.ctx, suite.app.StakingKeeper.Config.PowerReduction.Sub(sdk.NewInt(1))))
|
||||
suite.Require().Equal(int64(1), suite.app.StakingKeeper.TokensToConsensusPower(suite.ctx, suite.app.StakingKeeper.Config.PowerReduction))
|
||||
suite.Require().Equal(int64(0), suite.app.StakingKeeper.TokensToConsensusPower(suite.ctx, sdk.DefaultPowerReduction.Sub(sdk.NewInt(1))))
|
||||
suite.Require().Equal(int64(1), suite.app.StakingKeeper.TokensToConsensusPower(suite.ctx, sdk.DefaultPowerReduction))
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestTokensFromConsensusPower() {
|
||||
suite.Require().Equal(sdk.NewInt(0), suite.app.StakingKeeper.TokensFromConsensusPower(suite.ctx, 0))
|
||||
suite.Require().Equal(suite.app.StakingKeeper.Config.PowerReduction, suite.app.StakingKeeper.TokensFromConsensusPower(suite.ctx, 1))
|
||||
suite.Require().Equal(sdk.DefaultPowerReduction, suite.app.StakingKeeper.TokensFromConsensusPower(suite.ctx, 1))
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ func GetValidatorsByPowerIndexKey(validator types.Validator) []byte {
|
||||
// NOTE the address doesn't need to be stored because counter bytes must always be different
|
||||
// NOTE the larger values are of higher value
|
||||
|
||||
consensusPower := types.TokensToConsensusPower(validator.Tokens, types.DefaultConfig().PowerReduction)
|
||||
consensusPower := sdk.TokensToConsensusPower(validator.Tokens, sdk.DefaultPowerReduction)
|
||||
consensusPowerBytes := make([]byte, 8)
|
||||
binary.BigEndian.PutUint64(consensusPowerBytes, uint64(consensusPower))
|
||||
|
||||
|
||||
@ -62,7 +62,7 @@ func TestStoreMigration(t *testing.T) {
|
||||
{
|
||||
"ValidatorsByPowerIndexKey",
|
||||
v040staking.GetValidatorsByPowerIndexKey(val),
|
||||
types.GetValidatorsByPowerIndexKey(val, types.DefaultConfig().PowerReduction),
|
||||
types.GetValidatorsByPowerIndexKey(val, sdk.DefaultPowerReduction),
|
||||
},
|
||||
{
|
||||
"DelegationKey",
|
||||
|
||||
11
x/staking/simulation/common_test.go
Normal file
11
x/staking/simulation/common_test.go
Normal file
@ -0,0 +1,11 @@
|
||||
package simulation_test
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
func init() {
|
||||
sdk.DefaultPowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))
|
||||
}
|
||||
@ -256,6 +256,7 @@ func TestSimulateMsgBeginRedelegate(t *testing.T) {
|
||||
|
||||
// returns context and an app with updated mint keeper
|
||||
func createTestApp(t *testing.T, isCheckTx bool, r *rand.Rand, n int) (*simapp.SimApp, sdk.Context, []simtypes.Account) {
|
||||
sdk.DefaultPowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))
|
||||
|
||||
accounts := simtypes.RandomAccounts(r, n)
|
||||
// create validator set with single validator
|
||||
@ -280,7 +281,6 @@ func createTestApp(t *testing.T, isCheckTx bool, r *rand.Rand, n int) (*simapp.S
|
||||
app.MintKeeper.SetParams(ctx, minttypes.DefaultParams())
|
||||
app.MintKeeper.SetMinter(ctx, minttypes.DefaultInitialMinter())
|
||||
|
||||
app.StakingKeeper.Config.PowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))
|
||||
initAmt := app.StakingKeeper.TokensFromConsensusPower(ctx, 200)
|
||||
initCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt))
|
||||
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// Config is a config struct used for intialising the staking module to avoid using globals.
|
||||
type Config struct {
|
||||
// PowerReduction is the amount of staking tokens required for 1 unit of consensus-engine power
|
||||
PowerReduction sdk.Int
|
||||
}
|
||||
|
||||
func DefaultConfig() Config {
|
||||
return Config{
|
||||
PowerReduction: sdk.NewIntFromUint64(1000000),
|
||||
}
|
||||
}
|
||||
@ -10,6 +10,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
@ -28,7 +29,7 @@ func createValidators(t *testing.T) []types.Validator {
|
||||
|
||||
func TestHistoricalInfo(t *testing.T) {
|
||||
validators := createValidators(t)
|
||||
hi := types.NewHistoricalInfo(header, validators, types.DefaultConfig().PowerReduction)
|
||||
hi := types.NewHistoricalInfo(header, validators, sdk.DefaultPowerReduction)
|
||||
require.True(t, sort.IsSorted(types.Validators(hi.Valset)), "Validators are not sorted")
|
||||
|
||||
var value []byte
|
||||
@ -69,7 +70,7 @@ func TestValidateBasic(t *testing.T) {
|
||||
err = types.ValidateBasic(hi)
|
||||
require.Error(t, err, "ValidateBasic passed on unsorted ValSet")
|
||||
|
||||
hi = types.NewHistoricalInfo(header, validators, types.DefaultConfig().PowerReduction)
|
||||
hi = types.NewHistoricalInfo(header, validators, sdk.DefaultPowerReduction)
|
||||
err = types.ValidateBasic(hi)
|
||||
require.NoError(t, err, "ValidateBasic failed on valid HistoricalInfo")
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ func GetValidatorsByPowerIndexKey(validator Validator, powerReduction sdk.Int) [
|
||||
// NOTE the address doesn't need to be stored because counter bytes must always be different
|
||||
// NOTE the larger values are of higher value
|
||||
|
||||
consensusPower := TokensToConsensusPower(validator.Tokens, powerReduction)
|
||||
consensusPower := sdk.TokensToConsensusPower(validator.Tokens, powerReduction)
|
||||
consensusPowerBytes := make([]byte, 8)
|
||||
binary.BigEndian.PutUint64(consensusPowerBytes, uint64(consensusPower))
|
||||
|
||||
|
||||
@ -28,10 +28,10 @@ func TestGetValidatorPowerRank(t *testing.T) {
|
||||
val1 := newValidator(t, valAddr1, keysPK1)
|
||||
val1.Tokens = sdk.ZeroInt()
|
||||
val2, val3, val4 := val1, val1, val1
|
||||
val2.Tokens = sdk.NewIntFromUint64(1_000_000)
|
||||
val3.Tokens = sdk.NewIntFromUint64(10_000_000)
|
||||
val2.Tokens = sdk.TokensFromConsensusPower(1, sdk.DefaultPowerReduction)
|
||||
val3.Tokens = sdk.TokensFromConsensusPower(10, sdk.DefaultPowerReduction)
|
||||
x := new(big.Int).Exp(big.NewInt(2), big.NewInt(40), big.NewInt(0))
|
||||
val4.Tokens = sdk.NewInt(x.Int64()).Mul(sdk.NewIntFromUint64(1_000_000))
|
||||
val4.Tokens = sdk.TokensFromConsensusPower(x.Int64(), sdk.DefaultPowerReduction)
|
||||
|
||||
tests := []struct {
|
||||
validator types.Validator
|
||||
@ -43,7 +43,7 @@ func TestGetValidatorPowerRank(t *testing.T) {
|
||||
{val4, "230000010000000000149c288ede7df62742fc3b7d0962045a8cef0f79f6"},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
got := hex.EncodeToString(types.GetValidatorsByPowerIndexKey(tt.validator, types.DefaultConfig().PowerReduction))
|
||||
got := hex.EncodeToString(types.GetValidatorsByPowerIndexKey(tt.validator, sdk.DefaultPowerReduction))
|
||||
|
||||
require.Equal(t, tt.wantHex, got, "Keys did not match on test case %d", i)
|
||||
}
|
||||
|
||||
@ -1,26 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// TokensToConsensusPower - convert input tokens to Power
|
||||
func TokensToConsensusPower(tokens sdk.Int, powerReduction sdk.Int) int64 {
|
||||
if tokens.IsNil() || powerReduction.IsNil() || powerReduction.IsZero() {
|
||||
return 0
|
||||
}
|
||||
|
||||
power := tokens.Quo(powerReduction)
|
||||
|
||||
if power.GT(sdk.NewIntFromUint64(math.MaxInt64)) {
|
||||
return 0
|
||||
}
|
||||
return power.Int64()
|
||||
}
|
||||
|
||||
// TokensFromConsensusPower - convert input power to tokens
|
||||
func TokensFromConsensusPower(power int64, powerReduction sdk.Int) sdk.Int {
|
||||
return sdk.NewInt(power).Mul(powerReduction)
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
package types_test
|
||||
|
||||
import (
|
||||
"math"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
var powerReduction = sdk.NewIntFromUint64(1000000)
|
||||
|
||||
type stakingTestSuite struct {
|
||||
suite.Suite
|
||||
}
|
||||
|
||||
func TestStakingTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(stakingTestSuite))
|
||||
}
|
||||
|
||||
func (s *stakingTestSuite) SetupSuite() {
|
||||
s.T().Parallel()
|
||||
}
|
||||
|
||||
func (s *stakingTestSuite) TestTokensToConsensusPower() {
|
||||
|
||||
s.Require().Equal(int64(0), types.TokensToConsensusPower(sdk.NewInt(999_999), powerReduction))
|
||||
s.Require().Equal(int64(1), types.TokensToConsensusPower(sdk.NewInt(1_000_000), powerReduction))
|
||||
s.Require().Equal(int64(0), types.TokensToConsensusPower(sdk.NewIntFromBigInt(big.NewInt(math.MaxInt64).Add(big.NewInt(math.MaxInt64), big.NewInt(1))), sdk.NewIntFromUint64(1)))
|
||||
s.Require().Equal(int64(0), types.TokensToConsensusPower(sdk.NewInt(1_000_000), sdk.NewIntFromUint64(0)))
|
||||
}
|
||||
@ -366,7 +366,7 @@ func (v Validator) ConsensusPower(r sdk.Int) int64 {
|
||||
|
||||
// PotentialConsensusPower returns the potential consensus-engine power.
|
||||
func (v Validator) PotentialConsensusPower(r sdk.Int) int64 {
|
||||
return TokensToConsensusPower(v.Tokens, r)
|
||||
return sdk.TokensToConsensusPower(v.Tokens, r)
|
||||
}
|
||||
|
||||
// UpdateStatus updates the location of the shares within a validator
|
||||
|
||||
@ -58,7 +58,7 @@ func TestUpdateDescription(t *testing.T) {
|
||||
|
||||
func TestABCIValidatorUpdate(t *testing.T) {
|
||||
validator := newValidator(t, valAddr1, pk1)
|
||||
abciVal := validator.ABCIValidatorUpdate(types.DefaultConfig().PowerReduction)
|
||||
abciVal := validator.ABCIValidatorUpdate(sdk.DefaultPowerReduction)
|
||||
pk, err := validator.TmConsPublicKey()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, pk, abciVal.PubKey)
|
||||
@ -290,15 +290,15 @@ func TestValidatorsSortTendermint(t *testing.T) {
|
||||
valz := types.Validators(vals)
|
||||
|
||||
// create expected tendermint validators by converting to tendermint then sorting
|
||||
expectedVals, err := teststaking.ToTmValidators(valz, types.DefaultConfig().PowerReduction)
|
||||
expectedVals, err := teststaking.ToTmValidators(valz, sdk.DefaultPowerReduction)
|
||||
require.NoError(t, err)
|
||||
sort.Sort(tmtypes.ValidatorsByVotingPower(expectedVals))
|
||||
|
||||
// sort in SDK and then convert to tendermint
|
||||
sort.SliceStable(valz, func(i, j int) bool {
|
||||
return types.ValidatorsByVotingPower(valz).Less(i, j, types.DefaultConfig().PowerReduction)
|
||||
return types.ValidatorsByVotingPower(valz).Less(i, j, sdk.DefaultPowerReduction)
|
||||
})
|
||||
actualVals, err := teststaking.ToTmValidators(valz, types.DefaultConfig().PowerReduction)
|
||||
actualVals, err := teststaking.ToTmValidators(valz, sdk.DefaultPowerReduction)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, expectedVals, actualVals, "sorting in SDK is not the same as sorting in Tendermint")
|
||||
@ -316,9 +316,9 @@ func TestValidatorToTm(t *testing.T) {
|
||||
vals[i] = val
|
||||
tmPk, err := cryptocodec.ToTmPubKeyInterface(pk)
|
||||
require.NoError(t, err)
|
||||
expected[i] = tmtypes.NewValidator(tmPk, val.ConsensusPower(types.DefaultConfig().PowerReduction))
|
||||
expected[i] = tmtypes.NewValidator(tmPk, val.ConsensusPower(sdk.DefaultPowerReduction))
|
||||
}
|
||||
vs, err := teststaking.ToTmValidators(vals, types.DefaultConfig().PowerReduction)
|
||||
vs, err := teststaking.ToTmValidators(vals, sdk.DefaultPowerReduction)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected, vs)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user