Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Unit tests #21

Merged
merged 18 commits into from
Sep 22, 2023
Merged
28 changes: 17 additions & 11 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ func TestGetDestinationRPCEndpoint(t *testing.T) {
}

for i, testCase := range testCases {
res := testCase.s.GetNodeRPCEndpoint()
require.Equal(t, testCase.expectedResult, res, fmt.Sprintf("test case %d failed", i))
t.Run(fmt.Sprintf("test_%d", i), func(t *testing.T) {
res := testCase.s.GetNodeRPCEndpoint()
require.Equal(t, testCase.expectedResult, res)
})
minghinmatthewlam marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -182,8 +184,10 @@ func TestGetSourceSubnetWSEndpoint(t *testing.T) {
}

for i, testCase := range testCases {
res := testCase.s.GetNodeWSEndpoint()
require.Equal(t, testCase.expectedResult, res, fmt.Sprintf("test case %d failed", i))
t.Run(fmt.Sprintf("test_%d", i), func(t *testing.T) {
res := testCase.s.GetNodeWSEndpoint()
require.Equal(t, testCase.expectedResult, res)
})
}
}

Expand Down Expand Up @@ -240,12 +244,14 @@ func TestGetRelayerAccountInfo(t *testing.T) {
}

for i, testCase := range testCases {
pk, addr, err := testCase.s.GetRelayerAccountInfo()
require.Equal(t, testCase.expectedResult.err, err, fmt.Sprintf("test case %d had unexpected error", i))
if err == nil {
require.Equal(t, testCase.expectedResult.pk.D.Int64(), pk.D.Int64(), fmt.Sprintf("test case %d had mismatched pk", i))
require.Equal(t, testCase.expectedResult.addr, addr, fmt.Sprintf("test case %d had mismatched address", i))
}
t.Run(fmt.Sprintf("test_%d", i), func(t *testing.T) {
pk, addr, err := testCase.s.GetRelayerAccountInfo()
require.Equal(t, testCase.expectedResult.err, err)
if err == nil {
require.Equal(t, testCase.expectedResult.pk.D.Int64(), pk.D.Int64())
require.Equal(t, testCase.expectedResult.addr, addr)
}
})
}
}

Expand Down Expand Up @@ -280,7 +286,7 @@ func runGetRelayerAccountPrivateKeyTest(t *testing.T, testCase getRelayerAccount
require.NoError(t, err)
require.Equal(t, optionOverwritten, testCase.expectedOverwritten)

require.True(t, testCase.resultVerifier(parsedCfg), "unexpected config")
require.True(t, testCase.resultVerifier(parsedCfg))
}

func TestGetRelayerAccountPrivateKey_set_pk_in_config(t *testing.T) {
Expand Down
29 changes: 18 additions & 11 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package utils

import (
"fmt"
"math/big"
"testing"

Expand Down Expand Up @@ -50,14 +51,16 @@ func TestConvertProtocol(t *testing.T) {
}

for i, testCase := range testCases {
actualUrl, err := ConvertProtocol(testCase.urlString, testCase.protocol)
t.Run(fmt.Sprintf("test_%d", i), func(t *testing.T) {
actualUrl, err := ConvertProtocol(testCase.urlString, testCase.protocol)

if testCase.expectedError {
require.Error(t, err, "Test case %d failed", i)
} else {
require.NoError(t, err, "Test case %d failed", i)
}
require.Equal(t, testCase.expectedUrl, actualUrl, "Test case %d failed", i)
if testCase.expectedError {
require.Error(t, err)
} else {
require.NoError(t, err)
}
require.Equal(t, testCase.expectedUrl, actualUrl)
minghinmatthewlam marked this conversation as resolved.
Show resolved Hide resolved
})
}
}

Expand All @@ -83,8 +86,10 @@ func TestSanitizeHashString(t *testing.T) {
},
}
for i, testCase := range testCases {
actualResult := SanitizeHashString(testCase.hash)
require.Equal(t, testCase.expectedResult, actualResult, "Test case %d failed", i)
t.Run(fmt.Sprintf("test_%d", i), func(t *testing.T) {
actualResult := SanitizeHashString(testCase.hash)
require.Equal(t, testCase.expectedResult, actualResult)
})
}
}

Expand Down Expand Up @@ -133,7 +138,9 @@ func TestCheckStakeWeightExceedsThreshold(t *testing.T) {
},
}
for i, testCase := range testCases {
actualResult := CheckStakeWeightExceedsThreshold(new(big.Int).SetUint64(testCase.accumulatedSignatureWeight), testCase.totalWeight, testCase.quorumNumerator, testCase.quorumDenominator)
require.Equal(t, testCase.expectedResult, actualResult, "Test case %d failed", i)
t.Run(fmt.Sprintf("test_%d", i), func(t *testing.T) {
actualResult := CheckStakeWeightExceedsThreshold(new(big.Int).SetUint64(testCase.accumulatedSignatureWeight), testCase.totalWeight, testCase.quorumNumerator, testCase.quorumDenominator)
require.Equal(t, testCase.expectedResult, actualResult)
})
}
}