cosmos-sdk/x/slashing/simulation/msgs.go

33 lines
941 B
Go
Raw Normal View History

package simulation
import (
"fmt"
"math/rand"
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
2019-03-14 11:13:15 -07:00
"github.com/cosmos/cosmos-sdk/x/simulation"
"github.com/cosmos/cosmos-sdk/x/slashing"
)
2018-08-22 08:56:13 -07:00
// SimulateMsgUnjail
func SimulateMsgUnjail(k slashing.Keeper) simulation.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context,
2019-03-14 11:13:15 -07:00
accs []simulation.Account) (opMsg simulation.OperationMsg, fOps []simulation.FutureOperation, err error) {
acc := simulation.RandomAcc(r, accs)
address := sdk.ValAddress(acc.Address)
2018-08-22 08:56:13 -07:00
msg := slashing.NewMsgUnjail(address)
2018-08-29 23:02:15 -07:00
if msg.ValidateBasic() != nil {
2019-03-14 11:13:15 -07:00
return simulation.NoOpMsg(), nil, fmt.Errorf("expected msg to pass ValidateBasic: %s", msg.GetSignBytes())
2018-08-29 23:02:15 -07:00
}
ctx, write := ctx.CacheContext()
2019-03-14 11:13:15 -07:00
ok := slashing.NewHandler(k)(ctx, msg).IsOK()
if ok {
write()
}
2019-03-14 11:13:15 -07:00
opMsg = simulation.NewOperationMsg(msg, ok, "")
return opMsg, nil, nil
}
}