test(router_validation)_: removed error consts, see #5362

This commit is contained in:
Samuel Hawksby-Robinson 2024-06-20 17:21:30 +01:00
parent da2af02049
commit e4420533d6
2 changed files with 26 additions and 24 deletions

View File

@ -2,6 +2,7 @@ package router
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"math" "math"
"math/big" "math/big"
@ -443,17 +444,17 @@ func validateFromLockedAmount(fromLockedAmount map[uint64]*hexutil.Big, isTestne
for chainID, amount := range fromLockedAmount { for chainID, amount := range fromLockedAmount {
if isTestnetMode { if isTestnetMode {
if !supportedTestNetworks[chainID] { if !supportedTestNetworks[chainID] {
return ErrorLockedAmountNotSupportedNetwork return errors.New("locked amount is not supported for the selected network")
} }
} else { } else {
if !supportedNetworks[chainID] { if !supportedNetworks[chainID] {
return ErrorLockedAmountNotSupportedNetwork return errors.New("locked amount is not supported for the selected network")
} }
} }
// Check locked amount is not negative // Check locked amount is not negative
if amount == nil || amount.ToInt().Sign() < 0 { 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 // 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)) || if (!isTestnetMode && excludedChainCount == len(supportedNetworks)) ||
(isTestnetMode && excludedChainCount == len(supportedTestNetworks)) { (isTestnetMode && excludedChainCount == len(supportedTestNetworks)) {
return ErrorLockedAmountExcludesAllSupported return errors.New("all supported chains are excluded, routing impossible")
} }
return nil return nil
} }

View File

@ -3,6 +3,7 @@ package router
import ( import (
"context" "context"
"database/sql" "database/sql"
"errors"
"math/big" "math/big"
"testing" "testing"
@ -2635,7 +2636,7 @@ func TestValidateInputData(t *testing.T) {
TokenID: pathprocessor.SttSymbol, TokenID: pathprocessor.SttSymbol,
testnetMode: true, testnetMode: true,
}, },
expectedError: ErrorENSRegisterRequires, expectedError: errors.New("username and public key are required for ENSRegister"),
}, },
{ {
name: "ENSRegister missing public key", name: "ENSRegister missing public key",
@ -2645,7 +2646,7 @@ func TestValidateInputData(t *testing.T) {
TokenID: pathprocessor.SttSymbol, TokenID: pathprocessor.SttSymbol,
testnetMode: true, testnetMode: true,
}, },
expectedError: ErrorENSRegisterRequires, expectedError: errors.New("username and public key are required for ENSRegister"),
}, },
{ {
name: "ENSRegister invalid token on testnet", name: "ENSRegister invalid token on testnet",
@ -2656,7 +2657,7 @@ func TestValidateInputData(t *testing.T) {
TokenID: "invalidtoken", TokenID: "invalidtoken",
testnetMode: true, testnetMode: true,
}, },
expectedError: ErrorENSRegisterTestNetSTTOnly, expectedError: errors.New("only STT is supported for ENSRegister on testnet"),
}, },
{ {
name: "ENSRegister invalid token on mainnet", name: "ENSRegister invalid token on mainnet",
@ -2666,7 +2667,7 @@ func TestValidateInputData(t *testing.T) {
PublicKey: "validpublickey", PublicKey: "validpublickey",
TokenID: "invalidtoken", TokenID: "invalidtoken",
}, },
expectedError: ErrorENSRegisterSNTOnly, expectedError: errors.New("only SNT is supported for ENSRegister"),
}, },
{ {
name: "ENSRelease valid data", name: "ENSRelease valid data",
@ -2681,7 +2682,7 @@ func TestValidateInputData(t *testing.T) {
input: &RouteInputParams{ input: &RouteInputParams{
SendType: ENSRelease, SendType: ENSRelease,
}, },
expectedError: ErrorENSReleaseRequires, expectedError: errors.New("username is required for ENSRelease"),
}, },
{ {
name: "ENSSetPubKey valid data", name: "ENSSetPubKey valid data",
@ -2698,7 +2699,7 @@ func TestValidateInputData(t *testing.T) {
SendType: ENSSetPubKey, SendType: ENSSetPubKey,
PublicKey: "validpublickey", PublicKey: "validpublickey",
}, },
expectedError: ErrorENSSetPubKeyRequires, expectedError: errors.New("username and public key are required for ENSSetPubKey"),
}, },
{ {
name: "ENSSetPubKey missing public key", name: "ENSSetPubKey missing public key",
@ -2706,7 +2707,7 @@ func TestValidateInputData(t *testing.T) {
SendType: ENSSetPubKey, SendType: ENSSetPubKey,
Username: "validusername", Username: "validusername",
}, },
expectedError: ErrorENSSetPubKeyRequires, expectedError: errors.New("username and public key are required for ENSSetPubKey"),
}, },
{ {
name: "ENSSetPubKey invalid ENS username", name: "ENSSetPubKey invalid ENS username",
@ -2715,21 +2716,21 @@ func TestValidateInputData(t *testing.T) {
Username: "invalidusername", Username: "invalidusername",
PublicKey: "validpublickey", PublicKey: "validpublickey",
}, },
expectedError: ErrorENSSetPubKeyRequires, expectedError: errors.New("username and public key are required for ENSSetPubKey"),
}, },
{ {
name: "StickersBuy missing packID", name: "StickersBuy missing packID",
input: &RouteInputParams{ input: &RouteInputParams{
SendType: StickersBuy, SendType: StickersBuy,
}, },
expectedError: ErrorStickersBuyRequires, expectedError: errors.New("packID is required for StickersBuy"),
}, },
{ {
name: "Swap missing toTokenID", name: "Swap missing toTokenID",
input: &RouteInputParams{ input: &RouteInputParams{
SendType: Swap, SendType: Swap,
}, },
expectedError: ErrorSwapRequires, expectedError: errors.New("toTokenID is required for Swap"),
}, },
{ {
name: "Swap tokenID equal to toTokenID", name: "Swap tokenID equal to toTokenID",
@ -2738,7 +2739,7 @@ func TestValidateInputData(t *testing.T) {
TokenID: "token", TokenID: "token",
ToTokenID: "token", ToTokenID: "token",
}, },
expectedError: ErrorSwapTokenIDMustBeDifferent, expectedError: errors.New("tokenID and toTokenID must be different"),
}, },
{ {
name: "Swap both amountIn and amountOut set", name: "Swap both amountIn and amountOut set",
@ -2749,7 +2750,7 @@ func TestValidateInputData(t *testing.T) {
AmountIn: (*hexutil.Big)(big.NewInt(100)), AmountIn: (*hexutil.Big)(big.NewInt(100)),
AmountOut: (*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", name: "Swap negative amountIn",
@ -2759,7 +2760,7 @@ func TestValidateInputData(t *testing.T) {
ToTokenID: "token2", ToTokenID: "token2",
AmountIn: (*hexutil.Big)(big.NewInt(-100)), AmountIn: (*hexutil.Big)(big.NewInt(-100)),
}, },
expectedError: ErrorSwapAmountInMustBePositive, expectedError: errors.New("amountIn must be positive"),
}, },
{ {
name: "Swap negative amountOut", name: "Swap negative amountOut",
@ -2769,7 +2770,7 @@ func TestValidateInputData(t *testing.T) {
ToTokenID: "token2", ToTokenID: "token2",
AmountOut: (*hexutil.Big)(big.NewInt(-100)), AmountOut: (*hexutil.Big)(big.NewInt(-100)),
}, },
expectedError: ErrorSwapAmountOutMustBePositive, expectedError: errors.New("amountOut must be positive"),
}, },
{ {
name: "fromLockedAmount with supported network on testnet", name: "fromLockedAmount with supported network on testnet",
@ -2798,7 +2799,7 @@ func TestValidateInputData(t *testing.T) {
}, },
testnetMode: true, testnetMode: true,
}, },
expectedError: ErrorLockedAmountNotSupportedNetwork, expectedError: errors.New("locked amount is not supported for the selected network"),
}, },
{ {
name: "fromLockedAmount with unsupported network on testnet", name: "fromLockedAmount with unsupported network on testnet",
@ -2808,7 +2809,7 @@ func TestValidateInputData(t *testing.T) {
}, },
testnetMode: true, testnetMode: true,
}, },
expectedError: ErrorLockedAmountNotSupportedNetwork, expectedError: errors.New("locked amount is not supported for the selected network"),
}, },
{ {
name: "fromLockedAmount with unsupported network on mainnet", name: "fromLockedAmount with unsupported network on mainnet",
@ -2817,7 +2818,7 @@ func TestValidateInputData(t *testing.T) {
999: (*hexutil.Big)(big.NewInt(10)), 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", name: "fromLockedAmount with negative amount",
@ -2826,7 +2827,7 @@ func TestValidateInputData(t *testing.T) {
walletCommon.EthereumMainnet: (*hexutil.Big)(big.NewInt(-10)), walletCommon.EthereumMainnet: (*hexutil.Big)(big.NewInt(-10)),
}, },
}, },
expectedError: ErrorLockedAmountNotNegative, expectedError: errors.New("locked amount must not be negative"),
}, },
{ {
name: "fromLockedAmount with zero amount", name: "fromLockedAmount with zero amount",
@ -2856,7 +2857,7 @@ func TestValidateInputData(t *testing.T) {
walletCommon.ArbitrumMainnet: (*hexutil.Big)(big.NewInt(0)), 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", name: "fromLockedAmount with all supported test networks with zero amount",
@ -2868,7 +2869,7 @@ func TestValidateInputData(t *testing.T) {
}, },
testnetMode: true, testnetMode: true,
}, },
expectedError: ErrorLockedAmountExcludesAllSupported, expectedError: errors.New("all supported chains are excluded, routing impossible"),
}, },
} }