2019-09-27 18:48:57 +00:00
|
|
|
package validatorvesting
|
|
|
|
|
|
|
|
// nolint
|
|
|
|
// DONTCOVER
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
"github.com/tendermint/tendermint/crypto"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-10-02 13:10:28 +00:00
|
|
|
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
|
2019-09-27 18:48:57 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/mock"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/supply"
|
|
|
|
supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported"
|
2020-04-30 14:13:31 +00:00
|
|
|
|
2020-04-04 23:26:15 +00:00
|
|
|
"github.com/kava-labs/kava/x/validator-vesting/keeper"
|
|
|
|
"github.com/kava-labs/kava/x/validator-vesting/types"
|
2019-09-27 18:48:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
valTokens = sdk.TokensFromConsensusPower(42)
|
|
|
|
initTokens = sdk.TokensFromConsensusPower(100000)
|
|
|
|
valCoins = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, valTokens))
|
|
|
|
initCoins = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens))
|
|
|
|
)
|
|
|
|
|
|
|
|
type testInput struct {
|
|
|
|
mApp *mock.App
|
|
|
|
keeper keeper.Keeper
|
|
|
|
sk staking.Keeper
|
|
|
|
addrs []sdk.AccAddress
|
|
|
|
pubKeys []crypto.PubKey
|
|
|
|
privKeys []crypto.PrivKey
|
|
|
|
}
|
|
|
|
|
2019-10-02 13:10:28 +00:00
|
|
|
func getMockApp(t *testing.T, numGenAccs int, genState types.GenesisState, genAccs []authexported.Account) testInput {
|
2019-09-27 18:48:57 +00:00
|
|
|
mApp := mock.NewApp()
|
|
|
|
|
|
|
|
staking.RegisterCodec(mApp.Cdc)
|
|
|
|
types.RegisterCodec(mApp.Cdc)
|
|
|
|
supply.RegisterCodec(mApp.Cdc)
|
|
|
|
|
|
|
|
keyStaking := sdk.NewKVStoreKey(staking.StoreKey)
|
|
|
|
keyValidatorVesting := sdk.NewKVStoreKey(types.StoreKey)
|
|
|
|
keySupply := sdk.NewKVStoreKey(supply.StoreKey)
|
|
|
|
|
|
|
|
validatorVestingAcc := supply.NewEmptyModuleAccount(types.ModuleName, supply.Burner)
|
|
|
|
notBondedPool := supply.NewEmptyModuleAccount(staking.NotBondedPoolName, supply.Burner, supply.Staking)
|
|
|
|
bondPool := supply.NewEmptyModuleAccount(staking.BondedPoolName, supply.Burner, supply.Staking)
|
|
|
|
|
|
|
|
blacklistedAddrs := make(map[string]bool)
|
|
|
|
blacklistedAddrs[validatorVestingAcc.GetAddress().String()] = true
|
|
|
|
blacklistedAddrs[notBondedPool.GetAddress().String()] = true
|
|
|
|
blacklistedAddrs[bondPool.GetAddress().String()] = true
|
|
|
|
|
|
|
|
pk := mApp.ParamsKeeper
|
|
|
|
|
2020-04-23 16:35:58 +00:00
|
|
|
bk := bank.NewBaseKeeper(mApp.AccountKeeper, mApp.ParamsKeeper.Subspace(bank.DefaultParamspace), blacklistedAddrs)
|
2019-09-27 18:48:57 +00:00
|
|
|
|
|
|
|
maccPerms := map[string][]string{
|
|
|
|
types.ModuleName: {supply.Burner},
|
|
|
|
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
|
|
|
|
staking.BondedPoolName: {supply.Burner, supply.Staking},
|
|
|
|
}
|
|
|
|
supplyKeeper := supply.NewKeeper(mApp.Cdc, keySupply, mApp.AccountKeeper, bk, maccPerms)
|
|
|
|
sk := staking.NewKeeper(
|
2020-04-23 16:35:58 +00:00
|
|
|
mApp.Cdc, keyStaking, supplyKeeper, pk.Subspace(staking.DefaultParamspace),
|
2019-09-27 18:48:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
keeper := keeper.NewKeeper(
|
|
|
|
mApp.Cdc, keyValidatorVesting, mApp.AccountKeeper, bk, supplyKeeper, sk)
|
|
|
|
|
|
|
|
mApp.SetBeginBlocker(getBeginBlocker(keeper))
|
|
|
|
mApp.SetInitChainer(getInitChainer(mApp, keeper, sk, supplyKeeper, genAccs, genState,
|
|
|
|
[]supplyexported.ModuleAccountI{validatorVestingAcc, notBondedPool, bondPool}))
|
|
|
|
|
|
|
|
require.NoError(t, mApp.CompleteSetup(keyStaking, keyValidatorVesting, keySupply))
|
|
|
|
|
|
|
|
var (
|
|
|
|
addrs []sdk.AccAddress
|
|
|
|
pubKeys []crypto.PubKey
|
|
|
|
privKeys []crypto.PrivKey
|
|
|
|
)
|
|
|
|
|
|
|
|
if genAccs == nil || len(genAccs) == 0 {
|
|
|
|
genAccs, addrs, pubKeys, privKeys = mock.CreateGenAccounts(numGenAccs, valCoins)
|
|
|
|
}
|
|
|
|
|
|
|
|
mock.SetGenesis(mApp, genAccs)
|
|
|
|
|
|
|
|
return testInput{mApp, keeper, sk, addrs, pubKeys, privKeys}
|
|
|
|
}
|
|
|
|
|
|
|
|
// gov and staking endblocker
|
|
|
|
func getBeginBlocker(keeper Keeper) sdk.BeginBlocker {
|
|
|
|
return func(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
|
|
|
|
BeginBlocker(ctx, req, keeper)
|
|
|
|
return abci.ResponseBeginBlock{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// gov and staking initchainer
|
2019-10-02 13:10:28 +00:00
|
|
|
func getInitChainer(mapp *mock.App, keeper Keeper, stakingKeeper staking.Keeper, supplyKeeper supply.Keeper, accs []authexported.Account, genState GenesisState,
|
2019-09-27 18:48:57 +00:00
|
|
|
blacklistedAddrs []supplyexported.ModuleAccountI) sdk.InitChainer {
|
|
|
|
return func(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
|
|
|
|
mapp.InitChainer(ctx, req)
|
|
|
|
|
|
|
|
stakingGenesis := staking.DefaultGenesisState()
|
|
|
|
|
|
|
|
totalSupply := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens.MulRaw(int64(len(mapp.GenesisAccounts)))))
|
|
|
|
supplyKeeper.SetSupply(ctx, supply.NewSupply(totalSupply))
|
|
|
|
|
|
|
|
// set module accounts
|
|
|
|
for _, macc := range blacklistedAddrs {
|
|
|
|
supplyKeeper.SetModuleAccount(ctx, macc)
|
|
|
|
}
|
|
|
|
|
|
|
|
validators := staking.InitGenesis(ctx, stakingKeeper, mapp.AccountKeeper, supplyKeeper, stakingGenesis)
|
|
|
|
if genState.IsEmpty() {
|
2019-10-02 13:10:28 +00:00
|
|
|
InitGenesis(ctx, keeper, mapp.AccountKeeper, types.DefaultGenesisState())
|
2019-09-27 18:48:57 +00:00
|
|
|
} else {
|
2019-10-02 13:10:28 +00:00
|
|
|
InitGenesis(ctx, keeper, mapp.AccountKeeper, genState)
|
2019-09-27 18:48:57 +00:00
|
|
|
}
|
|
|
|
return abci.ResponseInitChain{
|
|
|
|
Validators: validators,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|