## Description There are still some references to simapp in `x/bank` and `x/slashing`. This patch removes them. Somewhat related to forming tests also: - Flags `LegacySubspace exported.Subspace` as ``optional:"true"`` since x/params is moving to deprecation --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
106 lines
4.0 KiB
Go
106 lines
4.0 KiB
Go
package slashing_test
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
|
|
"cosmossdk.io/math"
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
|
"github.com/cosmos/cosmos-sdk/testutil/configurator"
|
|
"github.com/cosmos/cosmos-sdk/testutil/sims"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
|
"github.com/cosmos/cosmos-sdk/x/slashing/keeper"
|
|
"github.com/cosmos/cosmos-sdk/x/slashing/types"
|
|
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
|
)
|
|
|
|
var (
|
|
priv1 = secp256k1.GenPrivKey()
|
|
addr1 = sdk.AccAddress(priv1.PubKey().Address())
|
|
|
|
valKey = ed25519.GenPrivKey()
|
|
valAddr = sdk.AccAddress(valKey.PubKey().Address())
|
|
)
|
|
|
|
func TestSlashingMsgs(t *testing.T) {
|
|
genTokens := sdk.TokensFromConsensusPower(42, sdk.DefaultPowerReduction)
|
|
bondTokens := sdk.TokensFromConsensusPower(10, sdk.DefaultPowerReduction)
|
|
genCoin := sdk.NewCoin(sdk.DefaultBondDenom, genTokens)
|
|
bondCoin := sdk.NewCoin(sdk.DefaultBondDenom, bondTokens)
|
|
|
|
acc1 := &authtypes.BaseAccount{
|
|
Address: addr1.String(),
|
|
}
|
|
accs := []sims.GenesisAccount{{GenesisAccount: acc1, Coins: sdk.Coins{genCoin}}}
|
|
|
|
startupCfg := sims.DefaultStartUpConfig()
|
|
startupCfg.GenesisAccounts = accs
|
|
|
|
var (
|
|
stakingKeeper *stakingkeeper.Keeper
|
|
bankKeeper bankkeeper.Keeper
|
|
slashingKeeper keeper.Keeper
|
|
)
|
|
|
|
app, err := sims.SetupWithConfiguration(configurator.NewAppConfig(
|
|
configurator.ParamsModule(),
|
|
configurator.AuthModule(),
|
|
configurator.StakingModule(),
|
|
configurator.SlashingModule(),
|
|
configurator.TxModule(),
|
|
configurator.BankModule()),
|
|
startupCfg, &stakingKeeper, &bankKeeper, &slashingKeeper)
|
|
|
|
baseApp := app.BaseApp
|
|
|
|
ctxCheck := baseApp.NewContext(true, tmproto.Header{})
|
|
require.True(t, sdk.Coins{genCoin}.IsEqual(bankKeeper.GetAllBalances(ctxCheck, addr1)))
|
|
|
|
require.NoError(t, err)
|
|
|
|
description := stakingtypes.NewDescription("foo_moniker", "", "", "", "")
|
|
commission := stakingtypes.NewCommissionRates(math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec())
|
|
|
|
createValidatorMsg, err := stakingtypes.NewMsgCreateValidator(
|
|
sdk.ValAddress(addr1), valKey.PubKey(), bondCoin, description, commission, math.OneInt(),
|
|
)
|
|
require.NoError(t, err)
|
|
|
|
header := tmproto.Header{Height: app.LastBlockHeight() + 1}
|
|
txConfig := moduletestutil.MakeTestEncodingConfig().TxConfig
|
|
_, _, err = sims.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{createValidatorMsg}, "", []uint64{0}, []uint64{0}, true, true, priv1)
|
|
require.NoError(t, err)
|
|
require.True(t, sdk.Coins{genCoin.Sub(bondCoin)}.IsEqual(bankKeeper.GetAllBalances(ctxCheck, addr1)))
|
|
|
|
header = tmproto.Header{Height: app.LastBlockHeight() + 1}
|
|
app.BeginBlock(abci.RequestBeginBlock{Header: header})
|
|
|
|
ctxCheck = baseApp.NewContext(true, tmproto.Header{})
|
|
validator, found := stakingKeeper.GetValidator(ctxCheck, sdk.ValAddress(addr1))
|
|
require.True(t, found)
|
|
require.Equal(t, sdk.ValAddress(addr1).String(), validator.OperatorAddress)
|
|
require.Equal(t, stakingtypes.Bonded, validator.Status)
|
|
require.True(math.IntEq(t, bondTokens, validator.BondedTokens()))
|
|
unjailMsg := &types.MsgUnjail{ValidatorAddr: sdk.ValAddress(addr1).String()}
|
|
|
|
ctxCheck = app.BaseApp.NewContext(true, tmproto.Header{})
|
|
_, found = slashingKeeper.GetValidatorSigningInfo(ctxCheck, sdk.ConsAddress(valAddr))
|
|
require.True(t, found)
|
|
|
|
// unjail should fail with unknown validator
|
|
header = tmproto.Header{Height: app.LastBlockHeight() + 1}
|
|
_, res, err := sims.SignCheckDeliver(t, txConfig, app.BaseApp, header, []sdk.Msg{unjailMsg}, "", []uint64{0}, []uint64{1}, false, false, priv1)
|
|
require.Error(t, err)
|
|
require.Nil(t, res)
|
|
require.True(t, errors.Is(types.ErrValidatorNotJailed, err))
|
|
}
|