* Add new account bech32 prefixes with godocs * Restructure spacing of existing account code * Update account godocs * More account godoc updates + new tm pub/addr helpers * Update validator type to use new account types/bech32 prefixes * Fix account documentation errors * Update Bech32 prefix for consensus nodes * Update Bech32 spec doc * Fix account type tests * Add missing account consensus functions, clear up godocs, and fix tests * Add to TestRandBech32PubkeyConsistency check * Update initialization of validator public keys * Update query signing info command * Implement new ConsAddress type with associated unit tests * [WIP] Update stake and slashing parameters * Update all calls to MustBech32ifyValPub * [WIP] Validator operator API updates * [WIP] Fix and update unit tests * Fix gov logs (helping to debug failing tests) * Fix gov tally * Fix all broken x/ unit tests * Update gaia app genesis address logic * Fix linting errors * Fix broken LCD tests * Fix broken CLI tests * Implement command to get validator address and pubkey from key name * Add support for getting validator key information via REST endpoint * Update PENDING log * Update docs * Revert GaiaGenTx.PubKey bech32 prefix * Fix broken docs and cli tests * Update genesis to use correct Bech32 (cons) prefix for pubkeys * Update docs and unit tests to reflect new cosmos account bech32 prefix * minor formatting
102 lines
3.0 KiB
Go
102 lines
3.0 KiB
Go
package stake
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
keep "github.com/cosmos/cosmos-sdk/x/stake/keeper"
|
|
"github.com/cosmos/cosmos-sdk/x/stake/types"
|
|
)
|
|
|
|
func TestInitGenesis(t *testing.T) {
|
|
ctx, _, keeper := keep.CreateTestInput(t, false, 1000)
|
|
|
|
pool := keeper.GetPool(ctx)
|
|
pool.BondedTokens = sdk.NewDec(2)
|
|
|
|
params := keeper.GetParams(ctx)
|
|
var delegations []Delegation
|
|
|
|
validators := []Validator{
|
|
NewValidator(sdk.ValAddress(keep.Addrs[0]), keep.PKs[0], Description{Moniker: "hoop"}),
|
|
NewValidator(sdk.ValAddress(keep.Addrs[1]), keep.PKs[1], Description{Moniker: "bloop"}),
|
|
}
|
|
genesisState := types.NewGenesisState(pool, params, validators, delegations)
|
|
_, err := InitGenesis(ctx, keeper, genesisState)
|
|
require.Error(t, err)
|
|
|
|
// initialize the validators
|
|
validators[0].Status = sdk.Bonded
|
|
validators[0].Tokens = sdk.OneDec()
|
|
validators[0].DelegatorShares = sdk.OneDec()
|
|
validators[1].Status = sdk.Bonded
|
|
validators[1].Tokens = sdk.OneDec()
|
|
validators[1].DelegatorShares = sdk.OneDec()
|
|
|
|
genesisState = types.NewGenesisState(pool, params, validators, delegations)
|
|
vals, err := InitGenesis(ctx, keeper, genesisState)
|
|
require.NoError(t, err)
|
|
|
|
// now make sure the validators are bonded and intra-tx counters are correct
|
|
resVal, found := keeper.GetValidator(ctx, sdk.ValAddress(keep.Addrs[0]))
|
|
require.True(t, found)
|
|
require.Equal(t, sdk.Bonded, resVal.Status)
|
|
require.Equal(t, int16(0), resVal.BondIntraTxCounter)
|
|
|
|
resVal, found = keeper.GetValidator(ctx, sdk.ValAddress(keep.Addrs[1]))
|
|
require.True(t, found)
|
|
require.Equal(t, sdk.Bonded, resVal.Status)
|
|
require.Equal(t, int16(1), resVal.BondIntraTxCounter)
|
|
|
|
abcivals := make([]abci.Validator, len(vals))
|
|
for i, val := range validators {
|
|
abcivals[i] = sdk.ABCIValidator(val)
|
|
}
|
|
|
|
require.Equal(t, abcivals, vals)
|
|
}
|
|
|
|
func TestInitGenesisLargeValidatorSet(t *testing.T) {
|
|
size := 200
|
|
require.True(t, size > 100)
|
|
|
|
ctx, _, keeper := keep.CreateTestInput(t, false, 1000)
|
|
|
|
// Assigning 2 to the first 100 vals, 1 to the rest
|
|
pool := keeper.GetPool(ctx)
|
|
pool.BondedTokens = sdk.NewDec(int64(200 + (size - 100)))
|
|
|
|
params := keeper.GetParams(ctx)
|
|
delegations := []Delegation{}
|
|
validators := make([]Validator, size)
|
|
|
|
for i := range validators {
|
|
validators[i] = NewValidator(sdk.ValAddress(keep.Addrs[i]), keep.PKs[i], Description{Moniker: fmt.Sprintf("#%d", i)})
|
|
|
|
validators[i].Status = sdk.Bonded
|
|
if i < 100 {
|
|
validators[i].Tokens = sdk.NewDec(2)
|
|
validators[i].DelegatorShares = sdk.NewDec(2)
|
|
} else {
|
|
validators[i].Tokens = sdk.OneDec()
|
|
validators[i].DelegatorShares = sdk.OneDec()
|
|
}
|
|
}
|
|
|
|
genesisState := types.NewGenesisState(pool, params, validators, delegations)
|
|
vals, err := InitGenesis(ctx, keeper, genesisState)
|
|
require.NoError(t, err)
|
|
|
|
abcivals := make([]abci.Validator, 100)
|
|
for i, val := range validators[:100] {
|
|
abcivals[i] = sdk.ABCIValidator(val)
|
|
}
|
|
|
|
require.Equal(t, abcivals, vals)
|
|
}
|