test(router_validation)_: Added Error consts for all tested paths
This commit is contained in:
parent
79d0d08cfd
commit
cdaca322d0
|
@ -1,28 +1,41 @@
|
||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/status-im/status-go/errors"
|
"errors"
|
||||||
|
|
||||||
|
sErrors "github.com/status-im/status-go/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Abbreviation `WR` for the error code stands for Wallet Router
|
// Abbreviation `WR` for the error code stands for Wallet Router
|
||||||
var (
|
var (
|
||||||
ErrUsernameAndPubKeyRequiredForENSRegister = &errors.ErrorResponse{Code: errors.ErrorCode("WR-001"), Details: "username and public key are required for ENSRegister"}
|
ErrUsernameAndPubKeyRequiredForENSRegister = &sErrors.ErrorResponse{Code: sErrors.ErrorCode("WR-001"), Details: "username and public key are required for ENSRegister"}
|
||||||
ErrOnlySTTSupportedForENSRegisterOnTestnet = &errors.ErrorResponse{Code: errors.ErrorCode("WR-002"), Details: "only STT is supported for ENSRegister on testnet"}
|
ErrOnlySTTSupportedForENSRegisterOnTestnet = &sErrors.ErrorResponse{Code: sErrors.ErrorCode("WR-002"), Details: "only STT is supported for ENSRegister on testnet"}
|
||||||
ErrOnlySTTSupportedForENSReleaseOnTestnet = &errors.ErrorResponse{Code: errors.ErrorCode("WR-003"), Details: "only STT is supported for ENSRelease on testnet"}
|
ErrOnlySTTSupportedForENSReleaseOnTestnet = &sErrors.ErrorResponse{Code: sErrors.ErrorCode("WR-003"), Details: "only STT is supported for ENSRelease on testnet"}
|
||||||
ErrUsernameRequiredForENSRelease = &errors.ErrorResponse{Code: errors.ErrorCode("WR-004"), Details: "username is required for ENSRelease"}
|
ErrUsernameRequiredForENSRelease = &sErrors.ErrorResponse{Code: sErrors.ErrorCode("WR-004"), Details: "username is required for ENSRelease"}
|
||||||
ErrUsernameAndPubKeyRequiredForENSSetPubKey = &errors.ErrorResponse{Code: errors.ErrorCode("WR-005"), Details: "username and public key are required for ENSSetPubKey"}
|
ErrUsernameAndPubKeyRequiredForENSSetPubKey = &sErrors.ErrorResponse{Code: sErrors.ErrorCode("WR-005"), Details: "username and public key are required for ENSSetPubKey"}
|
||||||
ErrPackIDRequiredForStickersBuy = &errors.ErrorResponse{Code: errors.ErrorCode("WR-006"), Details: "packID is required for StickersBuy"}
|
ErrPackIDRequiredForStickersBuy = &sErrors.ErrorResponse{Code: sErrors.ErrorCode("WR-006"), Details: "packID is required for StickersBuy"}
|
||||||
ErrToTokenIDRequiredForSwap = &errors.ErrorResponse{Code: errors.ErrorCode("WR-007"), Details: "toTokenID is required for Swap"}
|
ErrToTokenIDRequiredForSwap = &sErrors.ErrorResponse{Code: sErrors.ErrorCode("WR-007"), Details: "toTokenID is required for Swap"}
|
||||||
ErrTokenIDAndToTokenIDDifferent = &errors.ErrorResponse{Code: errors.ErrorCode("WR-008"), Details: "tokenID and toTokenID must be different"}
|
ErrTokenIDAndToTokenIDDifferent = &sErrors.ErrorResponse{Code: sErrors.ErrorCode("WR-008"), Details: "tokenID and toTokenID must be different"}
|
||||||
ErrOnlyOneOfAmountInOrOutSet = &errors.ErrorResponse{Code: errors.ErrorCode("WR-009"), Details: "only one of amountIn or amountOut can be set"}
|
ErrOnlyOneOfAmountInOrOutSet = &sErrors.ErrorResponse{Code: sErrors.ErrorCode("WR-009"), Details: "only one of amountIn or amountOut can be set"}
|
||||||
ErrAmountInMustBePositive = &errors.ErrorResponse{Code: errors.ErrorCode("WR-010"), Details: "amountIn must be positive"}
|
ErrAmountInMustBePositive = &sErrors.ErrorResponse{Code: sErrors.ErrorCode("WR-010"), Details: "amountIn must be positive"}
|
||||||
ErrAmountOutMustBePositive = &errors.ErrorResponse{Code: errors.ErrorCode("WR-011"), Details: "amountOut must be positive"}
|
ErrAmountOutMustBePositive = &sErrors.ErrorResponse{Code: sErrors.ErrorCode("WR-011"), Details: "amountOut must be positive"}
|
||||||
ErrLockedAmountNotSupportedForNetwork = &errors.ErrorResponse{Code: errors.ErrorCode("WR-012"), Details: "locked amount is not supported for the selected network"}
|
ErrLockedAmountNotSupportedForNetwork = &sErrors.ErrorResponse{Code: sErrors.ErrorCode("WR-012"), Details: "locked amount is not supported for the selected network"}
|
||||||
ErrLockedAmountMustBePositive = &errors.ErrorResponse{Code: errors.ErrorCode("WR-013"), Details: "locked amount must be positive"}
|
ErrLockedAmountMustBePositive = &sErrors.ErrorResponse{Code: sErrors.ErrorCode("WR-013"), Details: "locked amount must be positive"}
|
||||||
ErrLockedAmountExceedsTotalSendAmount = &errors.ErrorResponse{Code: errors.ErrorCode("WR-014"), Details: "locked amount exceeds the total amount to send"}
|
ErrLockedAmountExceedsTotalSendAmount = &sErrors.ErrorResponse{Code: sErrors.ErrorCode("WR-014"), Details: "locked amount exceeds the total amount to send"}
|
||||||
ErrLockedAmountLessThanSendAmountAllNetworks = &errors.ErrorResponse{Code: errors.ErrorCode("WR-015"), Details: "locked amount is less than the total amount to send, but all networks are locked"}
|
ErrLockedAmountLessThanSendAmountAllNetworks = &sErrors.ErrorResponse{Code: sErrors.ErrorCode("WR-015"), Details: "locked amount is less than the total amount to send, but all networks are locked"}
|
||||||
ErrNotEnoughTokenBalance = &errors.ErrorResponse{Code: errors.ErrorCode("WR-016"), Details: "not enough token balance"}
|
ErrNotEnoughTokenBalance = &sErrors.ErrorResponse{Code: sErrors.ErrorCode("WR-016"), Details: "not enough token balance"}
|
||||||
ErrNotEnoughNativeBalance = &errors.ErrorResponse{Code: errors.ErrorCode("WR-017"), Details: "not enough native balance"}
|
ErrNotEnoughNativeBalance = &sErrors.ErrorResponse{Code: sErrors.ErrorCode("WR-017"), Details: "not enough native balance"}
|
||||||
ErrNativeTokenNotFound = &errors.ErrorResponse{Code: errors.ErrorCode("WR-018"), Details: "native token not found"}
|
ErrNativeTokenNotFound = &sErrors.ErrorResponse{Code: sErrors.ErrorCode("WR-018"), Details: "native token not found"}
|
||||||
ErrDisabledChainFoundAmongLockedNetworks = &errors.ErrorResponse{Code: errors.ErrorCode("WR-019"), Details: "disabled chain found among locked networks"}
|
ErrDisabledChainFoundAmongLockedNetworks = &sErrors.ErrorResponse{Code: sErrors.ErrorCode("WR-019"), Details: "disabled chain found among locked networks"}
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrorENSRegisterRequires = errors.New("username and public key are required for ENSRegister")
|
||||||
|
ErrorENSRegisterTestNetSTTOnly = errors.New("only STT is supported for ENSRegister on testnet")
|
||||||
|
ErrorENSRegisterSNTOnly = errors.New("only SNT is supported for ENSRegister")
|
||||||
|
ErrorENSReleaseRequires = errors.New("username is required for ENSRelease")
|
||||||
|
ErrorENSSetPubKeyRequires = errors.New("username and public key are required for ENSSetPubKey")
|
||||||
|
ErrorLockedAmountNotSupportedNetwork = errors.New("locked amount is not supported for the selected network")
|
||||||
|
ErrorLockedAmountNotNegative = errors.New("locked amount must not be negative")
|
||||||
|
ErrorLockedAmountExcludesAllSupported = errors.New("all supported chains are excluded, routing impossible")
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,7 +2,6 @@ package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
@ -444,17 +443,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 errors.New("locked amount is not supported for the selected network")
|
return ErrorLockedAmountNotSupportedNetwork
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if !supportedNetworks[chainID] {
|
if !supportedNetworks[chainID] {
|
||||||
return errors.New("locked amount is not supported for the selected network")
|
return ErrorLockedAmountNotSupportedNetwork
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 errors.New("locked amount must not be negative")
|
return ErrorLockedAmountNotNegative
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if locked chain ID is a duplicate
|
// Check if locked chain ID is a duplicate
|
||||||
|
@ -469,7 +468,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 errors.New("all supported chains are excluded, routing impossible")
|
return ErrorLockedAmountExcludesAllSupported
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -2636,7 +2636,7 @@ func TestValidateInputData(t *testing.T) {
|
||||||
TokenID: pathprocessor.SttSymbol,
|
TokenID: pathprocessor.SttSymbol,
|
||||||
testnetMode: true,
|
testnetMode: true,
|
||||||
},
|
},
|
||||||
expectedError: errors.New("username and public key are required for ENSRegister"),
|
expectedError: ErrorENSRegisterRequires,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ENSRegister missing public key",
|
name: "ENSRegister missing public key",
|
||||||
|
@ -2646,7 +2646,7 @@ func TestValidateInputData(t *testing.T) {
|
||||||
TokenID: pathprocessor.SttSymbol,
|
TokenID: pathprocessor.SttSymbol,
|
||||||
testnetMode: true,
|
testnetMode: true,
|
||||||
},
|
},
|
||||||
expectedError: errors.New("username and public key are required for ENSRegister"),
|
expectedError: ErrorENSRegisterRequires,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ENSRegister invalid token on testnet",
|
name: "ENSRegister invalid token on testnet",
|
||||||
|
@ -2657,7 +2657,7 @@ func TestValidateInputData(t *testing.T) {
|
||||||
TokenID: "invalidtoken",
|
TokenID: "invalidtoken",
|
||||||
testnetMode: true,
|
testnetMode: true,
|
||||||
},
|
},
|
||||||
expectedError: errors.New("only STT is supported for ENSRegister on testnet"),
|
expectedError: ErrorENSRegisterTestNetSTTOnly,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ENSRegister invalid token on mainnet",
|
name: "ENSRegister invalid token on mainnet",
|
||||||
|
@ -2667,7 +2667,7 @@ func TestValidateInputData(t *testing.T) {
|
||||||
PublicKey: "validpublickey",
|
PublicKey: "validpublickey",
|
||||||
TokenID: "invalidtoken",
|
TokenID: "invalidtoken",
|
||||||
},
|
},
|
||||||
expectedError: errors.New("only SNT is supported for ENSRegister"),
|
expectedError: ErrorENSRegisterSNTOnly,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ENSRelease valid data",
|
name: "ENSRelease valid data",
|
||||||
|
@ -2682,7 +2682,7 @@ func TestValidateInputData(t *testing.T) {
|
||||||
input: &RouteInputParams{
|
input: &RouteInputParams{
|
||||||
SendType: ENSRelease,
|
SendType: ENSRelease,
|
||||||
},
|
},
|
||||||
expectedError: errors.New("username is required for ENSRelease"),
|
expectedError: ErrorENSReleaseRequires,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ENSSetPubKey valid data",
|
name: "ENSSetPubKey valid data",
|
||||||
|
@ -2699,7 +2699,7 @@ func TestValidateInputData(t *testing.T) {
|
||||||
SendType: ENSSetPubKey,
|
SendType: ENSSetPubKey,
|
||||||
PublicKey: "validpublickey",
|
PublicKey: "validpublickey",
|
||||||
},
|
},
|
||||||
expectedError: errors.New("username and public key are required for ENSSetPubKey"),
|
expectedError: ErrorENSSetPubKeyRequires,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ENSSetPubKey missing public key",
|
name: "ENSSetPubKey missing public key",
|
||||||
|
@ -2707,7 +2707,7 @@ func TestValidateInputData(t *testing.T) {
|
||||||
SendType: ENSSetPubKey,
|
SendType: ENSSetPubKey,
|
||||||
Username: "validusername",
|
Username: "validusername",
|
||||||
},
|
},
|
||||||
expectedError: errors.New("username and public key are required for ENSSetPubKey"),
|
expectedError: ErrorENSSetPubKeyRequires,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ENSSetPubKey invalid ENS username",
|
name: "ENSSetPubKey invalid ENS username",
|
||||||
|
@ -2716,7 +2716,7 @@ func TestValidateInputData(t *testing.T) {
|
||||||
Username: "invalidusername",
|
Username: "invalidusername",
|
||||||
PublicKey: "validpublickey",
|
PublicKey: "validpublickey",
|
||||||
},
|
},
|
||||||
expectedError: errors.New("username and public key are required for ENSSetPubKey"),
|
expectedError: ErrorENSSetPubKeyRequires,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "fromLockedAmount with supported network on testnet",
|
name: "fromLockedAmount with supported network on testnet",
|
||||||
|
@ -2764,7 +2764,7 @@ func TestValidateInputData(t *testing.T) {
|
||||||
999: (*hexutil.Big)(big.NewInt(10)),
|
999: (*hexutil.Big)(big.NewInt(10)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedError: errors.New("locked amount is not supported for the selected network"),
|
expectedError: ErrorLockedAmountNotSupportedNetwork,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "fromLockedAmount with negative amount",
|
name: "fromLockedAmount with negative amount",
|
||||||
|
@ -2773,7 +2773,7 @@ func TestValidateInputData(t *testing.T) {
|
||||||
walletCommon.EthereumMainnet: (*hexutil.Big)(big.NewInt(-10)),
|
walletCommon.EthereumMainnet: (*hexutil.Big)(big.NewInt(-10)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedError: errors.New("locked amount must not be negative"),
|
expectedError: ErrorLockedAmountNotNegative,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "fromLockedAmount with zero amount",
|
name: "fromLockedAmount with zero amount",
|
||||||
|
@ -2803,7 +2803,7 @@ func TestValidateInputData(t *testing.T) {
|
||||||
walletCommon.ArbitrumMainnet: (*hexutil.Big)(big.NewInt(0)),
|
walletCommon.ArbitrumMainnet: (*hexutil.Big)(big.NewInt(0)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedError: errors.New("all supported chains are excluded, routing impossible"),
|
expectedError: ErrorLockedAmountExcludesAllSupported,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "fromLockedAmount with all supported test networks with zero amount",
|
name: "fromLockedAmount with all supported test networks with zero amount",
|
||||||
|
@ -2815,7 +2815,7 @@ func TestValidateInputData(t *testing.T) {
|
||||||
},
|
},
|
||||||
testnetMode: true,
|
testnetMode: true,
|
||||||
},
|
},
|
||||||
expectedError: errors.New("all supported chains are excluded, routing impossible"),
|
expectedError: ErrorLockedAmountExcludesAllSupported,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue