From 69125cd594cc4833a545520ff8d8dc457a08adf6 Mon Sep 17 00:00:00 2001 From: Samuel Hawksby-Robinson Date: Fri, 17 May 2024 14:11:38 +0100 Subject: [PATCH] test_: Added testing for hasSufficientCapacityV2 --- services/wallet/router/filter_test.go | 57 +++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/services/wallet/router/filter_test.go b/services/wallet/router/filter_test.go index a475c9805..591f02a3a 100644 --- a/services/wallet/router/filter_test.go +++ b/services/wallet/router/filter_test.go @@ -144,3 +144,60 @@ func TestIsValidForNetworkComplianceV2(t *testing.T) { }) } } + +func TestHasSufficientCapacityV2(t *testing.T) { + tests := []struct { + name string + route []*PathV2 + amountIn *big.Int + fromLockedAmount map[uint64]*hexutil.Big + expectedResult bool + }{ + { + name: "Sufficient capacity with multiple paths", + route: []*PathV2{ + {From: ¶ms.Network{ChainID: 1}, AmountIn: (*hexutil.Big)(big.NewInt(100))}, + {From: ¶ms.Network{ChainID: 2}, AmountIn: (*hexutil.Big)(big.NewInt(200))}, + }, + amountIn: big.NewInt(150), + fromLockedAmount: map[uint64]*hexutil.Big{ + 1: (*hexutil.Big)(big.NewInt(50)), + 2: (*hexutil.Big)(big.NewInt(100)), + }, + expectedResult: true, + }, + { + name: "Insufficient capacity", + route: []*PathV2{ + {From: ¶ms.Network{ChainID: 1}, AmountIn: (*hexutil.Big)(big.NewInt(100))}, + {From: ¶ms.Network{ChainID: 2}, AmountIn: (*hexutil.Big)(big.NewInt(50))}, + }, + amountIn: big.NewInt(200), + fromLockedAmount: map[uint64]*hexutil.Big{ + 1: (*hexutil.Big)(big.NewInt(50)), + 2: (*hexutil.Big)(big.NewInt(50)), + }, + expectedResult: false, + }, + { + name: "Exact capacity match", + route: []*PathV2{ + {From: ¶ms.Network{ChainID: 1}, AmountIn: (*hexutil.Big)(big.NewInt(100))}, + {From: ¶ms.Network{ChainID: 2}, AmountIn: (*hexutil.Big)(big.NewInt(50))}, + }, + amountIn: big.NewInt(150), + fromLockedAmount: map[uint64]*hexutil.Big{ + 1: (*hexutil.Big)(big.NewInt(100)), + 2: (*hexutil.Big)(big.NewInt(50)), + }, + expectedResult: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := hasSufficientCapacityV2(tt.route, tt.amountIn, tt.fromLockedAmount) + assert.Equal(t, tt.expectedResult, result) + }) + } +}