2018-08-16 08:36:15 -07:00
|
|
|
package simulation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
|
|
|
|
"github.com/tendermint/tendermint/crypto"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/mock/simulation"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/slashing"
|
|
|
|
)
|
|
|
|
|
2018-08-22 08:56:13 -07:00
|
|
|
// SimulateMsgUnjail
|
2018-08-26 18:04:52 -07:00
|
|
|
func SimulateMsgUnjail(k slashing.Keeper) simulation.Operation {
|
2018-09-09 08:34:09 -07:00
|
|
|
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, keys []crypto.PrivKey, event func(string)) (action string, fOp []simulation.FutureOperation, err error) {
|
2018-08-16 08:36:15 -07:00
|
|
|
key := simulation.RandomKey(r, keys)
|
2018-08-30 21:06:44 -07:00
|
|
|
address := sdk.ValAddress(key.PubKey().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 {
|
2018-09-09 08:34:09 -07:00
|
|
|
return "", 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()
|
|
|
|
result := slashing.NewHandler(k)(ctx, msg)
|
|
|
|
if result.IsOK() {
|
|
|
|
write()
|
|
|
|
}
|
2018-08-22 08:56:13 -07:00
|
|
|
event(fmt.Sprintf("slashing/MsgUnjail/%v", result.IsOK()))
|
|
|
|
action = fmt.Sprintf("TestMsgUnjail: ok %v, msg %s", result.IsOK(), msg.GetSignBytes())
|
2018-08-27 14:27:00 -07:00
|
|
|
return action, nil, nil
|
2018-08-16 08:36:15 -07:00
|
|
|
}
|
|
|
|
}
|