From 28973eaa3086ba0cbfafcddf5ad78c09efa9386b Mon Sep 17 00:00:00 2001 From: Charlie Chen Date: Thu, 20 Jun 2024 17:06:33 -0500 Subject: [PATCH] define an error for invalid withdrawal amount --- x/crosschain/keeper/evm_hooks.go | 6 +++--- x/crosschain/keeper/evm_hooks_test.go | 2 +- x/crosschain/types/errors.go | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/x/crosschain/keeper/evm_hooks.go b/x/crosschain/keeper/evm_hooks.go index fb6e129cd6..3ead05e604 100644 --- a/x/crosschain/keeper/evm_hooks.go +++ b/x/crosschain/keeper/evm_hooks.go @@ -329,15 +329,15 @@ func ValidateZrc20WithdrawEvent(event *zrc20.ZRC20Withdrawal, chainID int64) err if chains.IsBitcoinChain(chainID) { if event.Value.Cmp(big.NewInt(constant.BTCWithdrawalDustAmount)) < 0 { - return fmt.Errorf("ParseZRC20WithdrawalEvent: withdraw amount %s is less than minimum amount %d", + return errorsmod.Wrapf(types.ErrInvalidWithdrawalAmount, "withdraw amount %s is less than minimum amount %d", event.Value.String(), constant.BTCWithdrawalDustAmount) } addr, err := chains.DecodeBtcAddress(string(event.To), chainID) if err != nil { - return fmt.Errorf("ParseZRC20WithdrawalEvent: invalid address %s: %s", event.To, err) + return errorsmod.Wrapf(types.ErrInvalidAddress, "invalid address %s", string(event.To)) } if !chains.IsBtcAddressSupported(addr) { - return fmt.Errorf("ParseZRC20WithdrawalEvent: unsupported address %s", string(event.To)) + return errorsmod.Wrapf(types.ErrInvalidAddress, "unsupported address %s", string(event.To)) } } return nil diff --git a/x/crosschain/keeper/evm_hooks_test.go b/x/crosschain/keeper/evm_hooks_test.go index 60367745eb..fc0c33bd5d 100644 --- a/x/crosschain/keeper/evm_hooks_test.go +++ b/x/crosschain/keeper/evm_hooks_test.go @@ -165,7 +165,7 @@ func TestValidateZrc20WithdrawEvent(t *testing.T) { require.NoError(t, err) }) - t.Run("unable to validate a event with an invalid amount", func(t *testing.T) { + t.Run("unable to validate a btc withdrawal event with an invalid amount", func(t *testing.T) { btcMainNetWithdrawalEvent, err := crosschainkeeper.ParseZRC20WithdrawalEvent( *sample.GetValidZRC20WithdrawToBTC(t).Logs[3], ) diff --git a/x/crosschain/types/errors.go b/x/crosschain/types/errors.go index 232bf229db..6f430e5e1a 100644 --- a/x/crosschain/types/errors.go +++ b/x/crosschain/types/errors.go @@ -49,4 +49,5 @@ var ( ErrInvalidRateLimiterFlags = errorsmod.Register(ModuleName, 1152, "invalid rate limiter flags") ErrMaxTxOutTrackerHashesReached = errorsmod.Register(ModuleName, 1153, "max tx out tracker hashes reached") ErrInitiatitingOutbound = errorsmod.Register(ModuleName, 1154, "cannot initiate outbound") + ErrInvalidWithdrawalAmount = errorsmod.Register(ModuleName, 1155, "invalid withdrawal amount") )