refactor: remove .Type() and .Route() from msgs (#14751)
This commit is contained in:
@@ -52,33 +52,35 @@ func SimulateMsgUnjail(cdc *codec.ProtoCodec, ak types.AccountKeeper, bk types.B
|
||||
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context,
|
||||
accs []simtypes.Account, chainID string,
|
||||
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
|
||||
msgType := sdk.MsgTypeURL(&types.MsgUnjail{})
|
||||
|
||||
validator, ok := testutil.RandSliceElem(r, sk.GetAllValidators(ctx))
|
||||
if !ok {
|
||||
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "validator is not ok"), nil, nil // skip
|
||||
return simtypes.NoOpMsg(types.ModuleName, msgType, "validator is not ok"), nil, nil // skip
|
||||
}
|
||||
|
||||
simAccount, found := simtypes.FindAccount(accs, sdk.AccAddress(validator.GetOperator()))
|
||||
if !found {
|
||||
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "unable to find account"), nil, nil // skip
|
||||
return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to find account"), nil, nil // skip
|
||||
}
|
||||
|
||||
if !validator.IsJailed() {
|
||||
// TODO: due to this condition this message is almost, if not always, skipped !
|
||||
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "validator is not jailed"), nil, nil
|
||||
return simtypes.NoOpMsg(types.ModuleName, msgType, "validator is not jailed"), nil, nil
|
||||
}
|
||||
|
||||
consAddr, err := validator.GetConsAddr()
|
||||
if err != nil {
|
||||
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "unable to get validator consensus key"), nil, err
|
||||
return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to get validator consensus key"), nil, err
|
||||
}
|
||||
info, found := k.GetValidatorSigningInfo(ctx, consAddr)
|
||||
if !found {
|
||||
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "unable to find validator signing info"), nil, nil // skip
|
||||
return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to find validator signing info"), nil, nil // skip
|
||||
}
|
||||
|
||||
selfDel := sk.Delegation(ctx, simAccount.Address, validator.GetOperator())
|
||||
if selfDel == nil {
|
||||
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "self delegation is nil"), nil, nil // skip
|
||||
return simtypes.NoOpMsg(types.ModuleName, msgType, "self delegation is nil"), nil, nil // skip
|
||||
}
|
||||
|
||||
account := ak.GetAccount(ctx, sdk.AccAddress(validator.GetOperator()))
|
||||
@@ -86,7 +88,7 @@ func SimulateMsgUnjail(cdc *codec.ProtoCodec, ak types.AccountKeeper, bk types.B
|
||||
|
||||
fees, err := simtypes.RandomFees(r, ctx, spendable)
|
||||
if err != nil {
|
||||
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "unable to generate fees"), nil, err
|
||||
return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to generate fees"), nil, err
|
||||
}
|
||||
|
||||
msg := types.NewMsgUnjail(validator.GetOperator())
|
||||
@@ -104,7 +106,7 @@ func SimulateMsgUnjail(cdc *codec.ProtoCodec, ak types.AccountKeeper, bk types.B
|
||||
simAccount.PrivKey,
|
||||
)
|
||||
if err != nil {
|
||||
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err
|
||||
return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate mock tx"), nil, err
|
||||
}
|
||||
|
||||
_, res, err := app.SimDeliver(txGen.TxEncoder(), tx)
|
||||
@@ -132,7 +134,7 @@ func SimulateMsgUnjail(cdc *codec.ProtoCodec, ak types.AccountKeeper, bk types.B
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, errors.New(res.Log)
|
||||
return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, errors.New(res.Log)
|
||||
}
|
||||
|
||||
return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil
|
||||
|
||||
@@ -123,7 +123,9 @@ func (suite *SimTestSuite) TestWeightedOperations() {
|
||||
weight int
|
||||
opMsgRoute string
|
||||
opMsgName string
|
||||
}{{simulation.DefaultWeightMsgUnjail, types.ModuleName, types.TypeMsgUnjail}}
|
||||
}{
|
||||
{simulation.DefaultWeightMsgUnjail, types.ModuleName, sdk.MsgTypeURL(&types.MsgUnjail{})},
|
||||
}
|
||||
|
||||
weightesOps := simulation.WeightedOperations(appParams, suite.codec, suite.accountKeeper, suite.bankKeeper, suite.slashingKeeper, suite.stakingKeeper)
|
||||
for i, w := range weightesOps {
|
||||
@@ -181,7 +183,6 @@ func (suite *SimTestSuite) TestSimulateMsgUnjail() {
|
||||
types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg)
|
||||
|
||||
suite.Require().True(operationMsg.OK)
|
||||
suite.Require().Equal(types.TypeMsgUnjail, msg.Type())
|
||||
suite.Require().Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddr)
|
||||
suite.Require().Len(futureOperations, 0)
|
||||
}
|
||||
|
||||
+6
-13
@@ -3,17 +3,16 @@ package types
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
)
|
||||
|
||||
// slashing message types
|
||||
const (
|
||||
TypeMsgUnjail = "unjail"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
|
||||
)
|
||||
|
||||
// verify interface at compile time
|
||||
var (
|
||||
_ sdk.Msg = &MsgUnjail{}
|
||||
_ sdk.Msg = &MsgUpdateParams{}
|
||||
|
||||
_ legacytx.LegacyMsg = &MsgUnjail{}
|
||||
_ legacytx.LegacyMsg = &MsgUpdateParams{}
|
||||
)
|
||||
|
||||
// NewMsgUnjail creates a new MsgUnjail instance
|
||||
@@ -25,12 +24,6 @@ func NewMsgUnjail(validatorAddr sdk.ValAddress) *MsgUnjail {
|
||||
}
|
||||
}
|
||||
|
||||
// Route implements the sdk.Msg interface.
|
||||
func (msg MsgUnjail) Route() string { return RouterKey }
|
||||
|
||||
// Type implements the sdk.Msg interface.
|
||||
func (msg MsgUnjail) Type() string { return TypeMsgUnjail }
|
||||
|
||||
// GetSigners returns the expected signers for MsgUnjail.
|
||||
func (msg MsgUnjail) GetSigners() []sdk.AccAddress {
|
||||
valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddr)
|
||||
@@ -57,13 +50,13 @@ func (msg MsgUpdateParams) GetSignBytes() []byte {
|
||||
}
|
||||
|
||||
// GetSigners returns the expected signers for a MsgUpdateParams message.
|
||||
func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress {
|
||||
func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress {
|
||||
addr, _ := sdk.AccAddressFromBech32(msg.Authority)
|
||||
return []sdk.AccAddress{addr}
|
||||
}
|
||||
|
||||
// ValidateBasic does a sanity check on the provided data.
|
||||
func (msg *MsgUpdateParams) ValidateBasic() error {
|
||||
func (msg MsgUpdateParams) ValidateBasic() error {
|
||||
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil {
|
||||
return sdkerrors.Wrap(err, "invalid authority address")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user