From f2d4d84768a74f837eece318f4b2c9fa557c3f81 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Mon, 4 Mar 2024 18:12:24 -0500 Subject: [PATCH] fixed to error messages --- x/emissions/client/cli/tx.go | 2 +- ..._withdraw_emssions.go => tx_withdraw_emssions.go} | 4 ++-- x/emissions/keeper/msg_server_withdraw_emissions.go | 2 +- x/emissions/types/errors.go | 12 +++++------- x/emissions/types/message_withdraw_emissions.go | 4 ++-- x/emissions/types/message_withdraw_emissons_test.go | 6 ++++++ 6 files changed, 17 insertions(+), 13 deletions(-) rename x/emissions/client/cli/{tx_create_withdraw_emssions.go => tx_withdraw_emssions.go} (90%) diff --git a/x/emissions/client/cli/tx.go b/x/emissions/client/cli/tx.go index 78bcee33b5..888a192327 100644 --- a/x/emissions/client/cli/tx.go +++ b/x/emissions/client/cli/tx.go @@ -18,6 +18,6 @@ func GetTxCmd() *cobra.Command { SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, } - cmd.AddCommand(CmdCreateWithdrawEmission()) + cmd.AddCommand(CmdWithdrawEmission()) return cmd } diff --git a/x/emissions/client/cli/tx_create_withdraw_emssions.go b/x/emissions/client/cli/tx_withdraw_emssions.go similarity index 90% rename from x/emissions/client/cli/tx_create_withdraw_emssions.go rename to x/emissions/client/cli/tx_withdraw_emssions.go index a3a60fb406..fff24330dd 100644 --- a/x/emissions/client/cli/tx_create_withdraw_emssions.go +++ b/x/emissions/client/cli/tx_withdraw_emssions.go @@ -11,9 +11,9 @@ import ( "github.com/zeta-chain/zetacore/x/emissions/types" ) -func CmdCreateWithdrawEmission() *cobra.Command { +func CmdWithdrawEmission() *cobra.Command { cmd := &cobra.Command{ - Use: "create-withdraw-emission [amount]", + Use: "withdraw-emission [amount]", Short: "create a new withdrawEmission", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { diff --git a/x/emissions/keeper/msg_server_withdraw_emissions.go b/x/emissions/keeper/msg_server_withdraw_emissions.go index 1fa1287540..213906ccdf 100644 --- a/x/emissions/keeper/msg_server_withdraw_emissions.go +++ b/x/emissions/keeper/msg_server_withdraw_emissions.go @@ -32,7 +32,7 @@ func (k msgServer) WithdrawEmission(goCtx context.Context, msg *types.MsgWithdra err = k.RemoveWithdrawableEmission(ctx, msg.Creator, msg.Amount) if err != nil { - return nil, errorsmod.Wrap(types.ErrUnableToWithdrawEmissions, err.Error()) + return nil, errorsmod.Wrap(types.ErrUnableToWithdrawEmissions, fmt.Sprintf("error while removing withdrawable emission for address %s : %s", msg.Creator, err)) } err = k.GetBankKeeper().SendCoinsFromModuleToAccount(ctx, types.UndistributedObserverRewardsPool, address, sdk.NewCoins(sdk.NewCoin(config.BaseDenom, msg.Amount))) if err != nil { diff --git a/x/emissions/types/errors.go b/x/emissions/types/errors.go index e5f778bc25..e741408d81 100644 --- a/x/emissions/types/errors.go +++ b/x/emissions/types/errors.go @@ -2,12 +2,10 @@ package types import errorsmod "cosmossdk.io/errors" -// DONTCOVER - var ( - ErrEmissionsNotFound = errorsmod.Register(ModuleName, 1000, "Emissions not found") - ErrUnableToWithdrawEmissions = errorsmod.Register(ModuleName, 1002, "Unable to withdraw emissions") - ErrInvalidAddress = errorsmod.Register(ModuleName, 1003, "Invalid address") - ErrRewardsPoolDoesNotHaveEnoughBalance = errorsmod.Register(ModuleName, 1004, "Rewards pool does not have enough balance") - ErrInvalidAmount = errorsmod.Register(ModuleName, 1005, "Invalid amount") + ErrEmissionsNotFound = errorsmod.Register(ModuleName, 1000, "emissions not found") + ErrUnableToWithdrawEmissions = errorsmod.Register(ModuleName, 1002, "unable to withdraw emissions") + ErrInvalidAddress = errorsmod.Register(ModuleName, 1003, "invalid address") + ErrRewardsPoolDoesNotHaveEnoughBalance = errorsmod.Register(ModuleName, 1004, "rewards pool does not have enough balance") + ErrInvalidAmount = errorsmod.Register(ModuleName, 1005, "invalid amount") ) diff --git a/x/emissions/types/message_withdraw_emissions.go b/x/emissions/types/message_withdraw_emissions.go index 2d6759b792..460960f37b 100644 --- a/x/emissions/types/message_withdraw_emissions.go +++ b/x/emissions/types/message_withdraw_emissions.go @@ -43,8 +43,8 @@ func (msg *MsgWithdrawEmission) ValidateBasic() error { if err != nil { return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) } - if !msg.Amount.GT(sdkmath.ZeroInt()) { - return errorsmod.Wrapf(ErrInvalidAmount, "invalid amount (%s)", msg.Amount.String()) + if msg.Amount.IsNil() || !msg.Amount.IsPositive() { + return errorsmod.Wrapf(ErrInvalidAmount, "withdraw amount : (%s)", msg.Amount.String()) } return nil } diff --git a/x/emissions/types/message_withdraw_emissons_test.go b/x/emissions/types/message_withdraw_emissons_test.go index 280999cc3a..fcc7ae7fc5 100644 --- a/x/emissions/types/message_withdraw_emissons_test.go +++ b/x/emissions/types/message_withdraw_emissons_test.go @@ -29,6 +29,12 @@ func TestMsgWithdrawEmission_ValidateBasic(t *testing.T) { require.ErrorIs(t, err, emissionstypes.ErrInvalidAmount) }) + t.Run("invalid nil amount", func(t *testing.T) { + msg := emissionstypes.NewMsgWithdrawEmissions(sample.AccAddress(), sdkmath.Int{}) + err := msg.ValidateBasic() + require.ErrorIs(t, err, emissionstypes.ErrInvalidAmount) + }) + t.Run("valid withdraw message", func(t *testing.T) { msg := emissionstypes.NewMsgWithdrawEmissions(sample.AccAddress(), sample.IntInRange(1, 100)) err := msg.ValidateBasic()