Skip to content

Commit

Permalink
reject zero amount withdraws
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Mar 1, 2024
1 parent 2d7ab90 commit 40aa9a5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 1 addition & 2 deletions x/emissions/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ var (
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")
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.GTE(sdkmath.ZeroInt()) {
return errorsmod.Wrapf(sdkerrors.ErrInvalidCoins, "invalid amount (%s)", msg.Amount.String())
if !msg.Amount.GT(sdkmath.ZeroInt()) {
return errorsmod.Wrapf(ErrInvalidAmount, "invalid amount (%s)", msg.Amount.String())
}
return nil
}
11 changes: 9 additions & 2 deletions x/emissions/types/message_withdraw_emissons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types_test
import (
"testing"

sdkmath "cosmossdk.io/math"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/stretchr/testify/require"
"github.com/zeta-chain/zetacore/testutil/sample"
Expand All @@ -16,10 +17,16 @@ func TestMsgWithdrawEmission_ValidateBasic(t *testing.T) {
require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress)
})

t.Run("invalid amount", func(t *testing.T) {
t.Run("invalid negative amount", func(t *testing.T) {
msg := emissionstypes.NewMsgWithdrawEmissions(sample.AccAddress(), sample.IntInRange(-100, -1))
err := msg.ValidateBasic()
require.ErrorIs(t, err, sdkerrors.ErrInvalidCoins)
require.ErrorIs(t, err, emissionstypes.ErrInvalidAmount)
})

t.Run("invalid zero amount", func(t *testing.T) {
msg := emissionstypes.NewMsgWithdrawEmissions(sample.AccAddress(), sdkmath.ZeroInt())
err := msg.ValidateBasic()
require.ErrorIs(t, err, emissionstypes.ErrInvalidAmount)
})

t.Run("valid withdraw message", func(t *testing.T) {
Expand Down

0 comments on commit 40aa9a5

Please sign in to comment.