60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
package simulation
|
|
|
|
import (
|
|
"encoding/json"
|
|
"math/rand"
|
|
"testing"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
|
"github.com/cosmos/cosmos-sdk/x/mock"
|
|
"github.com/cosmos/cosmos-sdk/x/mock/simulation"
|
|
"github.com/cosmos/cosmos-sdk/x/stake"
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
)
|
|
|
|
// TestStakeWithRandomMessages
|
|
func TestStakeWithRandomMessages(t *testing.T) {
|
|
mapp := mock.NewApp()
|
|
|
|
bank.RegisterWire(mapp.Cdc)
|
|
mapper := mapp.AccountMapper
|
|
coinKeeper := bank.NewKeeper(mapper)
|
|
stakeKey := sdk.NewKVStoreKey("stake")
|
|
stakeKeeper := stake.NewKeeper(mapp.Cdc, stakeKey, coinKeeper, stake.DefaultCodespace)
|
|
mapp.Router().AddRoute("stake", stake.NewHandler(stakeKeeper))
|
|
mapp.SetEndBlocker(func(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
|
|
validatorUpdates := stake.EndBlocker(ctx, stakeKeeper)
|
|
return abci.ResponseEndBlock{
|
|
ValidatorUpdates: validatorUpdates,
|
|
}
|
|
})
|
|
|
|
err := mapp.CompleteSetup([]*sdk.KVStoreKey{stakeKey})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
appStateFn := func(r *rand.Rand, accs []sdk.AccAddress) json.RawMessage {
|
|
mock.RandomSetGenesis(r, mapp, accs, []string{"stake"})
|
|
return json.RawMessage("{}")
|
|
}
|
|
|
|
simulation.Simulate(
|
|
t, mapp.BaseApp, appStateFn,
|
|
[]simulation.TestAndRunTx{
|
|
SimulateMsgCreateValidator(mapper, stakeKeeper),
|
|
SimulateMsgEditValidator(stakeKeeper),
|
|
SimulateMsgDelegate(mapper, stakeKeeper),
|
|
SimulateMsgBeginUnbonding(mapper, stakeKeeper),
|
|
SimulateMsgCompleteUnbonding(stakeKeeper),
|
|
SimulateMsgBeginRedelegate(mapper, stakeKeeper),
|
|
SimulateMsgCompleteRedelegate(stakeKeeper),
|
|
}, []simulation.RandSetup{
|
|
Setup(mapp, stakeKeeper),
|
|
}, []simulation.Invariant{
|
|
AllInvariants(coinKeeper, stakeKeeper, mapp.AccountMapper),
|
|
}, 10, 100, 100,
|
|
)
|
|
}
|