Skip to content

Commit

Permalink
fixed to error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Mar 4, 2024
1 parent e9f4276 commit f2d4d84
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion x/emissions/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ func GetTxCmd() *cobra.Command {
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
cmd.AddCommand(CmdCreateWithdrawEmission())
cmd.AddCommand(CmdWithdrawEmission())
return cmd
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion x/emissions/keeper/msg_server_withdraw_emissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 5 additions & 7 deletions x/emissions/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
4 changes: 2 additions & 2 deletions x/emissions/types/message_withdraw_emissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions x/emissions/types/message_withdraw_emissons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit f2d4d84

Please sign in to comment.