chore!: removed v2 mark from api endpoints, structs and files marked as router v2
Breaking change! Since the old router logic is removed, there is no need to have files and structs marked as v2. Renamed endpoints: - `GetSuggestedRoutesV2` to `GetSuggestedRoutes` - `GetSuggestedRoutesV2Async` to `GetSuggestedRoutesAsync` - `StopSuggestedRoutesV2AsyncCalcualtion` to `StopSuggestedRoutesAsyncCalcualtion`
This commit is contained in:
parent
e58787536a
commit
d10d492515
|
@ -488,22 +488,22 @@ func gweiToWei(val *big.Float) *big.Int {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) GetSuggestedRoutesV2(ctx context.Context, input *router.RouteInputParams) (*router.SuggestedRoutesV2, error) {
|
func (api *API) GetSuggestedRoutes(ctx context.Context, input *router.RouteInputParams) (*router.SuggestedRoutes, error) {
|
||||||
log.Debug("call to GetSuggestedRoutesV2")
|
log.Debug("call to GetSuggestedRoutes")
|
||||||
|
|
||||||
return api.router.SuggestedRoutesV2(ctx, input)
|
return api.router.SuggestedRoutes(ctx, input)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) GetSuggestedRoutesV2Async(ctx context.Context, input *router.RouteInputParams) {
|
func (api *API) GetSuggestedRoutesAsync(ctx context.Context, input *router.RouteInputParams) {
|
||||||
log.Debug("call to GetSuggestedRoutesV2Async")
|
log.Debug("call to GetSuggestedRoutesAsync")
|
||||||
|
|
||||||
api.router.SuggestedRoutesV2Async(input)
|
api.router.SuggestedRoutesAsync(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) StopSuggestedRoutesV2AsyncCalcualtion(ctx context.Context) {
|
func (api *API) StopSuggestedRoutesAsyncCalculation(ctx context.Context) {
|
||||||
log.Debug("call to StopSuggestedRoutesV2AsyncCalcualtion")
|
log.Debug("call to StopSuggestedRoutesAsyncCalculation")
|
||||||
|
|
||||||
api.router.StopSuggestedRoutesV2AsyncCalcualtion()
|
api.router.StopSuggestedRoutesAsyncCalculation()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generates addresses for the provided paths, response doesn't include `HasActivity` value (if you need it check `GetAddressDetails` function)
|
// Generates addresses for the provided paths, response doesn't include `HasActivity` value (if you need it check `GetAddressDetails` function)
|
||||||
|
|
|
@ -20,7 +20,7 @@ func init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterRoutesV2(routes [][]*PathV2, amountIn *big.Int, fromLockedAmount map[uint64]*hexutil.Big) [][]*PathV2 {
|
func filterRoutes(routes [][]*Path, amountIn *big.Int, fromLockedAmount map[uint64]*hexutil.Big) [][]*Path {
|
||||||
for i := len(routes) - 1; i >= 0; i-- {
|
for i := len(routes) - 1; i >= 0; i-- {
|
||||||
routeAmount := big.NewInt(0)
|
routeAmount := big.NewInt(0)
|
||||||
for _, p := range routes[i] {
|
for _, p := range routes[i] {
|
||||||
|
@ -38,18 +38,18 @@ func filterRoutesV2(routes [][]*PathV2, amountIn *big.Int, fromLockedAmount map[
|
||||||
return routes
|
return routes
|
||||||
}
|
}
|
||||||
|
|
||||||
routesAfterNetworkCompliance := filterNetworkComplianceV2(routes, fromLockedAmount)
|
routesAfterNetworkCompliance := filterNetworkCompliance(routes, fromLockedAmount)
|
||||||
return filterCapacityValidationV2(routesAfterNetworkCompliance, amountIn, fromLockedAmount)
|
return filterCapacityValidation(routesAfterNetworkCompliance, amountIn, fromLockedAmount)
|
||||||
}
|
}
|
||||||
|
|
||||||
// filterNetworkComplianceV2 performs the first level of filtering based on network inclusion/exclusion criteria.
|
// filterNetworkCompliance performs the first level of filtering based on network inclusion/exclusion criteria.
|
||||||
func filterNetworkComplianceV2(routes [][]*PathV2, fromLockedAmount map[uint64]*hexutil.Big) [][]*PathV2 {
|
func filterNetworkCompliance(routes [][]*Path, fromLockedAmount map[uint64]*hexutil.Big) [][]*Path {
|
||||||
filteredRoutes := make([][]*PathV2, 0)
|
filteredRoutes := make([][]*Path, 0)
|
||||||
if routes == nil || fromLockedAmount == nil {
|
if routes == nil || fromLockedAmount == nil {
|
||||||
return filteredRoutes
|
return filteredRoutes
|
||||||
}
|
}
|
||||||
|
|
||||||
fromIncluded, fromExcluded := setupRouteValidationMapsV2(fromLockedAmount)
|
fromIncluded, fromExcluded := setupRouteValidationMaps(fromLockedAmount)
|
||||||
|
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
if route == nil {
|
if route == nil {
|
||||||
|
@ -57,15 +57,15 @@ func filterNetworkComplianceV2(routes [][]*PathV2, fromLockedAmount map[uint64]*
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create fresh copies of the maps for each route check, because they are manipulated
|
// Create fresh copies of the maps for each route check, because they are manipulated
|
||||||
if isValidForNetworkComplianceV2(route, copyMapGeneric(fromIncluded, nil).(map[uint64]bool), copyMapGeneric(fromExcluded, nil).(map[uint64]bool)) {
|
if isValidForNetworkCompliance(route, copyMapGeneric(fromIncluded, nil).(map[uint64]bool), copyMapGeneric(fromExcluded, nil).(map[uint64]bool)) {
|
||||||
filteredRoutes = append(filteredRoutes, route)
|
filteredRoutes = append(filteredRoutes, route)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filteredRoutes
|
return filteredRoutes
|
||||||
}
|
}
|
||||||
|
|
||||||
// isValidForNetworkComplianceV2 checks if a route complies with network inclusion/exclusion criteria.
|
// isValidForNetworkCompliance checks if a route complies with network inclusion/exclusion criteria.
|
||||||
func isValidForNetworkComplianceV2(route []*PathV2, fromIncluded, fromExcluded map[uint64]bool) bool {
|
func isValidForNetworkCompliance(route []*Path, fromIncluded, fromExcluded map[uint64]bool) bool {
|
||||||
logger.Debug("Initial inclusion/exclusion maps",
|
logger.Debug("Initial inclusion/exclusion maps",
|
||||||
zap.Any("fromIncluded", fromIncluded),
|
zap.Any("fromIncluded", fromIncluded),
|
||||||
zap.Any("fromExcluded", fromExcluded),
|
zap.Any("fromExcluded", fromExcluded),
|
||||||
|
@ -101,8 +101,8 @@ func isValidForNetworkComplianceV2(route []*PathV2, fromIncluded, fromExcluded m
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// setupRouteValidationMapsV2 initializes maps for network inclusion and exclusion based on locked amounts.
|
// setupRouteValidationMaps initializes maps for network inclusion and exclusion based on locked amounts.
|
||||||
func setupRouteValidationMapsV2(fromLockedAmount map[uint64]*hexutil.Big) (map[uint64]bool, map[uint64]bool) {
|
func setupRouteValidationMaps(fromLockedAmount map[uint64]*hexutil.Big) (map[uint64]bool, map[uint64]bool) {
|
||||||
fromIncluded := make(map[uint64]bool)
|
fromIncluded := make(map[uint64]bool)
|
||||||
fromExcluded := make(map[uint64]bool)
|
fromExcluded := make(map[uint64]bool)
|
||||||
|
|
||||||
|
@ -116,20 +116,20 @@ func setupRouteValidationMapsV2(fromLockedAmount map[uint64]*hexutil.Big) (map[u
|
||||||
return fromIncluded, fromExcluded
|
return fromIncluded, fromExcluded
|
||||||
}
|
}
|
||||||
|
|
||||||
// filterCapacityValidationV2 performs the second level of filtering based on amount and capacity validation.
|
// filterCapacityValidation performs the second level of filtering based on amount and capacity validation.
|
||||||
func filterCapacityValidationV2(routes [][]*PathV2, amountIn *big.Int, fromLockedAmount map[uint64]*hexutil.Big) [][]*PathV2 {
|
func filterCapacityValidation(routes [][]*Path, amountIn *big.Int, fromLockedAmount map[uint64]*hexutil.Big) [][]*Path {
|
||||||
filteredRoutes := make([][]*PathV2, 0)
|
filteredRoutes := make([][]*Path, 0)
|
||||||
|
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
if hasSufficientCapacityV2(route, amountIn, fromLockedAmount) {
|
if hasSufficientCapacity(route, amountIn, fromLockedAmount) {
|
||||||
filteredRoutes = append(filteredRoutes, route)
|
filteredRoutes = append(filteredRoutes, route)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filteredRoutes
|
return filteredRoutes
|
||||||
}
|
}
|
||||||
|
|
||||||
// hasSufficientCapacityV2 checks if a route has sufficient capacity to handle the required amount.
|
// hasSufficientCapacity checks if a route has sufficient capacity to handle the required amount.
|
||||||
func hasSufficientCapacityV2(route []*PathV2, amountIn *big.Int, fromLockedAmount map[uint64]*hexutil.Big) bool {
|
func hasSufficientCapacity(route []*Path, amountIn *big.Int, fromLockedAmount map[uint64]*hexutil.Big) bool {
|
||||||
for _, path := range route {
|
for _, path := range route {
|
||||||
if amount, ok := fromLockedAmount[path.FromChain.ChainID]; ok {
|
if amount, ok := fromLockedAmount[path.FromChain.ChainID]; ok {
|
||||||
if path.AmountIn.ToInt().Cmp(amount.ToInt()) != 0 {
|
if path.AmountIn.ToInt().Cmp(amount.ToInt()) != 0 {
|
||||||
|
@ -137,7 +137,7 @@ func hasSufficientCapacityV2(route []*PathV2, amountIn *big.Int, fromLockedAmoun
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
requiredAmountIn := new(big.Int).Sub(amountIn, amount.ToInt())
|
requiredAmountIn := new(big.Int).Sub(amountIn, amount.ToInt())
|
||||||
restAmountIn := calculateRestAmountInV2(route, path)
|
restAmountIn := calculateRestAmountIn(route, path)
|
||||||
|
|
||||||
logger.Debug("Checking path", zap.Any("path", path))
|
logger.Debug("Checking path", zap.Any("path", path))
|
||||||
logger.Debug("Required amount in", zap.String("requiredAmountIn", requiredAmountIn.String()))
|
logger.Debug("Required amount in", zap.String("requiredAmountIn", requiredAmountIn.String()))
|
||||||
|
@ -153,7 +153,7 @@ func hasSufficientCapacityV2(route []*PathV2, amountIn *big.Int, fromLockedAmoun
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculateRestAmountIn calculates the remaining amount in for the route excluding the specified path
|
// calculateRestAmountIn calculates the remaining amount in for the route excluding the specified path
|
||||||
func calculateRestAmountInV2(route []*PathV2, excludePath *PathV2) *big.Int {
|
func calculateRestAmountIn(route []*Path, excludePath *Path) *big.Int {
|
||||||
restAmountIn := big.NewInt(0)
|
restAmountIn := big.NewInt(0)
|
||||||
for _, path := range route {
|
for _, path := range route {
|
||||||
if path != excludePath {
|
if path != excludePath {
|
||||||
|
|
|
@ -26,24 +26,24 @@ var (
|
||||||
amount4 = hexutil.Big(*big.NewInt(400))
|
amount4 = hexutil.Big(*big.NewInt(400))
|
||||||
amount5 = hexutil.Big(*big.NewInt(500))
|
amount5 = hexutil.Big(*big.NewInt(500))
|
||||||
|
|
||||||
path0 = &PathV2{FromChain: network4, AmountIn: &amount0}
|
path0 = &Path{FromChain: network4, AmountIn: &amount0}
|
||||||
|
|
||||||
pathC1A1 = &PathV2{FromChain: network1, AmountIn: &amount1}
|
pathC1A1 = &Path{FromChain: network1, AmountIn: &amount1}
|
||||||
|
|
||||||
pathC2A1 = &PathV2{FromChain: network2, AmountIn: &amount1}
|
pathC2A1 = &Path{FromChain: network2, AmountIn: &amount1}
|
||||||
pathC2A2 = &PathV2{FromChain: network2, AmountIn: &amount2}
|
pathC2A2 = &Path{FromChain: network2, AmountIn: &amount2}
|
||||||
|
|
||||||
pathC3A1 = &PathV2{FromChain: network3, AmountIn: &amount1}
|
pathC3A1 = &Path{FromChain: network3, AmountIn: &amount1}
|
||||||
pathC3A2 = &PathV2{FromChain: network3, AmountIn: &amount2}
|
pathC3A2 = &Path{FromChain: network3, AmountIn: &amount2}
|
||||||
pathC3A3 = &PathV2{FromChain: network3, AmountIn: &amount3}
|
pathC3A3 = &Path{FromChain: network3, AmountIn: &amount3}
|
||||||
|
|
||||||
pathC4A1 = &PathV2{FromChain: network4, AmountIn: &amount1}
|
pathC4A1 = &Path{FromChain: network4, AmountIn: &amount1}
|
||||||
pathC4A4 = &PathV2{FromChain: network4, AmountIn: &amount4}
|
pathC4A4 = &Path{FromChain: network4, AmountIn: &amount4}
|
||||||
|
|
||||||
pathC5A5 = &PathV2{FromChain: network5, AmountIn: &amount5}
|
pathC5A5 = &Path{FromChain: network5, AmountIn: &amount5}
|
||||||
)
|
)
|
||||||
|
|
||||||
func routesEqual(t *testing.T, expected, actual [][]*PathV2) bool {
|
func routesEqual(t *testing.T, expected, actual [][]*Path) bool {
|
||||||
if len(expected) != len(actual) {
|
if len(expected) != len(actual) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ func routesEqual(t *testing.T, expected, actual [][]*PathV2) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func pathsEqual(t *testing.T, expected, actual []*PathV2) bool {
|
func pathsEqual(t *testing.T, expected, actual []*Path) bool {
|
||||||
if len(expected) != len(actual) {
|
if len(expected) != len(actual) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ func pathsEqual(t *testing.T, expected, actual []*PathV2) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func pathEqual(t *testing.T, expected, actual *PathV2) bool {
|
func pathEqual(t *testing.T, expected, actual *Path) bool {
|
||||||
if expected.FromChain.ChainID != actual.FromChain.ChainID {
|
if expected.FromChain.ChainID != actual.FromChain.ChainID {
|
||||||
t.Logf("expected chain ID '%d' , actual chain ID '%d'", expected.FromChain.ChainID, actual.FromChain.ChainID)
|
t.Logf("expected chain ID '%d' , actual chain ID '%d'", expected.FromChain.ChainID, actual.FromChain.ChainID)
|
||||||
return false
|
return false
|
||||||
|
@ -83,7 +83,7 @@ func pathEqual(t *testing.T, expected, actual *PathV2) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetupRouteValidationMapsV2(t *testing.T) {
|
func TestSetupRouteValidationMaps(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
fromLockedAmount map[uint64]*hexutil.Big
|
fromLockedAmount map[uint64]*hexutil.Big
|
||||||
|
@ -161,53 +161,53 @@ func TestSetupRouteValidationMapsV2(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
included, excluded := setupRouteValidationMapsV2(tt.fromLockedAmount)
|
included, excluded := setupRouteValidationMaps(tt.fromLockedAmount)
|
||||||
assert.Equal(t, tt.expectedIncluded, included)
|
assert.Equal(t, tt.expectedIncluded, included)
|
||||||
assert.Equal(t, tt.expectedExcluded, excluded)
|
assert.Equal(t, tt.expectedExcluded, excluded)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCalculateRestAmountInV2(t *testing.T) {
|
func TestCalculateRestAmountIn(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
route []*PathV2
|
route []*Path
|
||||||
excludePath *PathV2
|
excludePath *Path
|
||||||
expected *big.Int
|
expected *big.Int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Exclude pathC1A1",
|
name: "Exclude pathC1A1",
|
||||||
route: []*PathV2{pathC1A1, pathC2A2, pathC3A3},
|
route: []*Path{pathC1A1, pathC2A2, pathC3A3},
|
||||||
excludePath: pathC1A1,
|
excludePath: pathC1A1,
|
||||||
expected: big.NewInt(500), // 200 + 300
|
expected: big.NewInt(500), // 200 + 300
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Exclude pathC2A2",
|
name: "Exclude pathC2A2",
|
||||||
route: []*PathV2{pathC1A1, pathC2A2, pathC3A3},
|
route: []*Path{pathC1A1, pathC2A2, pathC3A3},
|
||||||
excludePath: pathC2A2,
|
excludePath: pathC2A2,
|
||||||
expected: big.NewInt(400), // 100 + 300
|
expected: big.NewInt(400), // 100 + 300
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Exclude pathC3A3",
|
name: "Exclude pathC3A3",
|
||||||
route: []*PathV2{pathC1A1, pathC2A2, pathC3A3},
|
route: []*Path{pathC1A1, pathC2A2, pathC3A3},
|
||||||
excludePath: pathC3A3,
|
excludePath: pathC3A3,
|
||||||
expected: big.NewInt(300), // 100 + 200
|
expected: big.NewInt(300), // 100 + 200
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Single path, exclude that path",
|
name: "Single path, exclude that path",
|
||||||
route: []*PathV2{pathC1A1},
|
route: []*Path{pathC1A1},
|
||||||
excludePath: pathC1A1,
|
excludePath: pathC1A1,
|
||||||
expected: big.NewInt(0), // No other paths
|
expected: big.NewInt(0), // No other paths
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Empty route",
|
name: "Empty route",
|
||||||
route: []*PathV2{},
|
route: []*Path{},
|
||||||
excludePath: pathC1A1,
|
excludePath: pathC1A1,
|
||||||
expected: big.NewInt(0), // No paths
|
expected: big.NewInt(0), // No paths
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Empty route, with nil exclude",
|
name: "Empty route, with nil exclude",
|
||||||
route: []*PathV2{},
|
route: []*Path{},
|
||||||
excludePath: nil,
|
excludePath: nil,
|
||||||
expected: big.NewInt(0), // No paths
|
expected: big.NewInt(0), // No paths
|
||||||
},
|
},
|
||||||
|
@ -215,65 +215,65 @@ func TestCalculateRestAmountInV2(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
result := calculateRestAmountInV2(tt.route, tt.excludePath)
|
result := calculateRestAmountIn(tt.route, tt.excludePath)
|
||||||
assert.Equal(t, tt.expected, result)
|
assert.Equal(t, tt.expected, result)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsValidForNetworkComplianceV2(t *testing.T) {
|
func TestIsValidForNetworkCompliance(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
route []*PathV2
|
route []*Path
|
||||||
fromIncluded map[uint64]bool
|
fromIncluded map[uint64]bool
|
||||||
fromExcluded map[uint64]bool
|
fromExcluded map[uint64]bool
|
||||||
expectedResult bool
|
expectedResult bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Route with all included chain IDs",
|
name: "Route with all included chain IDs",
|
||||||
route: []*PathV2{pathC1A1, pathC2A2},
|
route: []*Path{pathC1A1, pathC2A2},
|
||||||
fromIncluded: map[uint64]bool{1: true, 2: true},
|
fromIncluded: map[uint64]bool{1: true, 2: true},
|
||||||
fromExcluded: map[uint64]bool{},
|
fromExcluded: map[uint64]bool{},
|
||||||
expectedResult: true,
|
expectedResult: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Route with fromExcluded only",
|
name: "Route with fromExcluded only",
|
||||||
route: []*PathV2{pathC1A1, pathC2A2},
|
route: []*Path{pathC1A1, pathC2A2},
|
||||||
fromIncluded: map[uint64]bool{},
|
fromIncluded: map[uint64]bool{},
|
||||||
fromExcluded: map[uint64]bool{3: false, 4: false},
|
fromExcluded: map[uint64]bool{3: false, 4: false},
|
||||||
expectedResult: true,
|
expectedResult: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Route without excluded chain IDs",
|
name: "Route without excluded chain IDs",
|
||||||
route: []*PathV2{pathC1A1, pathC2A2},
|
route: []*Path{pathC1A1, pathC2A2},
|
||||||
fromIncluded: map[uint64]bool{1: false, 2: false},
|
fromIncluded: map[uint64]bool{1: false, 2: false},
|
||||||
fromExcluded: map[uint64]bool{3: false, 4: false},
|
fromExcluded: map[uint64]bool{3: false, 4: false},
|
||||||
expectedResult: true,
|
expectedResult: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Route with an excluded chain ID",
|
name: "Route with an excluded chain ID",
|
||||||
route: []*PathV2{pathC1A1, pathC3A3},
|
route: []*Path{pathC1A1, pathC3A3},
|
||||||
fromIncluded: map[uint64]bool{1: false, 2: false},
|
fromIncluded: map[uint64]bool{1: false, 2: false},
|
||||||
fromExcluded: map[uint64]bool{3: false, 4: false},
|
fromExcluded: map[uint64]bool{3: false, 4: false},
|
||||||
expectedResult: false,
|
expectedResult: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Route missing one included chain ID",
|
name: "Route missing one included chain ID",
|
||||||
route: []*PathV2{pathC1A1},
|
route: []*Path{pathC1A1},
|
||||||
fromIncluded: map[uint64]bool{1: false, 2: false},
|
fromIncluded: map[uint64]bool{1: false, 2: false},
|
||||||
fromExcluded: map[uint64]bool{},
|
fromExcluded: map[uint64]bool{},
|
||||||
expectedResult: false,
|
expectedResult: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Route with no fromIncluded or fromExcluded",
|
name: "Route with no fromIncluded or fromExcluded",
|
||||||
route: []*PathV2{pathC1A1, pathC2A2},
|
route: []*Path{pathC1A1, pathC2A2},
|
||||||
fromIncluded: map[uint64]bool{},
|
fromIncluded: map[uint64]bool{},
|
||||||
fromExcluded: map[uint64]bool{},
|
fromExcluded: map[uint64]bool{},
|
||||||
expectedResult: true,
|
expectedResult: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Empty route",
|
name: "Empty route",
|
||||||
route: []*PathV2{},
|
route: []*Path{},
|
||||||
fromIncluded: map[uint64]bool{1: false, 2: false},
|
fromIncluded: map[uint64]bool{1: false, 2: false},
|
||||||
fromExcluded: map[uint64]bool{3: false, 4: false},
|
fromExcluded: map[uint64]bool{3: false, 4: false},
|
||||||
expectedResult: false,
|
expectedResult: false,
|
||||||
|
@ -282,23 +282,23 @@ func TestIsValidForNetworkComplianceV2(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
result := isValidForNetworkComplianceV2(tt.route, tt.fromIncluded, tt.fromExcluded)
|
result := isValidForNetworkCompliance(tt.route, tt.fromIncluded, tt.fromExcluded)
|
||||||
assert.Equal(t, tt.expectedResult, result)
|
assert.Equal(t, tt.expectedResult, result)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHasSufficientCapacityV2(t *testing.T) {
|
func TestHasSufficientCapacity(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
route []*PathV2
|
route []*Path
|
||||||
amountIn *big.Int
|
amountIn *big.Int
|
||||||
fromLockedAmount map[uint64]*hexutil.Big
|
fromLockedAmount map[uint64]*hexutil.Big
|
||||||
expected bool
|
expected bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "All paths meet required amount",
|
name: "All paths meet required amount",
|
||||||
route: []*PathV2{pathC1A1, pathC2A2, pathC3A3},
|
route: []*Path{pathC1A1, pathC2A2, pathC3A3},
|
||||||
amountIn: big.NewInt(600),
|
amountIn: big.NewInt(600),
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2, 3: &amount3},
|
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2, 3: &amount3},
|
||||||
expected: true,
|
expected: true,
|
||||||
|
@ -308,7 +308,7 @@ func TestHasSufficientCapacityV2(t *testing.T) {
|
||||||
/*
|
/*
|
||||||
{
|
{
|
||||||
name: "A path does not meet required amount",
|
name: "A path does not meet required amount",
|
||||||
route: []*PathV2{pathC1A1, pathC2A2, pathC3A3},
|
route: []*Path{pathC1A1, pathC2A2, pathC3A3},
|
||||||
amountIn: big.NewInt(600),
|
amountIn: big.NewInt(600),
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2, 4: &amount4},
|
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2, 4: &amount4},
|
||||||
expected: false,
|
expected: false,
|
||||||
|
@ -316,42 +316,42 @@ func TestHasSufficientCapacityV2(t *testing.T) {
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
name: "No fromLockedAmount",
|
name: "No fromLockedAmount",
|
||||||
route: []*PathV2{pathC1A1, pathC2A2, pathC3A3},
|
route: []*Path{pathC1A1, pathC2A2, pathC3A3},
|
||||||
amountIn: big.NewInt(600),
|
amountIn: big.NewInt(600),
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{},
|
fromLockedAmount: map[uint64]*hexutil.Big{},
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Single path meets required amount",
|
name: "Single path meets required amount",
|
||||||
route: []*PathV2{pathC1A1},
|
route: []*Path{pathC1A1},
|
||||||
amountIn: big.NewInt(100),
|
amountIn: big.NewInt(100),
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1},
|
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1},
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Single path does not meet required amount",
|
name: "Single path does not meet required amount",
|
||||||
route: []*PathV2{pathC1A1},
|
route: []*Path{pathC1A1},
|
||||||
amountIn: big.NewInt(200),
|
amountIn: big.NewInt(200),
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1},
|
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1},
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Path meets required amount with excess",
|
name: "Path meets required amount with excess",
|
||||||
route: []*PathV2{pathC1A1, pathC2A2},
|
route: []*Path{pathC1A1, pathC2A2},
|
||||||
amountIn: big.NewInt(250),
|
amountIn: big.NewInt(250),
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2},
|
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2},
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Path does not meet required amount due to insufficient rest",
|
name: "Path does not meet required amount due to insufficient rest",
|
||||||
route: []*PathV2{pathC1A1, pathC2A2, pathC4A4},
|
route: []*Path{pathC1A1, pathC2A2, pathC4A4},
|
||||||
amountIn: big.NewInt(800),
|
amountIn: big.NewInt(800),
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 4: &amount4},
|
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 4: &amount4},
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Empty route",
|
name: "Empty route",
|
||||||
route: []*PathV2{},
|
route: []*Path{},
|
||||||
amountIn: big.NewInt(500),
|
amountIn: big.NewInt(500),
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2},
|
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2},
|
||||||
expected: true,
|
expected: true,
|
||||||
|
@ -360,22 +360,22 @@ func TestHasSufficientCapacityV2(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
result := hasSufficientCapacityV2(tt.route, tt.amountIn, tt.fromLockedAmount)
|
result := hasSufficientCapacity(tt.route, tt.amountIn, tt.fromLockedAmount)
|
||||||
assert.Equal(t, tt.expected, result)
|
assert.Equal(t, tt.expected, result)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterNetworkComplianceV2(t *testing.T) {
|
func TestFilterNetworkCompliance(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
routes [][]*PathV2
|
routes [][]*Path
|
||||||
fromLockedAmount map[uint64]*hexutil.Big
|
fromLockedAmount map[uint64]*hexutil.Big
|
||||||
expected [][]*PathV2
|
expected [][]*Path
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Mixed routes with valid and invalid paths",
|
name: "Mixed routes with valid and invalid paths",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1},
|
{FromChain: network1},
|
||||||
{FromChain: network3},
|
{FromChain: network3},
|
||||||
|
@ -394,7 +394,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) {
|
||||||
1: (*hexutil.Big)(big.NewInt(100)),
|
1: (*hexutil.Big)(big.NewInt(100)),
|
||||||
2: (*hexutil.Big)(big.NewInt(0)),
|
2: (*hexutil.Big)(big.NewInt(0)),
|
||||||
},
|
},
|
||||||
expected: [][]*PathV2{
|
expected: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1},
|
{FromChain: network1},
|
||||||
{FromChain: network3},
|
{FromChain: network3},
|
||||||
|
@ -403,7 +403,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "All valid routes",
|
name: "All valid routes",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1},
|
{FromChain: network1},
|
||||||
{FromChain: network3},
|
{FromChain: network3},
|
||||||
|
@ -416,7 +416,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) {
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{
|
fromLockedAmount: map[uint64]*hexutil.Big{
|
||||||
1: (*hexutil.Big)(big.NewInt(100)),
|
1: (*hexutil.Big)(big.NewInt(100)),
|
||||||
},
|
},
|
||||||
expected: [][]*PathV2{
|
expected: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1},
|
{FromChain: network1},
|
||||||
{FromChain: network3},
|
{FromChain: network3},
|
||||||
|
@ -429,7 +429,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "All invalid routes",
|
name: "All invalid routes",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network2},
|
{FromChain: network2},
|
||||||
{FromChain: network3},
|
{FromChain: network3},
|
||||||
|
@ -443,19 +443,19 @@ func TestFilterNetworkComplianceV2(t *testing.T) {
|
||||||
1: (*hexutil.Big)(big.NewInt(100)),
|
1: (*hexutil.Big)(big.NewInt(100)),
|
||||||
2: (*hexutil.Big)(big.NewInt(0)),
|
2: (*hexutil.Big)(big.NewInt(0)),
|
||||||
},
|
},
|
||||||
expected: [][]*PathV2{},
|
expected: [][]*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Empty routes",
|
name: "Empty routes",
|
||||||
routes: [][]*PathV2{},
|
routes: [][]*Path{},
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{
|
fromLockedAmount: map[uint64]*hexutil.Big{
|
||||||
1: (*hexutil.Big)(big.NewInt(100)),
|
1: (*hexutil.Big)(big.NewInt(100)),
|
||||||
},
|
},
|
||||||
expected: [][]*PathV2{},
|
expected: [][]*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "No locked amounts",
|
name: "No locked amounts",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1},
|
{FromChain: network1},
|
||||||
{FromChain: network2},
|
{FromChain: network2},
|
||||||
|
@ -466,7 +466,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{},
|
fromLockedAmount: map[uint64]*hexutil.Big{},
|
||||||
expected: [][]*PathV2{
|
expected: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1},
|
{FromChain: network1},
|
||||||
{FromChain: network2},
|
{FromChain: network2},
|
||||||
|
@ -479,7 +479,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Single route with mixed valid and invalid paths",
|
name: "Single route with mixed valid and invalid paths",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1},
|
{FromChain: network1},
|
||||||
{FromChain: network2},
|
{FromChain: network2},
|
||||||
|
@ -490,11 +490,11 @@ func TestFilterNetworkComplianceV2(t *testing.T) {
|
||||||
1: (*hexutil.Big)(big.NewInt(100)),
|
1: (*hexutil.Big)(big.NewInt(100)),
|
||||||
2: (*hexutil.Big)(big.NewInt(0)),
|
2: (*hexutil.Big)(big.NewInt(0)),
|
||||||
},
|
},
|
||||||
expected: [][]*PathV2{},
|
expected: [][]*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Routes with duplicate chain IDs",
|
name: "Routes with duplicate chain IDs",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1},
|
{FromChain: network1},
|
||||||
{FromChain: network1},
|
{FromChain: network1},
|
||||||
|
@ -504,7 +504,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) {
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{
|
fromLockedAmount: map[uint64]*hexutil.Big{
|
||||||
1: (*hexutil.Big)(big.NewInt(100)),
|
1: (*hexutil.Big)(big.NewInt(100)),
|
||||||
},
|
},
|
||||||
expected: [][]*PathV2{
|
expected: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1},
|
{FromChain: network1},
|
||||||
{FromChain: network1},
|
{FromChain: network1},
|
||||||
|
@ -514,7 +514,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Minimum and maximum chain IDs",
|
name: "Minimum and maximum chain IDs",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: ¶ms.Network{ChainID: 0}},
|
{FromChain: ¶ms.Network{ChainID: 0}},
|
||||||
{FromChain: ¶ms.Network{ChainID: ^uint64(0)}},
|
{FromChain: ¶ms.Network{ChainID: ^uint64(0)}},
|
||||||
|
@ -524,7 +524,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) {
|
||||||
0: (*hexutil.Big)(big.NewInt(100)),
|
0: (*hexutil.Big)(big.NewInt(100)),
|
||||||
^uint64(0): (*hexutil.Big)(big.NewInt(100)),
|
^uint64(0): (*hexutil.Big)(big.NewInt(100)),
|
||||||
},
|
},
|
||||||
expected: [][]*PathV2{
|
expected: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: ¶ms.Network{ChainID: 0}},
|
{FromChain: ¶ms.Network{ChainID: 0}},
|
||||||
{FromChain: ¶ms.Network{ChainID: ^uint64(0)}},
|
{FromChain: ¶ms.Network{ChainID: ^uint64(0)}},
|
||||||
|
@ -533,10 +533,10 @@ func TestFilterNetworkComplianceV2(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Large number of routes",
|
name: "Large number of routes",
|
||||||
routes: func() [][]*PathV2 {
|
routes: func() [][]*Path {
|
||||||
var routes [][]*PathV2
|
var routes [][]*Path
|
||||||
for i := 0; i < 1000; i++ {
|
for i := 0; i < 1000; i++ {
|
||||||
routes = append(routes, []*PathV2{
|
routes = append(routes, []*Path{
|
||||||
{FromChain: ¶ms.Network{ChainID: uint64(i + 1)}},
|
{FromChain: ¶ms.Network{ChainID: uint64(i + 1)}},
|
||||||
{FromChain: ¶ms.Network{ChainID: uint64(i + 1001)}},
|
{FromChain: ¶ms.Network{ChainID: uint64(i + 1001)}},
|
||||||
})
|
})
|
||||||
|
@ -547,10 +547,10 @@ func TestFilterNetworkComplianceV2(t *testing.T) {
|
||||||
1: (*hexutil.Big)(big.NewInt(100)),
|
1: (*hexutil.Big)(big.NewInt(100)),
|
||||||
1001: (*hexutil.Big)(big.NewInt(100)),
|
1001: (*hexutil.Big)(big.NewInt(100)),
|
||||||
},
|
},
|
||||||
expected: func() [][]*PathV2 {
|
expected: func() [][]*Path {
|
||||||
var routes [][]*PathV2
|
var routes [][]*Path
|
||||||
for i := 0; i < 1; i++ {
|
for i := 0; i < 1; i++ {
|
||||||
routes = append(routes, []*PathV2{
|
routes = append(routes, []*Path{
|
||||||
{FromChain: ¶ms.Network{ChainID: uint64(i + 1)}},
|
{FromChain: ¶ms.Network{ChainID: uint64(i + 1)}},
|
||||||
{FromChain: ¶ms.Network{ChainID: uint64(i + 1001)}},
|
{FromChain: ¶ms.Network{ChainID: uint64(i + 1001)}},
|
||||||
})
|
})
|
||||||
|
@ -560,7 +560,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Routes with missing data",
|
name: "Routes with missing data",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: nil},
|
{FromChain: nil},
|
||||||
{FromChain: network2},
|
{FromChain: network2},
|
||||||
|
@ -574,11 +574,11 @@ func TestFilterNetworkComplianceV2(t *testing.T) {
|
||||||
1: (*hexutil.Big)(big.NewInt(100)),
|
1: (*hexutil.Big)(big.NewInt(100)),
|
||||||
2: (*hexutil.Big)(big.NewInt(0)),
|
2: (*hexutil.Big)(big.NewInt(0)),
|
||||||
},
|
},
|
||||||
expected: [][]*PathV2{},
|
expected: [][]*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Consistency check",
|
name: "Consistency check",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1},
|
{FromChain: network1},
|
||||||
{FromChain: network2},
|
{FromChain: network2},
|
||||||
|
@ -591,7 +591,7 @@ func TestFilterNetworkComplianceV2(t *testing.T) {
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{
|
fromLockedAmount: map[uint64]*hexutil.Big{
|
||||||
1: (*hexutil.Big)(big.NewInt(100)),
|
1: (*hexutil.Big)(big.NewInt(100)),
|
||||||
},
|
},
|
||||||
expected: [][]*PathV2{
|
expected: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1},
|
{FromChain: network1},
|
||||||
{FromChain: network2},
|
{FromChain: network2},
|
||||||
|
@ -604,101 +604,101 @@ func TestFilterNetworkComplianceV2(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Routes without excluded chain IDs, missing included path",
|
name: "Routes without excluded chain IDs, missing included path",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{pathC1A1, pathC2A2},
|
{pathC1A1, pathC2A2},
|
||||||
{pathC2A2, pathC3A3},
|
{pathC2A2, pathC3A3},
|
||||||
},
|
},
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2},
|
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2},
|
||||||
expected: [][]*PathV2{
|
expected: [][]*Path{
|
||||||
{pathC1A1, pathC2A2},
|
{pathC1A1, pathC2A2},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Routes with an excluded chain ID",
|
name: "Routes with an excluded chain ID",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{pathC1A1, pathC2A2},
|
{pathC1A1, pathC2A2},
|
||||||
{pathC2A2, pathC3A3, path0},
|
{pathC2A2, pathC3A3, path0},
|
||||||
},
|
},
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2, 4: &amount0},
|
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2, 4: &amount0},
|
||||||
expected: [][]*PathV2{
|
expected: [][]*Path{
|
||||||
{pathC1A1, pathC2A2},
|
{pathC1A1, pathC2A2},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Routes with all included chain IDs",
|
name: "Routes with all included chain IDs",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{pathC1A1, pathC2A2, pathC3A3},
|
{pathC1A1, pathC2A2, pathC3A3},
|
||||||
},
|
},
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2, 3: &amount3},
|
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2, 3: &amount3},
|
||||||
expected: [][]*PathV2{
|
expected: [][]*Path{
|
||||||
{pathC1A1, pathC2A2, pathC3A3},
|
{pathC1A1, pathC2A2, pathC3A3},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Routes missing one included chain ID",
|
name: "Routes missing one included chain ID",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{pathC1A1, pathC2A2},
|
{pathC1A1, pathC2A2},
|
||||||
{pathC1A1},
|
{pathC1A1},
|
||||||
},
|
},
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2, 3: &amount3},
|
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2, 3: &amount3},
|
||||||
expected: [][]*PathV2{},
|
expected: [][]*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Routes with no fromLockedAmount",
|
name: "Routes with no fromLockedAmount",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{pathC1A1, pathC2A2},
|
{pathC1A1, pathC2A2},
|
||||||
{pathC2A2, pathC3A3},
|
{pathC2A2, pathC3A3},
|
||||||
},
|
},
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{},
|
fromLockedAmount: map[uint64]*hexutil.Big{},
|
||||||
expected: [][]*PathV2{
|
expected: [][]*Path{
|
||||||
{pathC1A1, pathC2A2},
|
{pathC1A1, pathC2A2},
|
||||||
{pathC2A2, pathC3A3},
|
{pathC2A2, pathC3A3},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Routes with fromExcluded only",
|
name: "Routes with fromExcluded only",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{pathC1A1, pathC2A2},
|
{pathC1A1, pathC2A2},
|
||||||
{pathC2A2, pathC3A3},
|
{pathC2A2, pathC3A3},
|
||||||
},
|
},
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{4: &amount0},
|
fromLockedAmount: map[uint64]*hexutil.Big{4: &amount0},
|
||||||
expected: [][]*PathV2{
|
expected: [][]*Path{
|
||||||
{pathC1A1, pathC2A2},
|
{pathC1A1, pathC2A2},
|
||||||
{pathC2A2, pathC3A3},
|
{pathC2A2, pathC3A3},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Routes with all excluded chain IDs",
|
name: "Routes with all excluded chain IDs",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{path0, pathC1A1},
|
{path0, pathC1A1},
|
||||||
{path0, pathC2A2},
|
{path0, pathC2A2},
|
||||||
},
|
},
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2, 3: &amount3, 4: &amount0},
|
fromLockedAmount: map[uint64]*hexutil.Big{1: &amount1, 2: &amount2, 3: &amount3, 4: &amount0},
|
||||||
expected: [][]*PathV2{},
|
expected: [][]*Path{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
t.Logf("Original Routes: %+v\n", tt.routes)
|
t.Logf("Original Routes: %+v\n", tt.routes)
|
||||||
filteredRoutes := filterNetworkComplianceV2(tt.routes, tt.fromLockedAmount)
|
filteredRoutes := filterNetworkCompliance(tt.routes, tt.fromLockedAmount)
|
||||||
t.Logf("Filtered Routes: %+v\n", filteredRoutes)
|
t.Logf("Filtered Routes: %+v\n", filteredRoutes)
|
||||||
assert.Equal(t, tt.expected, filteredRoutes)
|
assert.Equal(t, tt.expected, filteredRoutes)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterCapacityValidationV2(t *testing.T) {
|
func TestFilterCapacityValidation(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
routes [][]*PathV2
|
routes [][]*Path
|
||||||
amountIn *big.Int
|
amountIn *big.Int
|
||||||
fromLockedAmount map[uint64]*hexutil.Big
|
fromLockedAmount map[uint64]*hexutil.Big
|
||||||
expectedRoutes [][]*PathV2
|
expectedRoutes [][]*Path
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Sufficient capacity with multiple paths",
|
name: "Sufficient capacity with multiple paths",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
||||||
{FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
{FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
||||||
|
@ -717,7 +717,7 @@ func TestFilterCapacityValidationV2(t *testing.T) {
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{
|
fromLockedAmount: map[uint64]*hexutil.Big{
|
||||||
1: (*hexutil.Big)(big.NewInt(50)),
|
1: (*hexutil.Big)(big.NewInt(50)),
|
||||||
},
|
},
|
||||||
expectedRoutes: [][]*PathV2{
|
expectedRoutes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
||||||
{FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
{FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
||||||
|
@ -731,7 +731,7 @@ func TestFilterCapacityValidationV2(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Insufficient capacity",
|
name: "Insufficient capacity",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
||||||
{FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
{FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
||||||
|
@ -742,11 +742,11 @@ func TestFilterCapacityValidationV2(t *testing.T) {
|
||||||
1: (*hexutil.Big)(big.NewInt(50)),
|
1: (*hexutil.Big)(big.NewInt(50)),
|
||||||
2: (*hexutil.Big)(big.NewInt(50)),
|
2: (*hexutil.Big)(big.NewInt(50)),
|
||||||
},
|
},
|
||||||
expectedRoutes: [][]*PathV2{},
|
expectedRoutes: [][]*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Exact capacity match",
|
name: "Exact capacity match",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
||||||
{FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
{FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
||||||
|
@ -757,7 +757,7 @@ func TestFilterCapacityValidationV2(t *testing.T) {
|
||||||
1: (*hexutil.Big)(big.NewInt(100)),
|
1: (*hexutil.Big)(big.NewInt(100)),
|
||||||
2: (*hexutil.Big)(big.NewInt(50)),
|
2: (*hexutil.Big)(big.NewInt(50)),
|
||||||
},
|
},
|
||||||
expectedRoutes: [][]*PathV2{
|
expectedRoutes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
||||||
{FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
{FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
||||||
|
@ -766,7 +766,7 @@ func TestFilterCapacityValidationV2(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "No locked amounts",
|
name: "No locked amounts",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
||||||
{FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
{FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
||||||
|
@ -774,7 +774,7 @@ func TestFilterCapacityValidationV2(t *testing.T) {
|
||||||
},
|
},
|
||||||
amountIn: big.NewInt(150),
|
amountIn: big.NewInt(150),
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{},
|
fromLockedAmount: map[uint64]*hexutil.Big{},
|
||||||
expectedRoutes: [][]*PathV2{
|
expectedRoutes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
||||||
{FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
{FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
||||||
|
@ -783,7 +783,7 @@ func TestFilterCapacityValidationV2(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Single route with sufficient capacity",
|
name: "Single route with sufficient capacity",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
||||||
{FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
{FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
||||||
|
@ -793,7 +793,7 @@ func TestFilterCapacityValidationV2(t *testing.T) {
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{
|
fromLockedAmount: map[uint64]*hexutil.Big{
|
||||||
1: (*hexutil.Big)(big.NewInt(50)),
|
1: (*hexutil.Big)(big.NewInt(50)),
|
||||||
},
|
},
|
||||||
expectedRoutes: [][]*PathV2{
|
expectedRoutes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
||||||
{FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
{FromChain: network2, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
||||||
|
@ -802,7 +802,7 @@ func TestFilterCapacityValidationV2(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Single route with inappropriately locked amount",
|
name: "Single route with inappropriately locked amount",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
||||||
},
|
},
|
||||||
|
@ -811,11 +811,11 @@ func TestFilterCapacityValidationV2(t *testing.T) {
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{
|
fromLockedAmount: map[uint64]*hexutil.Big{
|
||||||
1: (*hexutil.Big)(big.NewInt(50)),
|
1: (*hexutil.Big)(big.NewInt(50)),
|
||||||
},
|
},
|
||||||
expectedRoutes: [][]*PathV2{},
|
expectedRoutes: [][]*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Single route with insufficient capacity",
|
name: "Single route with insufficient capacity",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
||||||
},
|
},
|
||||||
|
@ -824,20 +824,20 @@ func TestFilterCapacityValidationV2(t *testing.T) {
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{
|
fromLockedAmount: map[uint64]*hexutil.Big{
|
||||||
1: (*hexutil.Big)(big.NewInt(50)),
|
1: (*hexutil.Big)(big.NewInt(50)),
|
||||||
},
|
},
|
||||||
expectedRoutes: [][]*PathV2{},
|
expectedRoutes: [][]*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Empty routes",
|
name: "Empty routes",
|
||||||
routes: [][]*PathV2{},
|
routes: [][]*Path{},
|
||||||
amountIn: big.NewInt(150),
|
amountIn: big.NewInt(150),
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{
|
fromLockedAmount: map[uint64]*hexutil.Big{
|
||||||
1: (*hexutil.Big)(big.NewInt(50)),
|
1: (*hexutil.Big)(big.NewInt(50)),
|
||||||
},
|
},
|
||||||
expectedRoutes: [][]*PathV2{},
|
expectedRoutes: [][]*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Partial locked amounts",
|
name: "Partial locked amounts",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
||||||
{FromChain: network3, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
{FromChain: network3, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
||||||
|
@ -850,7 +850,7 @@ func TestFilterCapacityValidationV2(t *testing.T) {
|
||||||
2: (*hexutil.Big)(big.NewInt(0)), // Excluded path
|
2: (*hexutil.Big)(big.NewInt(0)), // Excluded path
|
||||||
3: (*hexutil.Big)(big.NewInt(100)),
|
3: (*hexutil.Big)(big.NewInt(100)),
|
||||||
},
|
},
|
||||||
expectedRoutes: [][]*PathV2{
|
expectedRoutes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(50))},
|
||||||
{FromChain: network3, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
{FromChain: network3, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
||||||
|
@ -860,7 +860,7 @@ func TestFilterCapacityValidationV2(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Mixed networks with sufficient capacity",
|
name: "Mixed networks with sufficient capacity",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
||||||
{FromChain: network3, AmountIn: (*hexutil.Big)(big.NewInt(200))},
|
{FromChain: network3, AmountIn: (*hexutil.Big)(big.NewInt(200))},
|
||||||
|
@ -871,7 +871,7 @@ func TestFilterCapacityValidationV2(t *testing.T) {
|
||||||
1: (*hexutil.Big)(big.NewInt(100)),
|
1: (*hexutil.Big)(big.NewInt(100)),
|
||||||
3: (*hexutil.Big)(big.NewInt(200)),
|
3: (*hexutil.Big)(big.NewInt(200)),
|
||||||
},
|
},
|
||||||
expectedRoutes: [][]*PathV2{
|
expectedRoutes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
||||||
{FromChain: network3, AmountIn: (*hexutil.Big)(big.NewInt(200))},
|
{FromChain: network3, AmountIn: (*hexutil.Big)(big.NewInt(200))},
|
||||||
|
@ -880,7 +880,7 @@ func TestFilterCapacityValidationV2(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Mixed networks with insufficient capacity",
|
name: "Mixed networks with insufficient capacity",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{
|
{
|
||||||
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
{FromChain: network1, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
||||||
{FromChain: network3, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
{FromChain: network3, AmountIn: (*hexutil.Big)(big.NewInt(100))},
|
||||||
|
@ -891,13 +891,13 @@ func TestFilterCapacityValidationV2(t *testing.T) {
|
||||||
1: (*hexutil.Big)(big.NewInt(50)),
|
1: (*hexutil.Big)(big.NewInt(50)),
|
||||||
3: (*hexutil.Big)(big.NewInt(100)),
|
3: (*hexutil.Big)(big.NewInt(100)),
|
||||||
},
|
},
|
||||||
expectedRoutes: [][]*PathV2{},
|
expectedRoutes: [][]*Path{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
filteredRoutes := filterCapacityValidationV2(tt.routes, tt.amountIn, tt.fromLockedAmount)
|
filteredRoutes := filterCapacityValidation(tt.routes, tt.amountIn, tt.fromLockedAmount)
|
||||||
if !routesEqual(t, tt.expectedRoutes, filteredRoutes) {
|
if !routesEqual(t, tt.expectedRoutes, filteredRoutes) {
|
||||||
t.Errorf("Expected: %+v, Actual: %+v", tt.expectedRoutes, filteredRoutes)
|
t.Errorf("Expected: %+v, Actual: %+v", tt.expectedRoutes, filteredRoutes)
|
||||||
}
|
}
|
||||||
|
@ -905,53 +905,53 @@ func TestFilterCapacityValidationV2(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterRoutesV2(t *testing.T) {
|
func TestFilterRoutes(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
routes [][]*PathV2
|
routes [][]*Path
|
||||||
amountIn *big.Int
|
amountIn *big.Int
|
||||||
fromLockedAmount map[uint64]*hexutil.Big
|
fromLockedAmount map[uint64]*hexutil.Big
|
||||||
expectedRoutes [][]*PathV2
|
expectedRoutes [][]*Path
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Empty fromLockedAmount and routes don't match amountIn",
|
name: "Empty fromLockedAmount and routes don't match amountIn",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{pathC1A1, pathC2A2},
|
{pathC1A1, pathC2A2},
|
||||||
{pathC3A3, pathC4A4},
|
{pathC3A3, pathC4A4},
|
||||||
},
|
},
|
||||||
amountIn: big.NewInt(150),
|
amountIn: big.NewInt(150),
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{},
|
fromLockedAmount: map[uint64]*hexutil.Big{},
|
||||||
expectedRoutes: [][]*PathV2{},
|
expectedRoutes: [][]*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Empty fromLockedAmount and sigle route match amountIn",
|
name: "Empty fromLockedAmount and sigle route match amountIn",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{pathC1A1, pathC2A2},
|
{pathC1A1, pathC2A2},
|
||||||
{pathC3A3, pathC4A4},
|
{pathC3A3, pathC4A4},
|
||||||
},
|
},
|
||||||
amountIn: big.NewInt(300),
|
amountIn: big.NewInt(300),
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{},
|
fromLockedAmount: map[uint64]*hexutil.Big{},
|
||||||
expectedRoutes: [][]*PathV2{
|
expectedRoutes: [][]*Path{
|
||||||
{pathC1A1, pathC2A2},
|
{pathC1A1, pathC2A2},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Empty fromLockedAmount and more routes match amountIn",
|
name: "Empty fromLockedAmount and more routes match amountIn",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{pathC1A1, pathC2A2},
|
{pathC1A1, pathC2A2},
|
||||||
{pathC3A3, pathC4A4},
|
{pathC3A3, pathC4A4},
|
||||||
{pathC1A1, pathC2A1, pathC3A1},
|
{pathC1A1, pathC2A1, pathC3A1},
|
||||||
},
|
},
|
||||||
amountIn: big.NewInt(300),
|
amountIn: big.NewInt(300),
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{},
|
fromLockedAmount: map[uint64]*hexutil.Big{},
|
||||||
expectedRoutes: [][]*PathV2{
|
expectedRoutes: [][]*Path{
|
||||||
{pathC1A1, pathC2A2},
|
{pathC1A1, pathC2A2},
|
||||||
{pathC1A1, pathC2A1, pathC3A1},
|
{pathC1A1, pathC2A1, pathC3A1},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "All paths appear in fromLockedAmount but not within a single route",
|
name: "All paths appear in fromLockedAmount but not within a single route",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{pathC1A1, pathC3A3},
|
{pathC1A1, pathC3A3},
|
||||||
{pathC2A2, pathC4A4},
|
{pathC2A2, pathC4A4},
|
||||||
},
|
},
|
||||||
|
@ -962,11 +962,11 @@ func TestFilterRoutesV2(t *testing.T) {
|
||||||
3: &amount3,
|
3: &amount3,
|
||||||
4: &amount4,
|
4: &amount4,
|
||||||
},
|
},
|
||||||
expectedRoutes: [][]*PathV2{},
|
expectedRoutes: [][]*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Mixed valid and invalid routes I",
|
name: "Mixed valid and invalid routes I",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{pathC1A1, pathC2A2},
|
{pathC1A1, pathC2A2},
|
||||||
{pathC2A2, pathC3A3},
|
{pathC2A2, pathC3A3},
|
||||||
{pathC1A1, pathC4A4},
|
{pathC1A1, pathC4A4},
|
||||||
|
@ -977,13 +977,13 @@ func TestFilterRoutesV2(t *testing.T) {
|
||||||
1: &amount1,
|
1: &amount1,
|
||||||
2: &amount2,
|
2: &amount2,
|
||||||
},
|
},
|
||||||
expectedRoutes: [][]*PathV2{
|
expectedRoutes: [][]*Path{
|
||||||
{pathC1A1, pathC2A2},
|
{pathC1A1, pathC2A2},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Mixed valid and invalid routes II",
|
name: "Mixed valid and invalid routes II",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{pathC1A1, pathC2A2},
|
{pathC1A1, pathC2A2},
|
||||||
{pathC2A2, pathC3A3},
|
{pathC2A2, pathC3A3},
|
||||||
{pathC1A1, pathC4A4},
|
{pathC1A1, pathC4A4},
|
||||||
|
@ -993,14 +993,14 @@ func TestFilterRoutesV2(t *testing.T) {
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{
|
fromLockedAmount: map[uint64]*hexutil.Big{
|
||||||
1: &amount1,
|
1: &amount1,
|
||||||
},
|
},
|
||||||
expectedRoutes: [][]*PathV2{
|
expectedRoutes: [][]*Path{
|
||||||
{pathC1A1, pathC2A2},
|
{pathC1A1, pathC2A2},
|
||||||
{pathC1A1, pathC2A1, pathC3A1},
|
{pathC1A1, pathC2A1, pathC3A1},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "All invalid routes",
|
name: "All invalid routes",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{pathC2A2, pathC3A3},
|
{pathC2A2, pathC3A3},
|
||||||
{pathC4A4, pathC5A5},
|
{pathC4A4, pathC5A5},
|
||||||
},
|
},
|
||||||
|
@ -1008,11 +1008,11 @@ func TestFilterRoutesV2(t *testing.T) {
|
||||||
fromLockedAmount: map[uint64]*hexutil.Big{
|
fromLockedAmount: map[uint64]*hexutil.Big{
|
||||||
1: &amount1,
|
1: &amount1,
|
||||||
},
|
},
|
||||||
expectedRoutes: [][]*PathV2{},
|
expectedRoutes: [][]*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Single valid route",
|
name: "Single valid route",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{pathC1A1, pathC3A3},
|
{pathC1A1, pathC3A3},
|
||||||
{pathC2A2, pathC3A3},
|
{pathC2A2, pathC3A3},
|
||||||
},
|
},
|
||||||
|
@ -1021,13 +1021,13 @@ func TestFilterRoutesV2(t *testing.T) {
|
||||||
1: &amount1,
|
1: &amount1,
|
||||||
3: &amount3,
|
3: &amount3,
|
||||||
},
|
},
|
||||||
expectedRoutes: [][]*PathV2{
|
expectedRoutes: [][]*Path{
|
||||||
{pathC1A1, pathC3A3},
|
{pathC1A1, pathC3A3},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Route with mixed valid and invalid paths I",
|
name: "Route with mixed valid and invalid paths I",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{pathC1A1, pathC2A2, pathC3A3},
|
{pathC1A1, pathC2A2, pathC3A3},
|
||||||
},
|
},
|
||||||
amountIn: big.NewInt(300),
|
amountIn: big.NewInt(300),
|
||||||
|
@ -1035,11 +1035,11 @@ func TestFilterRoutesV2(t *testing.T) {
|
||||||
1: &amount1,
|
1: &amount1,
|
||||||
2: &amount0, // This path should be filtered out due to being excluded via a zero amount
|
2: &amount0, // This path should be filtered out due to being excluded via a zero amount
|
||||||
},
|
},
|
||||||
expectedRoutes: [][]*PathV2{},
|
expectedRoutes: [][]*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Route with mixed valid and invalid paths II",
|
name: "Route with mixed valid and invalid paths II",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{pathC1A1, pathC3A3},
|
{pathC1A1, pathC3A3},
|
||||||
},
|
},
|
||||||
amountIn: big.NewInt(400),
|
amountIn: big.NewInt(400),
|
||||||
|
@ -1047,13 +1047,13 @@ func TestFilterRoutesV2(t *testing.T) {
|
||||||
1: &amount1,
|
1: &amount1,
|
||||||
2: &amount0, // This path should be filtered out due to being excluded via a zero amount, 0 value locked means this chain is disabled
|
2: &amount0, // This path should be filtered out due to being excluded via a zero amount, 0 value locked means this chain is disabled
|
||||||
},
|
},
|
||||||
expectedRoutes: [][]*PathV2{
|
expectedRoutes: [][]*Path{
|
||||||
{pathC1A1, pathC3A3},
|
{pathC1A1, pathC3A3},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Route with mixed valid and invalid paths III",
|
name: "Route with mixed valid and invalid paths III",
|
||||||
routes: [][]*PathV2{
|
routes: [][]*Path{
|
||||||
{pathC1A1, pathC3A3},
|
{pathC1A1, pathC3A3},
|
||||||
{pathC1A1, pathC3A2, pathC4A1},
|
{pathC1A1, pathC3A2, pathC4A1},
|
||||||
},
|
},
|
||||||
|
@ -1062,7 +1062,7 @@ func TestFilterRoutesV2(t *testing.T) {
|
||||||
1: &amount1,
|
1: &amount1,
|
||||||
2: &amount0, // This path should be filtered out due to being excluded via a zero amount, 0 value locked means this chain is disabled
|
2: &amount0, // This path should be filtered out due to being excluded via a zero amount, 0 value locked means this chain is disabled
|
||||||
},
|
},
|
||||||
expectedRoutes: [][]*PathV2{
|
expectedRoutes: [][]*Path{
|
||||||
{pathC1A1, pathC3A3},
|
{pathC1A1, pathC3A3},
|
||||||
{pathC1A1, pathC3A2, pathC4A1},
|
{pathC1A1, pathC3A2, pathC4A1},
|
||||||
},
|
},
|
||||||
|
@ -1072,7 +1072,7 @@ func TestFilterRoutesV2(t *testing.T) {
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
t.Logf("Original Routes: %+v\n", tt.routes)
|
t.Logf("Original Routes: %+v\n", tt.routes)
|
||||||
filteredRoutes := filterRoutesV2(tt.routes, tt.amountIn, tt.fromLockedAmount)
|
filteredRoutes := filterRoutes(tt.routes, tt.amountIn, tt.fromLockedAmount)
|
||||||
t.Logf("Filtered Routes: %+v\n", filteredRoutes)
|
t.Logf("Filtered Routes: %+v\n", filteredRoutes)
|
||||||
assert.Equal(t, tt.expectedRoutes, filteredRoutes)
|
assert.Equal(t, tt.expectedRoutes, filteredRoutes)
|
||||||
})
|
})
|
||||||
|
|
|
@ -101,7 +101,7 @@ func makeBalanceKey(chainID uint64, symbol string) string {
|
||||||
return fmt.Sprintf("%d-%s", chainID, symbol)
|
return fmt.Sprintf("%d-%s", chainID, symbol)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PathV2 struct {
|
type Path struct {
|
||||||
ProcessorName string
|
ProcessorName string
|
||||||
FromChain *params.Network // Source chain
|
FromChain *params.Network // Source chain
|
||||||
ToChain *params.Network // Destination chain
|
ToChain *params.Network // Destination chain
|
||||||
|
@ -147,32 +147,32 @@ type ProcessorError struct {
|
||||||
Error error
|
Error error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PathV2) Equal(o *PathV2) bool {
|
func (p *Path) Equal(o *Path) bool {
|
||||||
return p.FromChain.ChainID == o.FromChain.ChainID && p.ToChain.ChainID == o.ToChain.ChainID
|
return p.FromChain.ChainID == o.FromChain.ChainID && p.ToChain.ChainID == o.ToChain.ChainID
|
||||||
}
|
}
|
||||||
|
|
||||||
type SuggestedRoutesV2 struct {
|
type SuggestedRoutes struct {
|
||||||
Uuid string
|
Uuid string
|
||||||
Best []*PathV2
|
Best []*Path
|
||||||
Candidates []*PathV2
|
Candidates []*Path
|
||||||
TokenPrice float64
|
TokenPrice float64
|
||||||
NativeChainTokenPrice float64
|
NativeChainTokenPrice float64
|
||||||
}
|
}
|
||||||
|
|
||||||
type SuggestedRoutesV2Response struct {
|
type SuggestedRoutesResponse struct {
|
||||||
Uuid string `json:"Uuid"`
|
Uuid string `json:"Uuid"`
|
||||||
Best []*PathV2 `json:"Best,omitempty"`
|
Best []*Path `json:"Best,omitempty"`
|
||||||
Candidates []*PathV2 `json:"Candidates,omitempty"`
|
Candidates []*Path `json:"Candidates,omitempty"`
|
||||||
TokenPrice *float64 `json:"TokenPrice,omitempty"`
|
TokenPrice *float64 `json:"TokenPrice,omitempty"`
|
||||||
NativeChainTokenPrice *float64 `json:"NativeChainTokenPrice,omitempty"`
|
NativeChainTokenPrice *float64 `json:"NativeChainTokenPrice,omitempty"`
|
||||||
ErrorResponse *errors.ErrorResponse `json:"ErrorResponse,omitempty"`
|
ErrorResponse *errors.ErrorResponse `json:"ErrorResponse,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GraphV2 []*NodeV2
|
type Graph []*Node
|
||||||
|
|
||||||
type NodeV2 struct {
|
type Node struct {
|
||||||
Path *PathV2
|
Path *Path
|
||||||
Children GraphV2
|
Children Graph
|
||||||
}
|
}
|
||||||
|
|
||||||
type Router struct {
|
type Router struct {
|
||||||
|
@ -222,15 +222,15 @@ func (r *Router) GetPathProcessors() map[string]pathprocessor.PathProcessor {
|
||||||
return r.pathProcessors
|
return r.pathProcessors
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSuggestedRoutesV2(
|
func newSuggestedRoutes(
|
||||||
uuid string,
|
uuid string,
|
||||||
amountIn *big.Int,
|
amountIn *big.Int,
|
||||||
candidates []*PathV2,
|
candidates []*Path,
|
||||||
fromLockedAmount map[uint64]*hexutil.Big,
|
fromLockedAmount map[uint64]*hexutil.Big,
|
||||||
tokenPrice float64,
|
tokenPrice float64,
|
||||||
nativeChainTokenPrice float64,
|
nativeChainTokenPrice float64,
|
||||||
) (*SuggestedRoutesV2, [][]*PathV2) {
|
) (*SuggestedRoutes, [][]*Path) {
|
||||||
suggestedRoutes := &SuggestedRoutesV2{
|
suggestedRoutes := &SuggestedRoutes{
|
||||||
Uuid: uuid,
|
Uuid: uuid,
|
||||||
Candidates: candidates,
|
Candidates: candidates,
|
||||||
TokenPrice: tokenPrice,
|
TokenPrice: tokenPrice,
|
||||||
|
@ -240,12 +240,12 @@ func newSuggestedRoutesV2(
|
||||||
return suggestedRoutes, nil
|
return suggestedRoutes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
node := &NodeV2{
|
node := &Node{
|
||||||
Path: nil,
|
Path: nil,
|
||||||
Children: buildGraphV2(amountIn, candidates, 0, []uint64{}),
|
Children: buildGraph(amountIn, candidates, 0, []uint64{}),
|
||||||
}
|
}
|
||||||
allRoutes := node.buildAllRoutesV2()
|
allRoutes := node.buildAllRoutes()
|
||||||
allRoutes = filterRoutesV2(allRoutes, amountIn, fromLockedAmount)
|
allRoutes = filterRoutes(allRoutes, amountIn, fromLockedAmount)
|
||||||
|
|
||||||
if len(allRoutes) > 0 {
|
if len(allRoutes) > 0 {
|
||||||
sort.Slice(allRoutes, func(i, j int) bool {
|
sort.Slice(allRoutes, func(i, j int) bool {
|
||||||
|
@ -258,12 +258,12 @@ func newSuggestedRoutesV2(
|
||||||
return suggestedRoutes, allRoutes
|
return suggestedRoutes, allRoutes
|
||||||
}
|
}
|
||||||
|
|
||||||
func newNodeV2(path *PathV2) *NodeV2 {
|
func newNode(path *Path) *Node {
|
||||||
return &NodeV2{Path: path, Children: make(GraphV2, 0)}
|
return &Node{Path: path, Children: make(Graph, 0)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildGraphV2(AmountIn *big.Int, routes []*PathV2, level int, sourceChainIDs []uint64) GraphV2 {
|
func buildGraph(AmountIn *big.Int, routes []*Path, level int, sourceChainIDs []uint64) Graph {
|
||||||
graph := make(GraphV2, 0)
|
graph := make(Graph, 0)
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
found := false
|
found := false
|
||||||
for _, chainID := range sourceChainIDs {
|
for _, chainID := range sourceChainIDs {
|
||||||
|
@ -275,9 +275,9 @@ func buildGraphV2(AmountIn *big.Int, routes []*PathV2, level int, sourceChainIDs
|
||||||
if found {
|
if found {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
node := newNodeV2(route)
|
node := newNode(route)
|
||||||
|
|
||||||
newRoutes := make([]*PathV2, 0)
|
newRoutes := make([]*Path, 0)
|
||||||
for _, r := range routes {
|
for _, r := range routes {
|
||||||
if route.Equal(r) {
|
if route.Equal(r) {
|
||||||
continue
|
continue
|
||||||
|
@ -290,7 +290,7 @@ func buildGraphV2(AmountIn *big.Int, routes []*PathV2, level int, sourceChainIDs
|
||||||
newSourceChainIDs := make([]uint64, len(sourceChainIDs))
|
newSourceChainIDs := make([]uint64, len(sourceChainIDs))
|
||||||
copy(newSourceChainIDs, sourceChainIDs)
|
copy(newSourceChainIDs, sourceChainIDs)
|
||||||
newSourceChainIDs = append(newSourceChainIDs, route.FromChain.ChainID)
|
newSourceChainIDs = append(newSourceChainIDs, route.FromChain.ChainID)
|
||||||
node.Children = buildGraphV2(newAmountIn, newRoutes, level+1, newSourceChainIDs)
|
node.Children = buildGraph(newAmountIn, newRoutes, level+1, newSourceChainIDs)
|
||||||
|
|
||||||
if len(node.Children) == 0 {
|
if len(node.Children) == 0 {
|
||||||
continue
|
continue
|
||||||
|
@ -303,18 +303,18 @@ func buildGraphV2(AmountIn *big.Int, routes []*PathV2, level int, sourceChainIDs
|
||||||
return graph
|
return graph
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n NodeV2) buildAllRoutesV2() [][]*PathV2 {
|
func (n Node) buildAllRoutes() [][]*Path {
|
||||||
res := make([][]*PathV2, 0)
|
res := make([][]*Path, 0)
|
||||||
|
|
||||||
if len(n.Children) == 0 && n.Path != nil {
|
if len(n.Children) == 0 && n.Path != nil {
|
||||||
res = append(res, []*PathV2{n.Path})
|
res = append(res, []*Path{n.Path})
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, node := range n.Children {
|
for _, node := range n.Children {
|
||||||
for _, route := range node.buildAllRoutesV2() {
|
for _, route := range node.buildAllRoutes() {
|
||||||
extendedRoute := route
|
extendedRoute := route
|
||||||
if n.Path != nil {
|
if n.Path != nil {
|
||||||
extendedRoute = append([]*PathV2{n.Path}, route...)
|
extendedRoute = append([]*Path{n.Path}, route...)
|
||||||
}
|
}
|
||||||
res = append(res, extendedRoute)
|
res = append(res, extendedRoute)
|
||||||
}
|
}
|
||||||
|
@ -323,8 +323,8 @@ func (n NodeV2) buildAllRoutesV2() [][]*PathV2 {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func findBestV2(routes [][]*PathV2, tokenPrice float64, nativeTokenPrice float64) []*PathV2 {
|
func findBest(routes [][]*Path, tokenPrice float64, nativeTokenPrice float64) []*Path {
|
||||||
var best []*PathV2
|
var best []*Path
|
||||||
bestCost := big.NewFloat(math.Inf(1))
|
bestCost := big.NewFloat(math.Inf(1))
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
currentCost := big.NewFloat(0)
|
currentCost := big.NewFloat(0)
|
||||||
|
@ -503,11 +503,11 @@ func validateFromLockedAmount(input *RouteInputParams) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) SuggestedRoutesV2Async(input *RouteInputParams) {
|
func (r *Router) SuggestedRoutesAsync(input *RouteInputParams) {
|
||||||
r.scheduler.Enqueue(routerTask, func(ctx context.Context) (interface{}, error) {
|
r.scheduler.Enqueue(routerTask, func(ctx context.Context) (interface{}, error) {
|
||||||
return r.SuggestedRoutesV2(ctx, input)
|
return r.SuggestedRoutes(ctx, input)
|
||||||
}, func(result interface{}, taskType async.TaskType, err error) {
|
}, func(result interface{}, taskType async.TaskType, err error) {
|
||||||
routesResponse := SuggestedRoutesV2Response{
|
routesResponse := SuggestedRoutesResponse{
|
||||||
Uuid: input.Uuid,
|
Uuid: input.Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -516,7 +516,7 @@ func (r *Router) SuggestedRoutesV2Async(input *RouteInputParams) {
|
||||||
routesResponse.ErrorResponse = errorResponse.(*errors.ErrorResponse)
|
routesResponse.ErrorResponse = errorResponse.(*errors.ErrorResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
if suggestedRoutes, ok := result.(*SuggestedRoutesV2); ok && suggestedRoutes != nil {
|
if suggestedRoutes, ok := result.(*SuggestedRoutes); ok && suggestedRoutes != nil {
|
||||||
routesResponse.Best = suggestedRoutes.Best
|
routesResponse.Best = suggestedRoutes.Best
|
||||||
routesResponse.Candidates = suggestedRoutes.Candidates
|
routesResponse.Candidates = suggestedRoutes.Candidates
|
||||||
routesResponse.TokenPrice = &suggestedRoutes.TokenPrice
|
routesResponse.TokenPrice = &suggestedRoutes.TokenPrice
|
||||||
|
@ -527,11 +527,11 @@ func (r *Router) SuggestedRoutesV2Async(input *RouteInputParams) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) StopSuggestedRoutesV2AsyncCalcualtion() {
|
func (r *Router) StopSuggestedRoutesAsyncCalculation() {
|
||||||
r.scheduler.Stop()
|
r.scheduler.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) SuggestedRoutesV2(ctx context.Context, input *RouteInputParams) (*SuggestedRoutesV2, error) {
|
func (r *Router) SuggestedRoutes(ctx context.Context, input *RouteInputParams) (*SuggestedRoutes, error) {
|
||||||
testnetMode, err := r.rpcClient.NetworkManager.GetTestNetworksEnabled()
|
testnetMode, err := r.rpcClient.NetworkManager.GetTestNetworksEnabled()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.CreateErrorResponseFromError(err)
|
return nil, errors.CreateErrorResponseFromError(err)
|
||||||
|
@ -860,7 +860,7 @@ func (r *Router) getSelectedChains(input *RouteInputParams) (selectedFromChains
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) resolveCandidates(ctx context.Context, input *RouteInputParams, selectedFromChains []*params.Network,
|
func (r *Router) resolveCandidates(ctx context.Context, input *RouteInputParams, selectedFromChains []*params.Network,
|
||||||
selectedToChains []*params.Network, balanceMap map[string]*big.Int) (candidates []*PathV2, processorErrors []*ProcessorError, err error) {
|
selectedToChains []*params.Network, balanceMap map[string]*big.Int) (candidates []*Path, processorErrors []*ProcessorError, err error) {
|
||||||
var (
|
var (
|
||||||
testsMode = input.testsMode && input.testParams != nil
|
testsMode = input.testsMode && input.testParams != nil
|
||||||
group = async.NewAtomicGroup(ctx)
|
group = async.NewAtomicGroup(ctx)
|
||||||
|
@ -873,7 +873,7 @@ func (r *Router) resolveCandidates(ctx context.Context, input *RouteInputParams,
|
||||||
}
|
}
|
||||||
|
|
||||||
appendProcessorErrorFn := func(processorName string, sendType SendType, fromChainID uint64, toChainID uint64, amount *big.Int, err error) {
|
appendProcessorErrorFn := func(processorName string, sendType SendType, fromChainID uint64, toChainID uint64, amount *big.Int, err error) {
|
||||||
log.Error("routerv2.resolveCandidates error", "processor", processorName, "sendType", sendType, "fromChainId: ", fromChainID, "toChainId", toChainID, "amount", amount, "err", err)
|
log.Error("router.resolveCandidates error", "processor", processorName, "sendType", sendType, "fromChainId: ", fromChainID, "toChainId", toChainID, "amount", amount, "err", err)
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
processorErrors = append(processorErrors, &ProcessorError{
|
processorErrors = append(processorErrors, &ProcessorError{
|
||||||
|
@ -882,7 +882,7 @@ func (r *Router) resolveCandidates(ctx context.Context, input *RouteInputParams,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
appendPathFn := func(path *PathV2) {
|
appendPathFn := func(path *Path) {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
candidates = append(candidates, path)
|
candidates = append(candidates, path)
|
||||||
|
@ -1080,7 +1080,7 @@ func (r *Router) resolveCandidates(ctx context.Context, input *RouteInputParams,
|
||||||
requiredNativeBalance.Add(requiredNativeBalance, ethTotalFees)
|
requiredNativeBalance.Add(requiredNativeBalance, ethTotalFees)
|
||||||
}
|
}
|
||||||
|
|
||||||
appendPathFn(&PathV2{
|
appendPathFn(&Path{
|
||||||
ProcessorName: pProcessor.Name(),
|
ProcessorName: pProcessor.Name(),
|
||||||
FromChain: network,
|
FromChain: network,
|
||||||
ToChain: dest,
|
ToChain: dest,
|
||||||
|
@ -1137,7 +1137,7 @@ func (r *Router) resolveCandidates(ctx context.Context, input *RouteInputParams,
|
||||||
return candidates, processorErrors, nil
|
return candidates, processorErrors, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) checkBalancesForTheBestRoute(ctx context.Context, bestRoute []*PathV2, balanceMap map[string]*big.Int) (hasPositiveBalance bool, err error) {
|
func (r *Router) checkBalancesForTheBestRoute(ctx context.Context, bestRoute []*Path, balanceMap map[string]*big.Int) (hasPositiveBalance bool, err error) {
|
||||||
balanceMapCopy := copyMapGeneric(balanceMap, func(v interface{}) interface{} {
|
balanceMapCopy := copyMapGeneric(balanceMap, func(v interface{}) interface{} {
|
||||||
return new(big.Int).Set(v.(*big.Int))
|
return new(big.Int).Set(v.(*big.Int))
|
||||||
}).(map[string]*big.Int)
|
}).(map[string]*big.Int)
|
||||||
|
@ -1193,7 +1193,7 @@ func (r *Router) checkBalancesForTheBestRoute(ctx context.Context, bestRoute []*
|
||||||
return hasPositiveBalance, nil
|
return hasPositiveBalance, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeBestRouteFromAllRouters(allRoutes [][]*PathV2, best []*PathV2) [][]*PathV2 {
|
func removeBestRouteFromAllRouters(allRoutes [][]*Path, best []*Path) [][]*Path {
|
||||||
for i := len(allRoutes) - 1; i >= 0; i-- {
|
for i := len(allRoutes) - 1; i >= 0; i-- {
|
||||||
route := allRoutes[i]
|
route := allRoutes[i]
|
||||||
routeFound := true
|
routeFound := true
|
||||||
|
@ -1234,7 +1234,7 @@ func getChainPriority(chainID uint64) int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRoutePriority(route []*PathV2) int {
|
func getRoutePriority(route []*Path) int {
|
||||||
priority := 0
|
priority := 0
|
||||||
for _, path := range route {
|
for _, path := range route {
|
||||||
priority += getChainPriority(path.FromChain.ChainID)
|
priority += getChainPriority(path.FromChain.ChainID)
|
||||||
|
@ -1242,7 +1242,7 @@ func getRoutePriority(route []*PathV2) int {
|
||||||
return priority
|
return priority
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) resolveRoutes(ctx context.Context, input *RouteInputParams, candidates []*PathV2, balanceMap map[string]*big.Int) (suggestedRoutes *SuggestedRoutesV2, err error) {
|
func (r *Router) resolveRoutes(ctx context.Context, input *RouteInputParams, candidates []*Path, balanceMap map[string]*big.Int) (suggestedRoutes *SuggestedRoutes, err error) {
|
||||||
var prices map[string]float64
|
var prices map[string]float64
|
||||||
if input.testsMode {
|
if input.testsMode {
|
||||||
prices = input.testParams.tokenPrices
|
prices = input.testParams.tokenPrices
|
||||||
|
@ -1256,8 +1256,8 @@ func (r *Router) resolveRoutes(ctx context.Context, input *RouteInputParams, can
|
||||||
tokenPrice := prices[input.TokenID]
|
tokenPrice := prices[input.TokenID]
|
||||||
nativeTokenPrice := prices[pathprocessor.EthSymbol]
|
nativeTokenPrice := prices[pathprocessor.EthSymbol]
|
||||||
|
|
||||||
var allRoutes [][]*PathV2
|
var allRoutes [][]*Path
|
||||||
suggestedRoutes, allRoutes = newSuggestedRoutesV2(input.Uuid, input.AmountIn.ToInt(), candidates, input.FromLockedAmount, tokenPrice, nativeTokenPrice)
|
suggestedRoutes, allRoutes = newSuggestedRoutes(input.Uuid, input.AmountIn.ToInt(), candidates, input.FromLockedAmount, tokenPrice, nativeTokenPrice)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if suggestedRoutes.Best != nil && len(suggestedRoutes.Best) > 0 {
|
if suggestedRoutes.Best != nil && len(suggestedRoutes.Best) > 0 {
|
||||||
|
@ -1270,13 +1270,13 @@ func (r *Router) resolveRoutes(ctx context.Context, input *RouteInputParams, can
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
bestRoute []*PathV2
|
bestRoute []*Path
|
||||||
lastBestRouteWithPositiveBalance []*PathV2
|
lastBestRouteWithPositiveBalance []*Path
|
||||||
lastBestRouteErr error
|
lastBestRouteErr error
|
||||||
)
|
)
|
||||||
|
|
||||||
for len(allRoutes) > 0 {
|
for len(allRoutes) > 0 {
|
||||||
bestRoute = findBestV2(allRoutes, tokenPrice, nativeTokenPrice)
|
bestRoute = findBest(allRoutes, tokenPrice, nativeTokenPrice)
|
||||||
var hasPositiveBalance bool
|
var hasPositiveBalance bool
|
||||||
hasPositiveBalance, err = r.checkBalancesForTheBestRoute(ctx, bestRoute, balanceMap)
|
hasPositiveBalance, err = r.checkBalancesForTheBestRoute(ctx, bestRoute, balanceMap)
|
||||||
|
|
|
@ -58,7 +58,7 @@ func amountOptionsMapsEqual(map1, map2 map[uint64][]amountOption) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertPathsEqual(t *testing.T, expected, actual []*PathV2) {
|
func assertPathsEqual(t *testing.T, expected, actual []*Path) {
|
||||||
assert.Equal(t, len(expected), len(actual))
|
assert.Equal(t, len(expected), len(actual))
|
||||||
if len(expected) == 0 {
|
if len(expected) == 0 {
|
||||||
return
|
return
|
||||||
|
@ -124,19 +124,19 @@ func setupRouter(t *testing.T) (*Router, func()) {
|
||||||
return router, cleanTmpDb
|
return router, cleanTmpDb
|
||||||
}
|
}
|
||||||
|
|
||||||
type suggestedRoutesV2ResponseEnvelope struct {
|
type suggestedRoutesResponseEnvelope struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Routes SuggestedRoutesV2Response `json:"event"`
|
Routes SuggestedRoutesResponse `json:"event"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupSignalHandler(t *testing.T) (chan SuggestedRoutesV2Response, func()) {
|
func setupSignalHandler(t *testing.T) (chan SuggestedRoutesResponse, func()) {
|
||||||
suggestedRoutesCh := make(chan SuggestedRoutesV2Response)
|
suggestedRoutesCh := make(chan SuggestedRoutesResponse)
|
||||||
signalHandler := signal.MobileSignalHandler(func(data []byte) {
|
signalHandler := signal.MobileSignalHandler(func(data []byte) {
|
||||||
var envelope signal.Envelope
|
var envelope signal.Envelope
|
||||||
err := json.Unmarshal(data, &envelope)
|
err := json.Unmarshal(data, &envelope)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
if envelope.Type == string(signal.SuggestedRoutes) {
|
if envelope.Type == string(signal.SuggestedRoutes) {
|
||||||
var response suggestedRoutesV2ResponseEnvelope
|
var response suggestedRoutesResponseEnvelope
|
||||||
err := json.Unmarshal(data, &response)
|
err := json.Unmarshal(data, &response)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ func setupSignalHandler(t *testing.T) (chan SuggestedRoutesV2Response, func()) {
|
||||||
return suggestedRoutesCh, closeFn
|
return suggestedRoutesCh, closeFn
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRouterV2(t *testing.T) {
|
func TestRouter(t *testing.T) {
|
||||||
router, cleanTmpDb := setupRouter(t)
|
router, cleanTmpDb := setupRouter(t)
|
||||||
defer cleanTmpDb()
|
defer cleanTmpDb()
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ func TestRouterV2(t *testing.T) {
|
||||||
// Test blocking endpoints
|
// Test blocking endpoints
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
routes, err := router.SuggestedRoutesV2(context.Background(), tt.input)
|
routes, err := router.SuggestedRoutes(context.Background(), tt.input)
|
||||||
|
|
||||||
if tt.expectedError != nil {
|
if tt.expectedError != nil {
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
@ -184,7 +184,7 @@ func TestRouterV2(t *testing.T) {
|
||||||
|
|
||||||
// Test async endpoints
|
// Test async endpoints
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
router.SuggestedRoutesV2Async(tt.input)
|
router.SuggestedRoutesAsync(tt.input)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case asyncRoutes := <-suggestedRoutesCh:
|
case asyncRoutes := <-suggestedRoutesCh:
|
||||||
|
@ -198,7 +198,7 @@ func TestRouterV2(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNoBalanceForTheBestRouteRouterV2(t *testing.T) {
|
func TestNoBalanceForTheBestRouteRouter(t *testing.T) {
|
||||||
router, cleanTmpDb := setupRouter(t)
|
router, cleanTmpDb := setupRouter(t)
|
||||||
defer cleanTmpDb()
|
defer cleanTmpDb()
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@ func TestNoBalanceForTheBestRouteRouterV2(t *testing.T) {
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
||||||
routes, err := router.SuggestedRoutesV2(context.Background(), tt.input)
|
routes, err := router.SuggestedRoutes(context.Background(), tt.input)
|
||||||
|
|
||||||
if tt.expectedError != nil {
|
if tt.expectedError != nil {
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
@ -236,7 +236,7 @@ func TestNoBalanceForTheBestRouteRouterV2(t *testing.T) {
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
||||||
router.SuggestedRoutesV2Async(tt.input)
|
router.SuggestedRoutesAsync(tt.input)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case asyncRoutes := <-suggestedRoutesCh:
|
case asyncRoutes := <-suggestedRoutesCh:
|
|
@ -202,7 +202,7 @@ var defaultNetworks = []params.Network{
|
||||||
type normalTestParams struct {
|
type normalTestParams struct {
|
||||||
name string
|
name string
|
||||||
input *RouteInputParams
|
input *RouteInputParams
|
||||||
expectedCandidates []*PathV2
|
expectedCandidates []*Path
|
||||||
expectedError *errors.ErrorResponse
|
expectedError *errors.ErrorResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
Code: errors.GenericErrorCode,
|
Code: errors.GenericErrorCode,
|
||||||
Details: fmt.Sprintf("failed with 50000000 gas: insufficient funds for gas * price + value: address %s", common.HexToAddress("0x1")),
|
Details: fmt.Sprintf("failed with 50000000 gas: insufficient funds for gas * price + value: address %s", common.HexToAddress("0x1")),
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{},
|
expectedCandidates: []*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ETH transfer - No Specific FromChain - No Specific ToChain - 0 AmountIn",
|
name: "ETH transfer - No Specific FromChain - No Specific ToChain - 0 AmountIn",
|
||||||
|
@ -275,7 +275,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &mainnet,
|
FromChain: &mainnet,
|
||||||
|
@ -323,7 +323,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &mainnet,
|
FromChain: &mainnet,
|
||||||
|
@ -409,7 +409,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &mainnet,
|
FromChain: &mainnet,
|
||||||
|
@ -459,7 +459,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &optimism,
|
FromChain: &optimism,
|
||||||
|
@ -528,7 +528,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &arbitrum,
|
FromChain: &arbitrum,
|
||||||
|
@ -578,7 +578,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &optimism,
|
FromChain: &optimism,
|
||||||
|
@ -647,7 +647,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &arbitrum,
|
FromChain: &arbitrum,
|
||||||
|
@ -686,7 +686,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
||||||
FromChain: &arbitrum,
|
FromChain: &arbitrum,
|
||||||
|
@ -725,7 +725,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &arbitrum,
|
FromChain: &arbitrum,
|
||||||
|
@ -764,7 +764,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &mainnet,
|
FromChain: &mainnet,
|
||||||
|
@ -821,7 +821,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
||||||
FromChain: &arbitrum,
|
FromChain: &arbitrum,
|
||||||
|
@ -862,7 +862,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedError: ErrNoBestRouteFound,
|
expectedError: ErrNoBestRouteFound,
|
||||||
expectedCandidates: []*PathV2{},
|
expectedCandidates: []*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ETH transfer - No Specific FromChain - No Specific ToChain - Single Chain LockedAmount",
|
name: "ETH transfer - No Specific FromChain - No Specific ToChain - Single Chain LockedAmount",
|
||||||
|
@ -895,7 +895,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &mainnet,
|
FromChain: &mainnet,
|
||||||
|
@ -994,7 +994,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &optimism,
|
FromChain: &optimism,
|
||||||
|
@ -1050,7 +1050,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &mainnet,
|
FromChain: &mainnet,
|
||||||
|
@ -1149,7 +1149,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &mainnet,
|
FromChain: &mainnet,
|
||||||
|
@ -1249,7 +1249,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedError: ErrLockedAmountLessThanSendAmountAllNetworks,
|
expectedError: ErrLockedAmountLessThanSendAmountAllNetworks,
|
||||||
expectedCandidates: []*PathV2{},
|
expectedCandidates: []*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ETH transfer - No Specific FromChain - No Specific ToChain - LockedAmount exceeds sending amount",
|
name: "ETH transfer - No Specific FromChain - No Specific ToChain - LockedAmount exceeds sending amount",
|
||||||
|
@ -1284,7 +1284,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedError: ErrLockedAmountExceedsTotalSendAmount,
|
expectedError: ErrLockedAmountExceedsTotalSendAmount,
|
||||||
expectedCandidates: []*PathV2{},
|
expectedCandidates: []*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ERC20 transfer - No Specific FromChain - No Specific ToChain",
|
name: "ERC20 transfer - No Specific FromChain - No Specific ToChain",
|
||||||
|
@ -1314,7 +1314,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &mainnet,
|
FromChain: &mainnet,
|
||||||
|
@ -1400,7 +1400,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &mainnet,
|
FromChain: &mainnet,
|
||||||
|
@ -1450,7 +1450,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &optimism,
|
FromChain: &optimism,
|
||||||
|
@ -1518,7 +1518,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &arbitrum,
|
FromChain: &arbitrum,
|
||||||
|
@ -1568,7 +1568,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &optimism,
|
FromChain: &optimism,
|
||||||
|
@ -1637,7 +1637,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &arbitrum,
|
FromChain: &arbitrum,
|
||||||
|
@ -1676,7 +1676,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
||||||
FromChain: &arbitrum,
|
FromChain: &arbitrum,
|
||||||
|
@ -1715,7 +1715,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &arbitrum,
|
FromChain: &arbitrum,
|
||||||
|
@ -1754,7 +1754,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &mainnet,
|
FromChain: &mainnet,
|
||||||
|
@ -1811,7 +1811,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
||||||
FromChain: &arbitrum,
|
FromChain: &arbitrum,
|
||||||
|
@ -1851,7 +1851,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedError: ErrNoBestRouteFound,
|
expectedError: ErrNoBestRouteFound,
|
||||||
expectedCandidates: []*PathV2{},
|
expectedCandidates: []*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ERC20 transfer - All FromChains - No Locked Amount - Enough Token Balance Across All Chains",
|
name: "ERC20 transfer - All FromChains - No Locked Amount - Enough Token Balance Across All Chains",
|
||||||
|
@ -1881,7 +1881,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &mainnet,
|
FromChain: &mainnet,
|
||||||
|
@ -2080,7 +2080,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
||||||
FromChain: &mainnet,
|
FromChain: &mainnet,
|
||||||
|
@ -2148,7 +2148,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
||||||
FromChain: &optimism,
|
FromChain: &optimism,
|
||||||
|
@ -2192,7 +2192,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
||||||
FromChain: &mainnet,
|
FromChain: &mainnet,
|
||||||
|
@ -2248,7 +2248,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
||||||
FromChain: &arbitrum,
|
FromChain: &arbitrum,
|
||||||
|
@ -2292,7 +2292,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
||||||
FromChain: &optimism,
|
FromChain: &optimism,
|
||||||
|
@ -2350,7 +2350,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedError: ErrNoBestRouteFound,
|
expectedError: ErrNoBestRouteFound,
|
||||||
expectedCandidates: []*PathV2{},
|
expectedCandidates: []*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Bridge - Specific Single FromChain - Specific Single ToChain - Different Chains",
|
name: "Bridge - Specific Single FromChain - Specific Single ToChain - Different Chains",
|
||||||
|
@ -2382,7 +2382,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
||||||
FromChain: &arbitrum,
|
FromChain: &arbitrum,
|
||||||
|
@ -2422,7 +2422,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedError: ErrNoBestRouteFound,
|
expectedError: ErrNoBestRouteFound,
|
||||||
expectedCandidates: []*PathV2{},
|
expectedCandidates: []*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Bridge - Specific Multiple FromChain - Specific Multiple ToChain - Multiple Common Chains",
|
name: "Bridge - Specific Multiple FromChain - Specific Multiple ToChain - Multiple Common Chains",
|
||||||
|
@ -2454,7 +2454,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
||||||
FromChain: &mainnet,
|
FromChain: &mainnet,
|
||||||
|
@ -2499,7 +2499,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
||||||
FromChain: &arbitrum,
|
FromChain: &arbitrum,
|
||||||
|
@ -2539,7 +2539,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedError: ErrNoBestRouteFound,
|
expectedError: ErrNoBestRouteFound,
|
||||||
expectedCandidates: []*PathV2{},
|
expectedCandidates: []*Path{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ETH transfer - Not Enough Native Balance",
|
name: "ETH transfer - Not Enough Native Balance",
|
||||||
|
@ -2574,7 +2574,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
Code: ErrNotEnoughNativeBalance.Code,
|
Code: ErrNotEnoughNativeBalance.Code,
|
||||||
Details: fmt.Sprintf(ErrNotEnoughNativeBalance.Details, pathprocessor.EthSymbol, walletCommon.EthereumMainnet),
|
Details: fmt.Sprintf(ErrNotEnoughNativeBalance.Details, pathprocessor.EthSymbol, walletCommon.EthereumMainnet),
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
||||||
FromChain: &mainnet,
|
FromChain: &mainnet,
|
||||||
|
@ -2616,7 +2616,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
Code: ErrNotEnoughTokenBalance.Code,
|
Code: ErrNotEnoughTokenBalance.Code,
|
||||||
Details: fmt.Sprintf(ErrNotEnoughTokenBalance.Details, pathprocessor.UsdcSymbol, walletCommon.EthereumMainnet),
|
Details: fmt.Sprintf(ErrNotEnoughTokenBalance.Details, pathprocessor.UsdcSymbol, walletCommon.EthereumMainnet),
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
||||||
FromChain: &mainnet,
|
FromChain: &mainnet,
|
||||||
|
@ -2656,7 +2656,7 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedError: ErrLowAmountInForHopBridge,
|
expectedError: ErrLowAmountInForHopBridge,
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
||||||
FromChain: &arbitrum,
|
FromChain: &arbitrum,
|
||||||
|
@ -2671,8 +2671,8 @@ func getNormalTestParamsList() []normalTestParams {
|
||||||
type noBalanceTestParams struct {
|
type noBalanceTestParams struct {
|
||||||
name string
|
name string
|
||||||
input *RouteInputParams
|
input *RouteInputParams
|
||||||
expectedCandidates []*PathV2
|
expectedCandidates []*Path
|
||||||
expectedBest []*PathV2
|
expectedBest []*Path
|
||||||
expectedError *errors.ErrorResponse
|
expectedError *errors.ErrorResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2747,7 +2747,7 @@ func getNoBalanceTestParamsList() []noBalanceTestParams {
|
||||||
Code: ErrNotEnoughNativeBalance.Code,
|
Code: ErrNotEnoughNativeBalance.Code,
|
||||||
Details: fmt.Sprintf(ErrNotEnoughNativeBalance.Details, pathprocessor.EthSymbol, walletCommon.OptimismMainnet),
|
Details: fmt.Sprintf(ErrNotEnoughNativeBalance.Details, pathprocessor.EthSymbol, walletCommon.OptimismMainnet),
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorTransferName,
|
ProcessorName: pathprocessor.ProcessorTransferName,
|
||||||
FromChain: &optimism,
|
FromChain: &optimism,
|
||||||
|
@ -2834,7 +2834,7 @@ func getNoBalanceTestParamsList() []noBalanceTestParams {
|
||||||
Code: ErrNotEnoughNativeBalance.Code,
|
Code: ErrNotEnoughNativeBalance.Code,
|
||||||
Details: fmt.Sprintf(ErrNotEnoughNativeBalance.Details, pathprocessor.EthSymbol, walletCommon.ArbitrumMainnet),
|
Details: fmt.Sprintf(ErrNotEnoughNativeBalance.Details, pathprocessor.EthSymbol, walletCommon.ArbitrumMainnet),
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
||||||
FromChain: &mainnet,
|
FromChain: &mainnet,
|
||||||
|
@ -2888,7 +2888,7 @@ func getNoBalanceTestParamsList() []noBalanceTestParams {
|
||||||
approvalL1Fee: testApprovalL1Fee,
|
approvalL1Fee: testApprovalL1Fee,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedCandidates: []*PathV2{
|
expectedCandidates: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
||||||
FromChain: &mainnet,
|
FromChain: &mainnet,
|
||||||
|
@ -2910,7 +2910,7 @@ func getNoBalanceTestParamsList() []noBalanceTestParams {
|
||||||
ApprovalRequired: true,
|
ApprovalRequired: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedBest: []*PathV2{
|
expectedBest: []*Path{
|
||||||
{
|
{
|
||||||
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
ProcessorName: pathprocessor.ProcessorBridgeHopName,
|
||||||
FromChain: &arbitrum,
|
FromChain: &arbitrum,
|
Loading…
Reference in New Issue