From e1f65fb531bdec4f3b37cbbb8166bdd79d1ea993 Mon Sep 17 00:00:00 2001 From: Samuel Hawksby-Robinson Date: Fri, 17 May 2024 13:49:14 +0100 Subject: [PATCH] test_: Added testing for isValidForNetworkComplianceV2 --- services/wallet/router/filter_test.go | 53 +++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/services/wallet/router/filter_test.go b/services/wallet/router/filter_test.go index bf07adaaa..a475c9805 100644 --- a/services/wallet/router/filter_test.go +++ b/services/wallet/router/filter_test.go @@ -6,6 +6,8 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/status-im/status-go/params" + "github.com/stretchr/testify/assert" ) @@ -91,3 +93,54 @@ func TestCalculateTotalRestAmountV2(t *testing.T) { }) } } + +func TestIsValidForNetworkComplianceV2(t *testing.T) { + tests := []struct { + name string + route []*PathV2 + fromLockedAmount map[uint64]*hexutil.Big + expectedResult bool + }{ + { + name: "Valid route with required chain IDs included", + route: []*PathV2{ + {From: ¶ms.Network{ChainID: 1}}, + {From: ¶ms.Network{ChainID: 3}}, + }, + fromLockedAmount: map[uint64]*hexutil.Big{ + 1: (*hexutil.Big)(big.NewInt(100)), + 2: (*hexutil.Big)(big.NewInt(0)), + }, + expectedResult: true, + }, + { + name: "Invalid route with excluded chain ID", + route: []*PathV2{ + {From: ¶ms.Network{ChainID: 2}}, + }, + fromLockedAmount: map[uint64]*hexutil.Big{ + 1: (*hexutil.Big)(big.NewInt(100)), + 2: (*hexutil.Big)(big.NewInt(0)), + }, + expectedResult: false, + }, + { + name: "Route missing required chain ID", + route: []*PathV2{ + {From: ¶ms.Network{ChainID: 3}}, + }, + fromLockedAmount: map[uint64]*hexutil.Big{ + 1: (*hexutil.Big)(big.NewInt(100)), + 2: (*hexutil.Big)(big.NewInt(50)), + }, + expectedResult: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := isValidForNetworkComplianceV2(tt.route, tt.fromLockedAmount) + assert.Equal(t, tt.expectedResult, result) + }) + } +}