diff --git a/services/wallet/router/router_v2.go b/services/wallet/router/router_v2.go index 934c8063b..690af2df1 100644 --- a/services/wallet/router/router_v2.go +++ b/services/wallet/router/router_v2.go @@ -2,6 +2,7 @@ package router import ( "context" + "errors" "fmt" "math" "math/big" @@ -443,17 +444,17 @@ func validateFromLockedAmount(fromLockedAmount map[uint64]*hexutil.Big, isTestne for chainID, amount := range fromLockedAmount { if isTestnetMode { if !supportedTestNetworks[chainID] { - return ErrorLockedAmountNotSupportedNetwork + return errors.New("locked amount is not supported for the selected network") } } else { if !supportedNetworks[chainID] { - return ErrorLockedAmountNotSupportedNetwork + return errors.New("locked amount is not supported for the selected network") } } // Check locked amount is not negative if amount == nil || amount.ToInt().Sign() < 0 { - return ErrorLockedAmountNotNegative + return errors.New("locked amount must not be negative") } // Check if locked chain ID is a duplicate @@ -468,7 +469,7 @@ func validateFromLockedAmount(fromLockedAmount map[uint64]*hexutil.Big, isTestne } if (!isTestnetMode && excludedChainCount == len(supportedNetworks)) || (isTestnetMode && excludedChainCount == len(supportedTestNetworks)) { - return ErrorLockedAmountExcludesAllSupported + return errors.New("all supported chains are excluded, routing impossible") } return nil } diff --git a/services/wallet/router/router_v2_test.go b/services/wallet/router/router_v2_test.go index fb4f8266b..40b26cb82 100644 --- a/services/wallet/router/router_v2_test.go +++ b/services/wallet/router/router_v2_test.go @@ -3,6 +3,7 @@ package router import ( "context" "database/sql" + "errors" "math/big" "testing" @@ -2635,7 +2636,7 @@ func TestValidateInputData(t *testing.T) { TokenID: pathprocessor.SttSymbol, testnetMode: true, }, - expectedError: ErrorENSRegisterRequires, + expectedError: errors.New("username and public key are required for ENSRegister"), }, { name: "ENSRegister missing public key", @@ -2645,7 +2646,7 @@ func TestValidateInputData(t *testing.T) { TokenID: pathprocessor.SttSymbol, testnetMode: true, }, - expectedError: ErrorENSRegisterRequires, + expectedError: errors.New("username and public key are required for ENSRegister"), }, { name: "ENSRegister invalid token on testnet", @@ -2656,7 +2657,7 @@ func TestValidateInputData(t *testing.T) { TokenID: "invalidtoken", testnetMode: true, }, - expectedError: ErrorENSRegisterTestNetSTTOnly, + expectedError: errors.New("only STT is supported for ENSRegister on testnet"), }, { name: "ENSRegister invalid token on mainnet", @@ -2666,7 +2667,7 @@ func TestValidateInputData(t *testing.T) { PublicKey: "validpublickey", TokenID: "invalidtoken", }, - expectedError: ErrorENSRegisterSNTOnly, + expectedError: errors.New("only SNT is supported for ENSRegister"), }, { name: "ENSRelease valid data", @@ -2681,7 +2682,7 @@ func TestValidateInputData(t *testing.T) { input: &RouteInputParams{ SendType: ENSRelease, }, - expectedError: ErrorENSReleaseRequires, + expectedError: errors.New("username is required for ENSRelease"), }, { name: "ENSSetPubKey valid data", @@ -2698,7 +2699,7 @@ func TestValidateInputData(t *testing.T) { SendType: ENSSetPubKey, PublicKey: "validpublickey", }, - expectedError: ErrorENSSetPubKeyRequires, + expectedError: errors.New("username and public key are required for ENSSetPubKey"), }, { name: "ENSSetPubKey missing public key", @@ -2706,7 +2707,7 @@ func TestValidateInputData(t *testing.T) { SendType: ENSSetPubKey, Username: "validusername", }, - expectedError: ErrorENSSetPubKeyRequires, + expectedError: errors.New("username and public key are required for ENSSetPubKey"), }, { name: "ENSSetPubKey invalid ENS username", @@ -2715,21 +2716,21 @@ func TestValidateInputData(t *testing.T) { Username: "invalidusername", PublicKey: "validpublickey", }, - expectedError: ErrorENSSetPubKeyRequires, + expectedError: errors.New("username and public key are required for ENSSetPubKey"), }, { name: "StickersBuy missing packID", input: &RouteInputParams{ SendType: StickersBuy, }, - expectedError: ErrorStickersBuyRequires, + expectedError: errors.New("packID is required for StickersBuy"), }, { name: "Swap missing toTokenID", input: &RouteInputParams{ SendType: Swap, }, - expectedError: ErrorSwapRequires, + expectedError: errors.New("toTokenID is required for Swap"), }, { name: "Swap tokenID equal to toTokenID", @@ -2738,7 +2739,7 @@ func TestValidateInputData(t *testing.T) { TokenID: "token", ToTokenID: "token", }, - expectedError: ErrorSwapTokenIDMustBeDifferent, + expectedError: errors.New("tokenID and toTokenID must be different"), }, { name: "Swap both amountIn and amountOut set", @@ -2749,7 +2750,7 @@ func TestValidateInputData(t *testing.T) { AmountIn: (*hexutil.Big)(big.NewInt(100)), AmountOut: (*hexutil.Big)(big.NewInt(100)), }, - expectedError: ErrorSwapAmountInAmountOutMustBeExclusive, + expectedError: errors.New("only one of amountIn or amountOut can be set"), }, { name: "Swap negative amountIn", @@ -2759,7 +2760,7 @@ func TestValidateInputData(t *testing.T) { ToTokenID: "token2", AmountIn: (*hexutil.Big)(big.NewInt(-100)), }, - expectedError: ErrorSwapAmountInMustBePositive, + expectedError: errors.New("amountIn must be positive"), }, { name: "Swap negative amountOut", @@ -2769,7 +2770,7 @@ func TestValidateInputData(t *testing.T) { ToTokenID: "token2", AmountOut: (*hexutil.Big)(big.NewInt(-100)), }, - expectedError: ErrorSwapAmountOutMustBePositive, + expectedError: errors.New("amountOut must be positive"), }, { name: "fromLockedAmount with supported network on testnet", @@ -2798,7 +2799,7 @@ func TestValidateInputData(t *testing.T) { }, testnetMode: true, }, - expectedError: ErrorLockedAmountNotSupportedNetwork, + expectedError: errors.New("locked amount is not supported for the selected network"), }, { name: "fromLockedAmount with unsupported network on testnet", @@ -2808,7 +2809,7 @@ func TestValidateInputData(t *testing.T) { }, testnetMode: true, }, - expectedError: ErrorLockedAmountNotSupportedNetwork, + expectedError: errors.New("locked amount is not supported for the selected network"), }, { name: "fromLockedAmount with unsupported network on mainnet", @@ -2817,7 +2818,7 @@ func TestValidateInputData(t *testing.T) { 999: (*hexutil.Big)(big.NewInt(10)), }, }, - expectedError: ErrorLockedAmountNotSupportedNetwork, + expectedError: errors.New("locked amount is not supported for the selected network"), }, { name: "fromLockedAmount with negative amount", @@ -2826,7 +2827,7 @@ func TestValidateInputData(t *testing.T) { walletCommon.EthereumMainnet: (*hexutil.Big)(big.NewInt(-10)), }, }, - expectedError: ErrorLockedAmountNotNegative, + expectedError: errors.New("locked amount must not be negative"), }, { name: "fromLockedAmount with zero amount", @@ -2856,7 +2857,7 @@ func TestValidateInputData(t *testing.T) { walletCommon.ArbitrumMainnet: (*hexutil.Big)(big.NewInt(0)), }, }, - expectedError: ErrorLockedAmountExcludesAllSupported, + expectedError: errors.New("all supported chains are excluded, routing impossible"), }, { name: "fromLockedAmount with all supported test networks with zero amount", @@ -2868,7 +2869,7 @@ func TestValidateInputData(t *testing.T) { }, testnetMode: true, }, - expectedError: ErrorLockedAmountExcludesAllSupported, + expectedError: errors.New("all supported chains are excluded, routing impossible"), }, }