From e4def6a7a292feeefe20dbd563f3496e190a70e3 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Thu, 9 May 2024 00:09:51 +0900 Subject: [PATCH] chore: add denom validation for string type denom --- x/fswap/types/fswap.go | 13 +++++++++---- x/fswap/types/msgs.go | 12 ++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/x/fswap/types/fswap.go b/x/fswap/types/fswap.go index c307c826b3..f45d2b2d89 100644 --- a/x/fswap/types/fswap.go +++ b/x/fswap/types/fswap.go @@ -9,21 +9,26 @@ import ( // ValidateBasic validates the set of Swap func (s *Swap) ValidateBasic() error { - if s.FromDenom == "" { - return sdkerrors.ErrInvalidRequest.Wrap("from denomination cannot be empty") + if err := sdk.ValidateDenom(s.FromDenom); err != nil { + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } - if s.ToDenom == "" { - return sdkerrors.ErrInvalidRequest.Wrap("to denomination cannot be empty") + + if err := sdk.ValidateDenom(s.ToDenom); err != nil { + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } + if s.FromDenom == s.ToDenom { return sdkerrors.ErrInvalidRequest.Wrap("from denomination cannot be equal to to denomination") } + if s.AmountCapForToDenom.LT(sdk.OneInt()) { return sdkerrors.ErrInvalidRequest.Wrap("amount cannot be less than one") } + if s.SwapRate.IsZero() { return sdkerrors.ErrInvalidRequest.Wrap("swap rate cannot be zero") } + return nil } diff --git a/x/fswap/types/msgs.go b/x/fswap/types/msgs.go index eae8c6a2c2..f94e123cae 100644 --- a/x/fswap/types/msgs.go +++ b/x/fswap/types/msgs.go @@ -23,8 +23,8 @@ func (m *MsgSwap) ValidateBasic() error { return sdkerrors.ErrInvalidCoins.Wrap(m.FromCoinAmount.String()) } - if len(m.GetToDenom()) == 0 { - return sdkerrors.ErrInvalidRequest.Wrap("invalid denom (empty denom)") + if err := sdk.ValidateDenom(m.GetToDenom()); err != nil { + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } return nil @@ -53,12 +53,12 @@ func (m *MsgSwapAll) ValidateBasic() error { return sdkerrors.ErrInvalidAddress.Wrapf("Invalid address (%s)", err) } - if len(m.GetFromDenom()) == 0 { - return sdkerrors.ErrInvalidRequest.Wrap("invalid denom (empty denom)") + if err := sdk.ValidateDenom(m.FromDenom); err != nil { + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } - if len(m.GetToDenom()) == 0 { - return sdkerrors.ErrInvalidRequest.Wrap("invalid denom (empty denom)") + if err := sdk.ValidateDenom(m.ToDenom); err != nil { + return sdkerrors.ErrInvalidRequest.Wrap(err.Error()) } return nil