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"
|
|
|
|
|
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()
|
|
|
|
|
2018-09-13 11:17:32 -07:00
|
|
|
bank.RegisterCodec(mapp.Cdc)
|
2018-07-10 17:36:50 -07:00
|
|
|
mapper := mapp.AccountMapper
|
2018-09-10 11:25:34 -07:00
|
|
|
bankKeeper := bank.NewBaseKeeper(mapper)
|
2018-07-10 11:46:28 -07:00
|
|
|
stakeKey := sdk.NewKVStoreKey("stake")
|
2018-09-12 21:53:55 -07:00
|
|
|
stakeTKey := sdk.NewTransientStoreKey("transient_stake")
|
|
|
|
stakeKeeper := stake.NewKeeper(mapp.Cdc, stakeKey, stakeTKey, 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
|
|
|
|
2018-09-12 21:53:55 -07:00
|
|
|
err := mapp.CompleteSetup(stakeKey, stakeTKey)
|
2018-07-10 11:46:28 -07:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2018-09-22 20:20:53 -07:00
|
|
|
appStateFn := func(r *rand.Rand, accs []simulation.Account) json.RawMessage {
|
|
|
|
simulation.RandomSetGenesis(r, mapp, accs, []string{"stake"})
|
2018-07-17 16:01:36 -07:00
|
|
|
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-09-12 00:16:52 -07:00
|
|
|
[]simulation.WeightedOperation{
|
|
|
|
{10, SimulateMsgCreateValidator(mapper, stakeKeeper)},
|
|
|
|
{5, SimulateMsgEditValidator(stakeKeeper)},
|
|
|
|
{15, SimulateMsgDelegate(mapper, stakeKeeper)},
|
|
|
|
{10, SimulateMsgBeginUnbonding(mapper, stakeKeeper)},
|
|
|
|
{10, SimulateMsgBeginRedelegate(mapper, 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
|
|
|
)
|
|
|
|
}
|