test(router_validation)_: Added test cases for Sticker and Swaps

This commit is contained in:
Samuel Hawksby-Robinson 2024-06-18 10:59:50 +01:00
parent cdaca322d0
commit da2af02049
2 changed files with 70 additions and 11 deletions

View File

@ -30,12 +30,18 @@ var (
)
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")
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")
ErrorStickersBuyRequires = errors.New("packID is required for StickersBuy")
ErrorSwapRequires = errors.New("toTokenID is required for Swap")
ErrorSwapTokenIDMustBeDifferent = errors.New("tokenID and toTokenID must be different")
ErrorSwapAmountInAmountOutMustBeExclusive = errors.New("only one of amountIn or amountOut can be set")
ErrorSwapAmountInMustBePositive = errors.New("amountIn must be positive")
ErrorSwapAmountOutMustBePositive = errors.New("amountOut must be positive")
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")
)

View File

@ -3,7 +3,6 @@ package router
import (
"context"
"database/sql"
"errors"
"math/big"
"testing"
@ -2718,6 +2717,60 @@ func TestValidateInputData(t *testing.T) {
},
expectedError: ErrorENSSetPubKeyRequires,
},
{
name: "StickersBuy missing packID",
input: &RouteInputParams{
SendType: StickersBuy,
},
expectedError: ErrorStickersBuyRequires,
},
{
name: "Swap missing toTokenID",
input: &RouteInputParams{
SendType: Swap,
},
expectedError: ErrorSwapRequires,
},
{
name: "Swap tokenID equal to toTokenID",
input: &RouteInputParams{
SendType: Swap,
TokenID: "token",
ToTokenID: "token",
},
expectedError: ErrorSwapTokenIDMustBeDifferent,
},
{
name: "Swap both amountIn and amountOut set",
input: &RouteInputParams{
SendType: Swap,
TokenID: "token1",
ToTokenID: "token2",
AmountIn: (*hexutil.Big)(big.NewInt(100)),
AmountOut: (*hexutil.Big)(big.NewInt(100)),
},
expectedError: ErrorSwapAmountInAmountOutMustBeExclusive,
},
{
name: "Swap negative amountIn",
input: &RouteInputParams{
SendType: Swap,
TokenID: "token1",
ToTokenID: "token2",
AmountIn: (*hexutil.Big)(big.NewInt(-100)),
},
expectedError: ErrorSwapAmountInMustBePositive,
},
{
name: "Swap negative amountOut",
input: &RouteInputParams{
SendType: Swap,
TokenID: "token1",
ToTokenID: "token2",
AmountOut: (*hexutil.Big)(big.NewInt(-100)),
},
expectedError: ErrorSwapAmountOutMustBePositive,
},
{
name: "fromLockedAmount with supported network on testnet",
input: &RouteInputParams{
@ -2745,7 +2798,7 @@ func TestValidateInputData(t *testing.T) {
},
testnetMode: true,
},
expectedError: errors.New("locked amount is not supported for the selected network"),
expectedError: ErrorLockedAmountNotSupportedNetwork,
},
{
name: "fromLockedAmount with unsupported network on testnet",
@ -2755,7 +2808,7 @@ func TestValidateInputData(t *testing.T) {
},
testnetMode: true,
},
expectedError: errors.New("locked amount is not supported for the selected network"),
expectedError: ErrorLockedAmountNotSupportedNetwork,
},
{
name: "fromLockedAmount with unsupported network on mainnet",