refactor(crisis): move ValidateBasiclogic to msgServer (#15751)
This commit is contained in:
parent
7a92fd0f1f
commit
22eb756e48
@ -6,6 +6,7 @@ import (
|
||||
"cosmossdk.io/errors"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis/types"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
)
|
||||
@ -15,13 +16,14 @@ var _ types.MsgServer = &Keeper{}
|
||||
// VerifyInvariant implements MsgServer.VerifyInvariant method.
|
||||
// It defines a method to verify a particular invariant.
|
||||
func (k *Keeper) VerifyInvariant(goCtx context.Context, msg *types.MsgVerifyInvariant) (*types.MsgVerifyInvariantResponse, error) {
|
||||
sender, err := sdk.AccAddressFromBech32(msg.Sender)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid sender address: %s", err)
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
constantFee := sdk.NewCoins(k.GetConstantFee(ctx))
|
||||
|
||||
sender, err := sdk.AccAddressFromBech32(msg.Sender)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := k.SendCoinsFromAccountToFeeCollector(ctx, sender, constantFee); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -68,10 +70,22 @@ func (k *Keeper) VerifyInvariant(goCtx context.Context, msg *types.MsgVerifyInva
|
||||
// UpdateParams implements MsgServer.UpdateParams method.
|
||||
// It defines a method to update the x/crisis module parameters.
|
||||
func (k *Keeper) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
|
||||
if _, err := sdk.AccAddressFromBech32(req.Authority); err != nil {
|
||||
return nil, errors.Wrap(err, "invalid authority address")
|
||||
}
|
||||
|
||||
if k.authority != req.Authority {
|
||||
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, req.Authority)
|
||||
}
|
||||
|
||||
if !req.ConstantFee.IsValid() {
|
||||
return nil, errors.Wrap(sdkerrors.ErrInvalidCoins, "invalid constant fee")
|
||||
}
|
||||
|
||||
if req.ConstantFee.IsNegative() {
|
||||
return nil, errors.Wrap(sdkerrors.ErrInvalidCoins, "negative constant fee")
|
||||
}
|
||||
|
||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||
if err := k.SetConstantFee(ctx, req.ConstantFee); err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -34,7 +34,7 @@ func (s *KeeperTestSuite) SetupTest() {
|
||||
key := storetypes.NewKVStoreKey(types.StoreKey)
|
||||
testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test"))
|
||||
encCfg := moduletestutil.MakeTestEncodingConfig(crisis.AppModuleBasic{})
|
||||
keeper := keeper.NewKeeper(encCfg.Codec, key, 5, supplyKeeper, "", "")
|
||||
keeper := keeper.NewKeeper(encCfg.Codec, key, 5, supplyKeeper, "", sdk.AccAddress([]byte("addr1_______________")).String())
|
||||
|
||||
s.ctx = testCtx.Ctx
|
||||
s.keeper = keeper
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
|
||||
)
|
||||
|
||||
@ -35,14 +32,6 @@ func (msg MsgVerifyInvariant) GetSignBytes() []byte {
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// quick validity check
|
||||
func (msg MsgVerifyInvariant) ValidateBasic() error {
|
||||
if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil {
|
||||
return sdkerrors.ErrInvalidAddress.Wrapf("invalid sender address: %s", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FullInvariantRoute - get the messages full invariant route
|
||||
func (msg MsgVerifyInvariant) FullInvariantRoute() string {
|
||||
return msg.InvariantModuleName + "/" + msg.InvariantRoute
|
||||
@ -61,20 +50,3 @@ func (msg MsgUpdateParams) GetSignBytes() []byte {
|
||||
bz := aminoCdc.MustMarshalJSON(&msg)
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// ValidateBasic performs basic MsgUpdateParams message validation.
|
||||
func (msg MsgUpdateParams) ValidateBasic() error {
|
||||
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil {
|
||||
return errorsmod.Wrap(err, "invalid authority address")
|
||||
}
|
||||
|
||||
if !msg.ConstantFee.IsValid() {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "invalid costant fee")
|
||||
}
|
||||
|
||||
if msg.ConstantFee.IsNegative() {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "negative costant fee")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user