2019-08-13 15:16:03 -07:00
|
|
|
package operations
|
2018-08-16 08:36:15 -07:00
|
|
|
|
|
|
|
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"
|
2018-08-16 08:36:15 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/slashing"
|
|
|
|
)
|
|
|
|
|
2019-07-26 13:09:15 -07:00
|
|
|
// SimulateMsgUnjail generates a MsgUnjail with random values
|
2018-08-26 18:04:52 -07:00
|
|
|
func SimulateMsgUnjail(k slashing.Keeper) simulation.Operation {
|
2019-02-13 15:01:50 -08:00
|
|
|
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) {
|
2019-02-13 15:01:50 -08:00
|
|
|
|
2018-09-22 20:20:53 -07:00
|
|
|
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-07-26 13:09:15 -07:00
|
|
|
return simulation.NoOpMsg(slashing.ModuleName), nil, fmt.Errorf("expected msg to pass ValidateBasic: %s", msg.GetSignBytes())
|
2018-08-29 23:02:15 -07:00
|
|
|
}
|
2018-08-16 08:36:15 -07:00
|
|
|
ctx, write := ctx.CacheContext()
|
2019-03-14 11:13:15 -07:00
|
|
|
ok := slashing.NewHandler(k)(ctx, msg).IsOK()
|
|
|
|
if ok {
|
2018-08-16 08:36:15 -07:00
|
|
|
write()
|
|
|
|
}
|
2019-03-14 11:13:15 -07:00
|
|
|
opMsg = simulation.NewOperationMsg(msg, ok, "")
|
|
|
|
return opMsg, nil, nil
|
2018-08-16 08:36:15 -07:00
|
|
|
}
|
|
|
|
}
|