* stake/fees spec updates * staking overview.md revisions, moving files * docs reorganization * staking spec state revisions * transaction stake updates * complete staking spec update * WIP adding unbonding/redelegation commands * added msg types for unbonding, redelegation * stake sub-package reorg * working stake reorg * modify lcd tests to not use hardcoded json strings * add description update * index keys * key managment for unbonding redelegation complete * update stake errors * completed handleMsgCompleteUnbonding fn * updated to use begin/complete unbonding/redelegation * fix token shares bug * develop docs into unbonding * got non-tests compiling after merge develop * working fixing tests * PrivlegedKeeper -> PrivilegedKeeper * tests compile * fix some tests * fixing tests * remove PrivilegedKeeper * get unbonding bug * only rpc sig verification failed tests now * move percent unbonding/redelegation to the CLI and out of handler logic * remove min unbonding height * add lcd txs * add pool sanity checks, fix a buncha tests * fix ante. set lcd log to debug (#1322) * redelegation tests, adding query functionality for bonds * add self-delegations at genesis ref #1165 * PR comments (mostly) addressed * cleanup, added Query LCD functionality * test cleanup/fixes * fix governance test * SlashValidatorSet -> ValidatorSet * changelog * stake lcd fix * x/auth: fix chainID in ante * fix lcd test * fix lint, update lint make command for spelling * lowercase error string * don't expose coinkeeper in staking * remove a few duplicate lines in changelog * chain_id in stake lcd tests * added transient redelegation * 'transient' => 'transitive' * Re-add nolint instruction * Fix tiny linter error
100 lines
2.9 KiB
Go
100 lines
2.9 KiB
Go
package slashing
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
abci "github.com/tendermint/abci/types"
|
|
crypto "github.com/tendermint/go-crypto"
|
|
dbm "github.com/tendermint/tmlibs/db"
|
|
"github.com/tendermint/tmlibs/log"
|
|
|
|
"github.com/cosmos/cosmos-sdk/store"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/wire"
|
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
|
"github.com/cosmos/cosmos-sdk/x/stake"
|
|
)
|
|
|
|
// TODO remove dependencies on staking (should only refer to validator set type from sdk)
|
|
|
|
var (
|
|
addrs = []sdk.Address{
|
|
testAddr("A58856F0FD53BF058B4909A21AEC019107BA6160"),
|
|
testAddr("A58856F0FD53BF058B4909A21AEC019107BA6161"),
|
|
testAddr("A58856F0FD53BF058B4909A21AEC019107BA6162"),
|
|
}
|
|
pks = []crypto.PubKey{
|
|
newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB50"),
|
|
newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB51"),
|
|
newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB52"),
|
|
}
|
|
initCoins sdk.Int = sdk.NewInt(200)
|
|
)
|
|
|
|
func createTestCodec() *wire.Codec {
|
|
cdc := wire.NewCodec()
|
|
sdk.RegisterWire(cdc)
|
|
auth.RegisterWire(cdc)
|
|
bank.RegisterWire(cdc)
|
|
stake.RegisterWire(cdc)
|
|
wire.RegisterCrypto(cdc)
|
|
return cdc
|
|
}
|
|
|
|
func createTestInput(t *testing.T) (sdk.Context, bank.Keeper, stake.Keeper, Keeper) {
|
|
keyAcc := sdk.NewKVStoreKey("acc")
|
|
keyStake := sdk.NewKVStoreKey("stake")
|
|
keySlashing := sdk.NewKVStoreKey("slashing")
|
|
db := dbm.NewMemDB()
|
|
ms := store.NewCommitMultiStore(db)
|
|
ms.MountStoreWithDB(keyAcc, sdk.StoreTypeIAVL, db)
|
|
ms.MountStoreWithDB(keyStake, sdk.StoreTypeIAVL, db)
|
|
ms.MountStoreWithDB(keySlashing, sdk.StoreTypeIAVL, db)
|
|
err := ms.LoadLatestVersion()
|
|
require.Nil(t, err)
|
|
ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewTMLogger(os.Stdout))
|
|
cdc := createTestCodec()
|
|
accountMapper := auth.NewAccountMapper(cdc, keyAcc, &auth.BaseAccount{})
|
|
ck := bank.NewKeeper(accountMapper)
|
|
sk := stake.NewKeeper(cdc, keyStake, ck, stake.DefaultCodespace)
|
|
genesis := stake.DefaultGenesisState()
|
|
genesis.Pool.LooseTokens = initCoins.MulRaw(int64(len(addrs))).Int64()
|
|
stake.InitGenesis(ctx, sk, genesis)
|
|
for _, addr := range addrs {
|
|
ck.AddCoins(ctx, addr, sdk.Coins{
|
|
{sk.GetParams(ctx).BondDenom, initCoins},
|
|
})
|
|
}
|
|
keeper := NewKeeper(cdc, keySlashing, sk, DefaultCodespace)
|
|
return ctx, ck, sk, keeper
|
|
}
|
|
|
|
func newPubKey(pk string) (res crypto.PubKey) {
|
|
pkBytes, err := hex.DecodeString(pk)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
var pkEd crypto.PubKeyEd25519
|
|
copy(pkEd[:], pkBytes[:])
|
|
return pkEd
|
|
}
|
|
|
|
func testAddr(addr string) sdk.Address {
|
|
res := []byte(addr)
|
|
return res
|
|
}
|
|
|
|
func newTestMsgCreateValidator(address sdk.Address, pubKey crypto.PubKey, amt sdk.Int) stake.MsgCreateValidator {
|
|
return stake.MsgCreateValidator{
|
|
Description: stake.Description{},
|
|
ValidatorAddr: address,
|
|
PubKey: pubKey,
|
|
SelfDelegation: sdk.Coin{"steak", amt},
|
|
}
|
|
}
|