test_: Added much better coverage for testing for filterNetworkComplianceV2

This commit is contained in:
Samuel Hawksby-Robinson 2024-05-17 14:37:19 +01:00
parent 4f2cd8ff7a
commit a648635d60
1 changed files with 156 additions and 18 deletions

View File

@ -203,31 +203,169 @@ func TestHasSufficientCapacityV2(t *testing.T) {
}
func TestFilterNetworkComplianceV2(t *testing.T) {
fromLockedAmount := map[uint64]*hexutil.Big{
1: (*hexutil.Big)(big.NewInt(100)),
2: (*hexutil.Big)(big.NewInt(0)),
}
routes := [][]*PathV2{
tests := []struct {
name string
routes [][]*PathV2
fromLockedAmount map[uint64]*hexutil.Big
expectedRoutes [][]*PathV2
}{
{
{From: &params.Network{ChainID: 1}},
{From: &params.Network{ChainID: 3}},
name: "Mixed routes with valid and invalid paths",
routes: [][]*PathV2{
{
{From: &params.Network{ChainID: 1}},
{From: &params.Network{ChainID: 3}},
},
{
{From: &params.Network{ChainID: 2}},
{From: &params.Network{ChainID: 3}},
},
{
{From: &params.Network{ChainID: 1}},
{From: &params.Network{ChainID: 2}},
{From: &params.Network{ChainID: 3}},
},
},
fromLockedAmount: map[uint64]*hexutil.Big{
1: (*hexutil.Big)(big.NewInt(100)),
2: (*hexutil.Big)(big.NewInt(0)),
},
expectedRoutes: [][]*PathV2{
{
{From: &params.Network{ChainID: 1}},
{From: &params.Network{ChainID: 3}},
},
{
{From: &params.Network{ChainID: 1}},
{From: &params.Network{ChainID: 2}},
{From: &params.Network{ChainID: 3}},
},
},
},
{
{From: &params.Network{ChainID: 2}},
{From: &params.Network{ChainID: 3}},
name: "All valid routes",
routes: [][]*PathV2{
{
{From: &params.Network{ChainID: 1}},
{From: &params.Network{ChainID: 3}},
},
{
{From: &params.Network{ChainID: 1}},
{From: &params.Network{ChainID: 4}},
},
},
fromLockedAmount: map[uint64]*hexutil.Big{
1: (*hexutil.Big)(big.NewInt(100)),
},
expectedRoutes: [][]*PathV2{
{
{From: &params.Network{ChainID: 1}},
{From: &params.Network{ChainID: 3}},
},
{
{From: &params.Network{ChainID: 1}},
{From: &params.Network{ChainID: 4}},
},
},
},
{
name: "All invalid routes",
routes: [][]*PathV2{
{
{From: &params.Network{ChainID: 2}},
{From: &params.Network{ChainID: 3}},
},
{
{From: &params.Network{ChainID: 4}},
{From: &params.Network{ChainID: 5}},
},
},
fromLockedAmount: map[uint64]*hexutil.Big{
1: (*hexutil.Big)(big.NewInt(100)),
2: (*hexutil.Big)(big.NewInt(0)),
},
expectedRoutes: [][]*PathV2{},
},
{
name: "Empty routes",
routes: [][]*PathV2{},
fromLockedAmount: map[uint64]*hexutil.Big{
1: (*hexutil.Big)(big.NewInt(100)),
},
expectedRoutes: [][]*PathV2{},
},
{
name: "No locked amounts",
routes: [][]*PathV2{
{
{From: &params.Network{ChainID: 1}},
{From: &params.Network{ChainID: 2}},
},
{
{From: &params.Network{ChainID: 3}},
{From: &params.Network{ChainID: 4}},
},
},
fromLockedAmount: map[uint64]*hexutil.Big{},
expectedRoutes: [][]*PathV2{
{
{From: &params.Network{ChainID: 1}},
{From: &params.Network{ChainID: 2}},
},
{
{From: &params.Network{ChainID: 3}},
{From: &params.Network{ChainID: 4}},
},
},
},
{
name: "Single route with mixed valid and invalid paths",
routes: [][]*PathV2{
{
{From: &params.Network{ChainID: 1}},
{From: &params.Network{ChainID: 2}},
{From: &params.Network{ChainID: 3}},
},
},
fromLockedAmount: map[uint64]*hexutil.Big{
1: (*hexutil.Big)(big.NewInt(100)),
2: (*hexutil.Big)(big.NewInt(0)),
},
expectedRoutes: [][]*PathV2{
{
{From: &params.Network{ChainID: 1}},
{From: &params.Network{ChainID: 3}},
},
},
},
{
name: "Routes with duplicate chain IDs",
routes: [][]*PathV2{
{
{From: &params.Network{ChainID: 1}},
{From: &params.Network{ChainID: 1}},
{From: &params.Network{ChainID: 2}},
},
},
fromLockedAmount: map[uint64]*hexutil.Big{
1: (*hexutil.Big)(big.NewInt(100)),
},
expectedRoutes: [][]*PathV2{
{
{From: &params.Network{ChainID: 1}},
{From: &params.Network{ChainID: 1}},
{From: &params.Network{ChainID: 2}},
},
},
},
}
expectedRoutes := [][]*PathV2{
{
{From: &params.Network{ChainID: 1}},
{From: &params.Network{ChainID: 3}},
},
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
filteredRoutes := filterNetworkComplianceV2(tt.routes, tt.fromLockedAmount)
assert.Equal(t, tt.expectedRoutes, filteredRoutes)
})
}
filteredRoutes := filterNetworkComplianceV2(routes, fromLockedAmount)
assert.Equal(t, expectedRoutes, filteredRoutes)
}
func TestFilterCapacityValidationV2(t *testing.T) {