2018-07-11 10:43:25 -07:00
|
|
|
package simulation
|
2018-07-10 11:46:28 -07:00
|
|
|
|
|
|
|
import (
|
2018-07-17 11:50:30 -07:00
|
|
|
"encoding/json"
|
2018-07-17 16:01:36 -07:00
|
|
|
"math/rand"
|
2018-07-10 11:46:28 -07:00
|
|
|
"testing"
|
|
|
|
|
2018-08-16 08:36:15 -07:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
"github.com/tendermint/tendermint/crypto"
|
|
|
|
|
2018-07-10 11:46:28 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/mock"
|
2018-07-17 11:50:30 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/mock/simulation"
|
2018-07-11 10:43:25 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/stake"
|
2018-07-10 19:36:12 -07:00
|
|
|
)
|
|
|
|
|
2018-07-10 17:36:50 -07:00
|
|
|
// TestStakeWithRandomMessages
|
2018-07-10 11:46:28 -07:00
|
|
|
func TestStakeWithRandomMessages(t *testing.T) {
|
|
|
|
mapp := mock.NewApp()
|
|
|
|
|
|
|
|
bank.RegisterWire(mapp.Cdc)
|
2018-07-10 17:36:50 -07:00
|
|
|
mapper := mapp.AccountMapper
|
2018-09-07 22:34:32 -07:00
|
|
|
bankKeeper := bank.NewKeeper(mapper)
|
2018-07-10 11:46:28 -07:00
|
|
|
stakeKey := sdk.NewKVStoreKey("stake")
|
2018-09-07 22:34:32 -07:00
|
|
|
stakeKeeper := stake.NewKeeper(mapp.Cdc, stakeKey, bankKeeper, stake.DefaultCodespace)
|
2018-07-11 10:43:25 -07:00
|
|
|
mapp.Router().AddRoute("stake", stake.NewHandler(stakeKeeper))
|
2018-07-10 19:36:12 -07:00
|
|
|
mapp.SetEndBlocker(func(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
|
2018-07-11 10:43:25 -07:00
|
|
|
validatorUpdates := stake.EndBlocker(ctx, stakeKeeper)
|
2018-07-10 19:36:12 -07:00
|
|
|
return abci.ResponseEndBlock{
|
|
|
|
ValidatorUpdates: validatorUpdates,
|
|
|
|
}
|
|
|
|
})
|
2018-07-10 11:46:28 -07:00
|
|
|
|
|
|
|
err := mapp.CompleteSetup([]*sdk.KVStoreKey{stakeKey})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2018-08-16 08:36:15 -07:00
|
|
|
appStateFn := func(r *rand.Rand, keys []crypto.PrivKey, accs []sdk.AccAddress) json.RawMessage {
|
2018-07-17 16:01:36 -07:00
|
|
|
mock.RandomSetGenesis(r, mapp, accs, []string{"stake"})
|
|
|
|
return json.RawMessage("{}")
|
|
|
|
}
|
|
|
|
|
2018-07-17 11:50:30 -07:00
|
|
|
simulation.Simulate(
|
2018-07-17 16:01:36 -07:00
|
|
|
t, mapp.BaseApp, appStateFn,
|
2018-08-26 18:04:52 -07:00
|
|
|
[]simulation.Operation{
|
2018-07-10 17:36:50 -07:00
|
|
|
SimulateMsgCreateValidator(mapper, stakeKeeper),
|
|
|
|
SimulateMsgEditValidator(stakeKeeper),
|
2018-07-10 19:36:12 -07:00
|
|
|
SimulateMsgDelegate(mapper, stakeKeeper),
|
2018-07-17 22:37:38 -07:00
|
|
|
SimulateMsgBeginUnbonding(mapper, stakeKeeper),
|
2018-07-10 17:36:50 -07:00
|
|
|
SimulateMsgCompleteUnbonding(stakeKeeper),
|
2018-07-12 16:54:07 -07:00
|
|
|
SimulateMsgBeginRedelegate(mapper, stakeKeeper),
|
2018-07-10 17:36:50 -07:00
|
|
|
SimulateMsgCompleteRedelegate(stakeKeeper),
|
2018-07-17 11:50:30 -07:00
|
|
|
}, []simulation.RandSetup{
|
2018-07-17 22:50:04 -07:00
|
|
|
Setup(mapp, stakeKeeper),
|
2018-07-17 11:50:30 -07:00
|
|
|
}, []simulation.Invariant{
|
2018-09-07 22:34:32 -07:00
|
|
|
AllInvariants(bankKeeper, stakeKeeper, mapp.AccountMapper),
|
2018-08-16 08:36:15 -07:00
|
|
|
}, 10, 100,
|
2018-08-16 14:45:07 -07:00
|
|
|
false,
|
2018-07-10 11:46:28 -07:00
|
|
|
)
|
|
|
|
}
|