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,12 +203,15 @@ func TestHasSufficientCapacityV2(t *testing.T) {
} }
func TestFilterNetworkComplianceV2(t *testing.T) { func TestFilterNetworkComplianceV2(t *testing.T) {
fromLockedAmount := map[uint64]*hexutil.Big{ tests := []struct {
1: (*hexutil.Big)(big.NewInt(100)), name string
2: (*hexutil.Big)(big.NewInt(0)), routes [][]*PathV2
} fromLockedAmount map[uint64]*hexutil.Big
expectedRoutes [][]*PathV2
routes := [][]*PathV2{ }{
{
name: "Mixed routes with valid and invalid paths",
routes: [][]*PathV2{
{ {
{From: &params.Network{ChainID: 1}}, {From: &params.Network{ChainID: 1}},
{From: &params.Network{ChainID: 3}}, {From: &params.Network{ChainID: 3}},
@ -217,17 +220,152 @@ func TestFilterNetworkComplianceV2(t *testing.T) {
{From: &params.Network{ChainID: 2}}, {From: &params.Network{ChainID: 2}},
{From: &params.Network{ChainID: 3}}, {From: &params.Network{ChainID: 3}},
}, },
} {
{From: &params.Network{ChainID: 1}},
expectedRoutes := [][]*PathV2{ {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: 1}},
{From: &params.Network{ChainID: 3}}, {From: &params.Network{ChainID: 3}},
}, },
{
{From: &params.Network{ChainID: 1}},
{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}},
},
},
},
} }
filteredRoutes := filterNetworkComplianceV2(routes, fromLockedAmount) for _, tt := range tests {
assert.Equal(t, expectedRoutes, filteredRoutes) t.Run(tt.name, func(t *testing.T) {
filteredRoutes := filterNetworkComplianceV2(tt.routes, tt.fromLockedAmount)
assert.Equal(t, tt.expectedRoutes, filteredRoutes)
})
}
} }
func TestFilterCapacityValidationV2(t *testing.T) { func TestFilterCapacityValidationV2(t *testing.T) {