test_: Added testing for isValidForNetworkComplianceV2

This commit is contained in:
Samuel Hawksby-Robinson 2024-05-17 13:49:14 +01:00
parent 0f33076ceb
commit e1f65fb531
1 changed files with 53 additions and 0 deletions

View File

@ -6,6 +6,8 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/status-im/status-go/params"
"github.com/stretchr/testify/assert" "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: &params.Network{ChainID: 1}},
{From: &params.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: &params.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: &params.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)
})
}
}