test_: Added much better coverage for testing for filterNetworkComplianceV2
This commit is contained in:
parent
4f2cd8ff7a
commit
a648635d60
|
@ -203,31 +203,169 @@ 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{
|
}{
|
||||||
{
|
{
|
||||||
{From: ¶ms.Network{ChainID: 1}},
|
name: "Mixed routes with valid and invalid paths",
|
||||||
{From: ¶ms.Network{ChainID: 3}},
|
routes: [][]*PathV2{
|
||||||
|
{
|
||||||
|
{From: ¶ms.Network{ChainID: 1}},
|
||||||
|
{From: ¶ms.Network{ChainID: 3}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{From: ¶ms.Network{ChainID: 2}},
|
||||||
|
{From: ¶ms.Network{ChainID: 3}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{From: ¶ms.Network{ChainID: 1}},
|
||||||
|
{From: ¶ms.Network{ChainID: 2}},
|
||||||
|
{From: ¶ms.Network{ChainID: 3}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fromLockedAmount: map[uint64]*hexutil.Big{
|
||||||
|
1: (*hexutil.Big)(big.NewInt(100)),
|
||||||
|
2: (*hexutil.Big)(big.NewInt(0)),
|
||||||
|
},
|
||||||
|
expectedRoutes: [][]*PathV2{
|
||||||
|
{
|
||||||
|
{From: ¶ms.Network{ChainID: 1}},
|
||||||
|
{From: ¶ms.Network{ChainID: 3}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{From: ¶ms.Network{ChainID: 1}},
|
||||||
|
{From: ¶ms.Network{ChainID: 2}},
|
||||||
|
{From: ¶ms.Network{ChainID: 3}},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
{From: ¶ms.Network{ChainID: 2}},
|
name: "All valid routes",
|
||||||
{From: ¶ms.Network{ChainID: 3}},
|
routes: [][]*PathV2{
|
||||||
|
{
|
||||||
|
{From: ¶ms.Network{ChainID: 1}},
|
||||||
|
{From: ¶ms.Network{ChainID: 3}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{From: ¶ms.Network{ChainID: 1}},
|
||||||
|
{From: ¶ms.Network{ChainID: 4}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fromLockedAmount: map[uint64]*hexutil.Big{
|
||||||
|
1: (*hexutil.Big)(big.NewInt(100)),
|
||||||
|
},
|
||||||
|
expectedRoutes: [][]*PathV2{
|
||||||
|
{
|
||||||
|
{From: ¶ms.Network{ChainID: 1}},
|
||||||
|
{From: ¶ms.Network{ChainID: 3}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{From: ¶ms.Network{ChainID: 1}},
|
||||||
|
{From: ¶ms.Network{ChainID: 4}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "All invalid routes",
|
||||||
|
routes: [][]*PathV2{
|
||||||
|
{
|
||||||
|
{From: ¶ms.Network{ChainID: 2}},
|
||||||
|
{From: ¶ms.Network{ChainID: 3}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{From: ¶ms.Network{ChainID: 4}},
|
||||||
|
{From: ¶ms.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: ¶ms.Network{ChainID: 1}},
|
||||||
|
{From: ¶ms.Network{ChainID: 2}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{From: ¶ms.Network{ChainID: 3}},
|
||||||
|
{From: ¶ms.Network{ChainID: 4}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fromLockedAmount: map[uint64]*hexutil.Big{},
|
||||||
|
expectedRoutes: [][]*PathV2{
|
||||||
|
{
|
||||||
|
{From: ¶ms.Network{ChainID: 1}},
|
||||||
|
{From: ¶ms.Network{ChainID: 2}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{From: ¶ms.Network{ChainID: 3}},
|
||||||
|
{From: ¶ms.Network{ChainID: 4}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Single route with mixed valid and invalid paths",
|
||||||
|
routes: [][]*PathV2{
|
||||||
|
{
|
||||||
|
{From: ¶ms.Network{ChainID: 1}},
|
||||||
|
{From: ¶ms.Network{ChainID: 2}},
|
||||||
|
{From: ¶ms.Network{ChainID: 3}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fromLockedAmount: map[uint64]*hexutil.Big{
|
||||||
|
1: (*hexutil.Big)(big.NewInt(100)),
|
||||||
|
2: (*hexutil.Big)(big.NewInt(0)),
|
||||||
|
},
|
||||||
|
expectedRoutes: [][]*PathV2{
|
||||||
|
{
|
||||||
|
{From: ¶ms.Network{ChainID: 1}},
|
||||||
|
{From: ¶ms.Network{ChainID: 3}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Routes with duplicate chain IDs",
|
||||||
|
routes: [][]*PathV2{
|
||||||
|
{
|
||||||
|
{From: ¶ms.Network{ChainID: 1}},
|
||||||
|
{From: ¶ms.Network{ChainID: 1}},
|
||||||
|
{From: ¶ms.Network{ChainID: 2}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fromLockedAmount: map[uint64]*hexutil.Big{
|
||||||
|
1: (*hexutil.Big)(big.NewInt(100)),
|
||||||
|
},
|
||||||
|
expectedRoutes: [][]*PathV2{
|
||||||
|
{
|
||||||
|
{From: ¶ms.Network{ChainID: 1}},
|
||||||
|
{From: ¶ms.Network{ChainID: 1}},
|
||||||
|
{From: ¶ms.Network{ChainID: 2}},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedRoutes := [][]*PathV2{
|
for _, tt := range tests {
|
||||||
{
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
{From: ¶ms.Network{ChainID: 1}},
|
filteredRoutes := filterNetworkComplianceV2(tt.routes, tt.fromLockedAmount)
|
||||||
{From: ¶ms.Network{ChainID: 3}},
|
assert.Equal(t, tt.expectedRoutes, filteredRoutes)
|
||||||
},
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
filteredRoutes := filterNetworkComplianceV2(routes, fromLockedAmount)
|
|
||||||
assert.Equal(t, expectedRoutes, filteredRoutes)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterCapacityValidationV2(t *testing.T) {
|
func TestFilterCapacityValidationV2(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue