Engine: Protocol Features, coverage, types, BTC markets websocket (#368)

* Attempts to update orderbook so it doesn't need to sort

* Reverts the ws ob stuff. Gets rid of sorting because it happens later. Adds some exchange features

* update existing feature lists. Expands list definition to match my emotions

* Adds bithumb bitmex and bitstamp. adds a couple more types

* Features for you, features for me, features for bittrex, btcmarkets, btse, coinbasepro, coinut, exmo, gateio and gemini

* Features for hitbtc, huobi, itbit, kraken, lakebtc, lbank, localbitcoins, okcoin, okex, poloniex, yobit, zb

* Who can forget good old alphapoint?

* Adds btcmarksets websocket :glitch_crab: fixes alphapoint features

* Adds extra data not in the documentation :/

* Replaces websocket features by using protocol features. However, it breaks it due to import cycles. I'm not sure what I'll do just yet

* Removes import cycle via duplicate structs.

* Increases coverage of config with `TestCheckCurrencyConfigValues`. Moves all currency pair package types into their own files or places it at the bottom of files if necessary

* Increase coverage in code.go

* One way of determining a test has failed, is when to it fails. Removed redundant explanation

* Increases code coverage of conversion

* Lint fixes

* Fixes orderbook tests

* Re-adds sorting because its important to still have the internal pre-processed orderbook to be representative of a real orderbook

* Secret lints that did not show up via Windows linting

* Adds protocol package to contain exchange features

* Fixes protocol implementation

* Fixes ws tests

* Addresses the following: Removes st-st-stutters in config types, changes GetAvailableForexProviders -> GetSupportedForexProviders, removes errors from tests where error is nil, removes orderbook setup when not necessary, removes import newlines, removes false bools from declaration, changes should of to should have

* imports and casing

* Fixes two more nil error checks
This commit is contained in:
Scott
2019-10-22 10:56:20 +11:00
committed by Adrian Gallagher
parent ec0ed1c1e5
commit ccfcdf26aa
156 changed files with 5228 additions and 4337 deletions

View File

@@ -16,13 +16,13 @@ func TestIsEnabled(t *testing.T) {
expected := "Enabled"
actual := IsEnabled(true)
if actual != expected {
t.Errorf("Test failed. Expected %s. Actual %s", expected, actual)
t.Errorf("Expected %s. Actual %s", expected, actual)
}
expected = "Disabled"
actual = IsEnabled(false)
if actual != expected {
t.Errorf("Test failed. Expected %s. Actual %s", expected, actual)
t.Errorf("Expected %s. Actual %s", expected, actual)
}
}
@@ -30,44 +30,44 @@ func TestIsValidCryptoAddress(t *testing.T) {
t.Parallel()
b, err := IsValidCryptoAddress("1Mz7153HMuxXTuR2R1t78mGSdzaAtNbBWX", "bTC")
if err != nil && !b {
t.Errorf("Test Failed - Common IsValidCryptoAddress error: %s", err)
t.Errorf("Common IsValidCryptoAddress error: %s", err)
}
b, err = IsValidCryptoAddress("0Mz7153HMuxXTuR2R1t78mGSdzaAtNbBWX", "btc")
if err == nil && b {
t.Error("Test Failed - Common IsValidCryptoAddress error")
t.Error("Common IsValidCryptoAddress error")
}
b, err = IsValidCryptoAddress("1Mz7153HMuxXTuR2R1t78mGSdzaAtNbBWX", "lTc")
if err == nil && b {
t.Error("Test Failed - Common IsValidCryptoAddress error")
t.Error("Common IsValidCryptoAddress error")
}
b, err = IsValidCryptoAddress("3CDJNfdWX8m2NwuGUV3nhXHXEeLygMXoAj", "ltc")
if err != nil && !b {
t.Errorf("Test Failed - Common IsValidCryptoAddress error: %s", err)
t.Errorf("Common IsValidCryptoAddress error: %s", err)
}
b, err = IsValidCryptoAddress("NCDJNfdWX8m2NwuGUV3nhXHXEeLygMXoAj", "lTc")
if err == nil && b {
t.Error("Test Failed - Common IsValidCryptoAddress error")
t.Error("Common IsValidCryptoAddress error")
}
b, err = IsValidCryptoAddress(
"0xb794f5ea0ba39494ce839613fffba74279579268",
"eth",
)
if err != nil && b {
t.Errorf("Test Failed - Common IsValidCryptoAddress error: %s", err)
t.Errorf("Common IsValidCryptoAddress error: %s", err)
}
b, err = IsValidCryptoAddress(
"xxb794f5ea0ba39494ce839613fffba74279579268",
"eTh",
)
if err == nil && b {
t.Error("Test Failed - Common IsValidCryptoAddress error")
t.Error("Common IsValidCryptoAddress error")
}
b, err = IsValidCryptoAddress(
"xxb794f5ea0ba39494ce839613fffba74279579268",
"ding",
)
if err == nil && b {
t.Error("Test Failed - Common IsValidCryptoAddress error")
t.Error("Common IsValidCryptoAddress error")
}
}
@@ -78,7 +78,7 @@ func TestStringSliceDifference(t *testing.T) {
expectedOutput := []string{"hello moto"}
actualResult := StringSliceDifference(originalInputOne, originalInputTwo)
if reflect.DeepEqual(expectedOutput, actualResult) {
t.Errorf("Test failed. Expected '%s'. Actual '%s'",
t.Errorf("Expected '%s'. Actual '%s'",
expectedOutput, actualResult)
}
}
@@ -92,12 +92,12 @@ func TestStringDataContains(t *testing.T) {
expectedOutputTwo := false
actualResult := StringDataContains(originalHaystack, originalNeedle)
if actualResult != expectedOutput {
t.Errorf("Test failed. Expected '%v'. Actual '%v'",
t.Errorf("Expected '%v'. Actual '%v'",
expectedOutput, actualResult)
}
actualResult = StringDataContains(originalHaystack, anotherNeedle)
if actualResult != expectedOutputTwo {
t.Errorf("Test failed. Expected '%v'. Actual '%v'",
t.Errorf("Expected '%v'. Actual '%v'",
expectedOutput, actualResult)
}
}
@@ -111,12 +111,12 @@ func TestStringDataCompare(t *testing.T) {
expectedOutputTwo := false
actualResult := StringDataCompare(originalHaystack, originalNeedle)
if actualResult != expectedOutput {
t.Errorf("Test failed. Expected '%v'. Actual '%v'",
t.Errorf("Expected '%v'. Actual '%v'",
expectedOutput, actualResult)
}
actualResult = StringDataCompare(originalHaystack, anotherNeedle)
if actualResult != expectedOutputTwo {
t.Errorf("Test failed. Expected '%v'. Actual '%v'",
t.Errorf("Expected '%v'. Actual '%v'",
expectedOutput, actualResult)
}
}
@@ -130,13 +130,13 @@ func TestStringDataCompareUpper(t *testing.T) {
expectedOutputTwo := false
actualResult := StringDataCompareInsensitive(originalHaystack, originalNeedle)
if actualResult != expectedOutput {
t.Errorf("Test failed. Expected '%v'. Actual '%v'",
t.Errorf("Expected '%v'. Actual '%v'",
expectedOutput, actualResult)
}
actualResult = StringDataCompareInsensitive(originalHaystack, anotherNeedle)
if actualResult != expectedOutputTwo {
t.Errorf("Test failed. Expected '%v'. Actual '%v'",
t.Errorf("Expected '%v'. Actual '%v'",
expectedOutput, actualResult)
}
}
@@ -150,12 +150,12 @@ func TestStringDataContainsUpper(t *testing.T) {
expectedOutputTwo := false
actualResult := StringDataContainsInsensitive(originalHaystack, originalNeedle)
if actualResult != expectedOutput {
t.Errorf("Test failed. Expected '%v'. Actual '%v'",
t.Errorf("Expected '%v'. Actual '%v'",
expectedOutput, actualResult)
}
actualResult = StringDataContainsInsensitive(originalHaystack, anotherNeedle)
if actualResult != expectedOutputTwo {
t.Errorf("Test failed. Expected '%v'. Actual '%v'",
t.Errorf("Expected '%v'. Actual '%v'",
expectedOutput, actualResult)
}
}
@@ -163,13 +163,13 @@ func TestStringDataContainsUpper(t *testing.T) {
func TestYesOrNo(t *testing.T) {
t.Parallel()
if !YesOrNo("y") {
t.Error("Test failed - Common YesOrNo Error.")
t.Error("Common YesOrNo Error.")
}
if !YesOrNo("yes") {
t.Error("Test failed - Common YesOrNo Error.")
t.Error("Common YesOrNo Error.")
}
if YesOrNo("ding") {
t.Error("Test failed - Common YesOrNo Error.")
t.Error("Common YesOrNo Error.")
}
}
@@ -187,42 +187,42 @@ func TestSendHTTPRequest(t *testing.T) {
strings.NewReader(""),
)
if err == nil {
t.Error("Test failed. ")
t.Error("Expected error 'invalid HTTP method specified'")
}
_, err = SendHTTPRequest(
methodPost, "https://www.google.com", headers,
strings.NewReader(""),
)
if err != nil {
t.Errorf("Test failed. %s ", err)
t.Error(err)
}
_, err = SendHTTPRequest(
methodGet, "https://www.google.com", headers,
strings.NewReader(""),
)
if err != nil {
t.Errorf("Test failed. %s ", err)
t.Error(err)
}
_, err = SendHTTPRequest(
methodDelete, "https://www.google.com", headers,
strings.NewReader(""),
)
if err != nil {
t.Errorf("Test failed. %s ", err)
t.Error(err)
}
_, err = SendHTTPRequest(
methodGet, ":missingprotocolscheme", headers,
strings.NewReader(""),
)
if err == nil {
t.Error("Test failed. Common HTTPRequest accepted missing protocol")
t.Error("Common HTTPRequest accepted missing protocol")
}
_, err = SendHTTPRequest(
methodGet, "test://unsupportedprotocolscheme", headers,
strings.NewReader(""),
)
if err == nil {
t.Error("Test failed. Common HTTPRequest accepted invalid protocol")
t.Error("Common HTTPRequest accepted invalid protocol")
}
}
@@ -243,23 +243,23 @@ func TestSendHTTPGetRequest(t *testing.T) {
err := SendHTTPGetRequest(ethURL, true, true, &result)
if err != nil {
t.Errorf("Test failed - common SendHTTPGetRequest error: %s", err)
t.Errorf("common SendHTTPGetRequest error: %s", err)
}
err = SendHTTPGetRequest("DINGDONG", true, false, &result)
if err == nil {
t.Error("Test failed - common SendHTTPGetRequest error")
t.Error("common SendHTTPGetRequest error")
}
err = SendHTTPGetRequest(ethURL, false, false, &result)
if err != nil {
t.Errorf("Test failed - common SendHTTPGetRequest error: %s", err)
t.Errorf("common SendHTTPGetRequest error: %s", err)
}
err = SendHTTPGetRequest("https://httpstat.us/202", false, false, &result)
if err == nil {
t.Error("Test failed = common SendHTTPGetRequest error: Ignored unexpected status code")
t.Error("= common SendHTTPGetRequest error: Ignored unexpected status code")
}
err = SendHTTPGetRequest(ethURL, true, false, &badresult)
if err == nil {
t.Error("Test failed - common SendHTTPGetRequest error: Unmarshalled into bad type")
t.Error("common SendHTTPGetRequest error: Unmarshalled into bad type")
}
}
@@ -282,14 +282,14 @@ func TestJSONEncode(t *testing.T) {
bitey, err := JSONEncode(v)
if err != nil {
t.Errorf("Test failed - common JSONEncode error: %s", err)
t.Errorf("common JSONEncode error: %s", err)
}
if string(bitey) != expectOutputString {
t.Error("Test failed - common JSONEncode error")
t.Error("common JSONEncode error")
}
_, err = JSONEncode("WigWham")
if err != nil {
t.Errorf("Test failed - common JSONEncode error: %s", err)
t.Errorf("common JSONEncode error: %s", err)
}
}
@@ -299,7 +299,7 @@ func TestJSONDecode(t *testing.T) {
result := "Not a memory address"
err := JSONDecode(data, result)
if err == nil {
t.Error("Test failed. Common JSONDecode, unmarshalled when address not supplied")
t.Error("Common JSONDecode, unmarshalled when address not supplied")
}
type test struct {
@@ -314,7 +314,7 @@ func TestJSONDecode(t *testing.T) {
data = []byte(`{"status":1,"data":null}`)
err = JSONDecode(data, &v)
if err != nil || v.Status != 1 {
t.Errorf("Test failed. Common JSONDecode. Data: %v \nError: %s",
t.Errorf("Common JSONDecode. Data: %v \nError: %s",
v, err)
}
}
@@ -329,7 +329,7 @@ func TestEncodeURLValues(t *testing.T) {
output := EncodeURLValues(urlstring, values)
if output != expectedOutput {
t.Error("Test Failed - common EncodeURLValues error")
t.Error("common EncodeURLValues error")
}
}
@@ -341,12 +341,12 @@ func TestExtractHost(t *testing.T) {
actualResult := ExtractHost(address)
if expectedOutput != actualResult {
t.Errorf(
"Test failed. Expected '%s'. Actual '%s'.", expectedOutput, actualResult)
"Expected '%s'. Actual '%s'.", expectedOutput, actualResult)
}
actualResultTwo := ExtractHost(addresstwo)
if expectedOutput != actualResultTwo {
t.Errorf(
"Test failed. Expected '%s'. Actual '%s'.", expectedOutput, actualResult)
"Expected '%s'. Actual '%s'.", expectedOutput, actualResult)
}
address = "192.168.1.100:1337"
@@ -354,7 +354,7 @@ func TestExtractHost(t *testing.T) {
actualResult = ExtractHost(address)
if expectedOutput != actualResult {
t.Errorf(
"Test failed. Expected '%s'. Actual '%s'.", expectedOutput, actualResult)
"Expected '%s'. Actual '%s'.", expectedOutput, actualResult)
}
}
@@ -365,7 +365,7 @@ func TestExtractPort(t *testing.T) {
actualResult := ExtractPort(address)
if expectedOutput != actualResult {
t.Errorf(
"Test failed. Expected '%d'. Actual '%d'.", expectedOutput, actualResult)
"Expected '%d'. Actual '%d'.", expectedOutput, actualResult)
}
}
@@ -378,11 +378,11 @@ func TestOutputCSV(t *testing.T) {
err := OutputCSV(path, data)
if err != nil {
t.Errorf("Test failed - common OutputCSV error: %s", err)
t.Errorf("common OutputCSV error: %s", err)
}
err = OutputCSV("/:::notapath:::", data)
if err == nil {
t.Error("Test failed - common OutputCSV, tried writing to invalid path")
t.Error("common OutputCSV, tried writing to invalid path")
}
}
@@ -397,7 +397,7 @@ func TestGetURIPath(t *testing.T) {
for testInput, expectedOutput := range testTable {
actualOutput := GetURIPath(testInput)
if actualOutput != expectedOutput {
t.Errorf("Test failed. Expected '%s'. Actual '%s'.",
t.Errorf("Expected '%s'. Actual '%s'.",
expectedOutput, actualOutput)
}
}
@@ -407,7 +407,7 @@ func TestGetExecutablePath(t *testing.T) {
t.Parallel()
_, err := GetExecutablePath()
if err != nil {
t.Errorf("Test failed. Common GetExecutablePath. Error: %s", err)
t.Errorf("Common GetExecutablePath. Error: %s", err)
}
}

View File

@@ -12,20 +12,20 @@ func TestFloatFromString(t *testing.T) {
actualOutput, err := FloatFromString(testString)
if actualOutput != expectedOutput || err != nil {
t.Errorf("Test failed. Common FloatFromString. Expected '%v'. Actual '%v'. Error: %s",
t.Errorf("Common FloatFromString. Expected '%v'. Actual '%v'. Error: %s",
expectedOutput, actualOutput, err)
}
var testByte []byte
_, err = FloatFromString(testByte)
if err == nil {
t.Error("Test failed. Common FloatFromString. Converted non-string.")
t.Error("Common FloatFromString. Converted non-string.")
}
testString = " something unconvertible "
_, err = FloatFromString(testString)
if err == nil {
t.Error("Test failed. Common FloatFromString. Converted invalid syntax.")
t.Error("Common FloatFromString. Converted invalid syntax.")
}
}
@@ -36,20 +36,20 @@ func TestIntFromString(t *testing.T) {
actualOutput, err := IntFromString(testString)
if actualOutput != expectedOutput || err != nil {
t.Errorf("Test failed. Common IntFromString. Expected '%v'. Actual '%v'. Error: %s",
t.Errorf("Common IntFromString. Expected '%v'. Actual '%v'. Error: %s",
expectedOutput, actualOutput, err)
}
var testByte []byte
_, err = IntFromString(testByte)
if err == nil {
t.Error("Test failed. Common IntFromString. Converted non-string.")
t.Error("Common IntFromString. Converted non-string.")
}
testString = "1.41421356237"
_, err = IntFromString(testString)
if err == nil {
t.Error("Test failed. Common IntFromString. Converted invalid syntax.")
t.Error("Common IntFromString. Converted invalid syntax.")
}
}
@@ -60,20 +60,20 @@ func TestInt64FromString(t *testing.T) {
actualOutput, err := Int64FromString(testString)
if actualOutput != expectedOutput || err != nil {
t.Errorf("Test failed. Common Int64FromString. Expected '%v'. Actual '%v'. Error: %s",
t.Errorf("Common Int64FromString. Expected '%v'. Actual '%v'. Error: %s",
expectedOutput, actualOutput, err)
}
var testByte []byte
_, err = Int64FromString(testByte)
if err == nil {
t.Error("Test failed. Common Int64FromString. Converted non-string.")
t.Error("Common Int64FromString. Converted non-string.")
}
testString = "1.41421356237"
_, err = Int64FromString(testString)
if err == nil {
t.Error("Test failed. Common Int64FromString. Converted invalid syntax.")
t.Error("Common Int64FromString. Converted invalid syntax.")
}
}
@@ -84,14 +84,14 @@ func TestTimeFromUnixTimestampFloat(t *testing.T) {
actualOutput, err := TimeFromUnixTimestampFloat(testTimestamp)
if actualOutput.UTC().String() != expectedOutput.UTC().String() || err != nil {
t.Errorf("Test failed. Common TimeFromUnixTimestampFloat. Expected '%v'. Actual '%v'. Error: %s",
t.Errorf("Common TimeFromUnixTimestampFloat. Expected '%v'. Actual '%v'. Error: %s",
expectedOutput, actualOutput, err)
}
testString := "Time"
_, err = TimeFromUnixTimestampFloat(testString)
if err == nil {
t.Error("Test failed. Common TimeFromUnixTimestampFloat. Converted invalid syntax.")
t.Error("Common TimeFromUnixTimestampFloat. Converted invalid syntax.")
}
}
@@ -103,7 +103,7 @@ func TestUnixTimestampToTime(t *testing.T) {
actualResult := UnixTimestampToTime(testTime)
if tm.String() != actualResult.String() {
t.Errorf(
"Test failed. Expected '%s'. Actual '%s'.", expectedOutput, actualResult)
"Expected '%s'. Actual '%s'.", expectedOutput, actualResult)
}
}
@@ -118,11 +118,11 @@ func TestUnixTimestampStrToTime(t *testing.T) {
}
if actualResult.UTC().String() != expectedOutput {
t.Errorf(
"Test failed. Expected '%s'. Actual '%s'.", expectedOutput, actualResult)
"Expected '%s'. Actual '%s'.", expectedOutput, actualResult)
}
actualResult, err = UnixTimestampStrToTime(incorrectTime)
if err == nil {
t.Error("Test failed. Common UnixTimestampStrToTime error")
t.Error("Common UnixTimestampStrToTime error")
}
}
@@ -133,7 +133,7 @@ func TestUnixMillis(t *testing.T) {
actualOutput := UnixMillis(testTime)
if actualOutput != expectedOutput {
t.Errorf("Test failed. Common UnixMillis. Expected '%d'. Actual '%d'.",
t.Errorf("Common UnixMillis. Expected '%d'. Actual '%d'.",
expectedOutput, actualOutput)
}
}
@@ -145,7 +145,7 @@ func TestRecvWindow(t *testing.T) {
actualOutput := RecvWindow(testTime)
if actualOutput != expectedOutput {
t.Errorf("Test failed. Common RecvWindow. Expected '%d'. Actual '%d'",
t.Errorf("Common RecvWindow. Expected '%d'. Actual '%d'",
expectedOutput, actualOutput)
}
}

View File

@@ -11,7 +11,7 @@ func TestHexEncodeToString(t *testing.T) {
expectedOutput := "737472696e67"
actualResult := HexEncodeToString(originalInput)
if actualResult != expectedOutput {
t.Errorf("Test failed. Expected '%s'. Actual '%s'",
t.Errorf("Expected '%s'. Actual '%s'",
expectedOutput, actualResult)
}
}
@@ -22,13 +22,13 @@ func TestBase64Decode(t *testing.T) {
expectedOutput := []byte("hello")
actualResult, err := Base64Decode(originalInput)
if !bytes.Equal(actualResult, expectedOutput) {
t.Errorf("Test failed. Expected '%s'. Actual '%s'. Error: %s",
t.Errorf("Expected '%s'. Actual '%s'. Error: %s",
expectedOutput, actualResult, err)
}
_, err = Base64Decode("-")
if err == nil {
t.Error("Test failed. Bad base64 string failed returned nil error")
t.Error("Bad base64 string failed returned nil error")
}
}
@@ -38,7 +38,7 @@ func TestBase64Encode(t *testing.T) {
expectedOutput := "aGVsbG8="
actualResult := Base64Encode(originalInput)
if actualResult != expectedOutput {
t.Errorf("Test failed. Expected '%s'. Actual '%s'",
t.Errorf("Expected '%s'. Actual '%s'",
expectedOutput, actualResult)
}
}
@@ -48,7 +48,7 @@ func TestGetRandomSalt(t *testing.T) {
_, err := GetRandomSalt(nil, -1)
if err == nil {
t.Fatal("Test failed. Expected err on negative salt length")
t.Fatal("Expected err on negative salt length")
}
salt, err := GetRandomSalt(nil, 10)
@@ -57,7 +57,7 @@ func TestGetRandomSalt(t *testing.T) {
}
if len(salt) != 10 {
t.Fatal("Test failed. Expected salt of len=10")
t.Fatal("Expected salt of len=10")
}
salt, err = GetRandomSalt([]byte("RAWR"), 12)
@@ -66,7 +66,7 @@ func TestGetRandomSalt(t *testing.T) {
}
if len(salt) != 16 {
t.Fatal("Test failed. Expected salt of len=16")
t.Fatal("Expected salt of len=16")
}
}
@@ -77,7 +77,7 @@ func TestGetMD5(t *testing.T) {
actualOutput := GetMD5(originalString)
actualStr := HexEncodeToString(actualOutput)
if !bytes.Equal(expectedOutput, []byte(actualStr)) {
t.Errorf("Test failed. Expected '%s'. Actual '%s'",
t.Errorf("Expected '%s'. Actual '%s'",
expectedOutput, []byte(actualStr))
}
@@ -92,7 +92,7 @@ func TestGetSHA512(t *testing.T) {
actualOutput := GetSHA512(originalString)
actualStr := HexEncodeToString(actualOutput)
if !bytes.Equal(expectedOutput, []byte(actualStr)) {
t.Errorf("Test failed. Expected '%x'. Actual '%x'",
t.Errorf("Expected '%x'. Actual '%x'",
expectedOutput, []byte(actualStr))
}
}
@@ -106,7 +106,7 @@ func TestGetSHA256(t *testing.T) {
actualOutput := GetSHA256(originalString)
actualStr := HexEncodeToString(actualOutput)
if !bytes.Equal(expectedOutput, []byte(actualStr)) {
t.Errorf("Test failed. Expected '%x'. Actual '%x'", expectedOutput,
t.Errorf("Expected '%x'. Actual '%x'", expectedOutput,
[]byte(actualStr))
}
}
@@ -138,31 +138,31 @@ func TestGetHMAC(t *testing.T) {
sha1 := GetHMAC(HashSHA1, []byte("Hello,World"), []byte("1234"))
if string(sha1) != string(expectedSha1) {
t.Errorf("Test failed. Common GetHMAC error: Expected '%x'. Actual '%x'",
t.Errorf("Common GetHMAC error: Expected '%x'. Actual '%x'",
expectedSha1, sha1,
)
}
sha256 := GetHMAC(HashSHA256, []byte("Hello,World"), []byte("1234"))
if string(sha256) != string(expectedsha256) {
t.Errorf("Test failed. Common GetHMAC error: Expected '%x'. Actual '%x'",
t.Errorf("Common GetHMAC error: Expected '%x'. Actual '%x'",
expectedsha256, sha256,
)
}
sha512 := GetHMAC(HashSHA512, []byte("Hello,World"), []byte("1234"))
if string(sha512) != string(expectedsha512) {
t.Errorf("Test failed. Common GetHMAC error: Expected '%x'. Actual '%x'",
t.Errorf("Common GetHMAC error: Expected '%x'. Actual '%x'",
expectedsha512, sha512,
)
}
sha512384 := GetHMAC(HashSHA512_384, []byte("Hello,World"), []byte("1234"))
if string(sha512384) != string(expectedsha512384) {
t.Errorf("Test failed. Common GetHMAC error: Expected '%x'. Actual '%x'",
t.Errorf("Common GetHMAC error: Expected '%x'. Actual '%x'",
expectedsha512384, sha512384,
)
}
md5 := GetHMAC(HashMD5, []byte("Hello World"), []byte("1234"))
if string(md5) != string(expectedmd5) {
t.Errorf("Test failed. Common GetHMAC error: Expected '%x'. Actual '%x'",
t.Errorf("Common GetHMAC error: Expected '%x'. Actual '%x'",
expectedmd5, md5,
)
}
@@ -174,7 +174,7 @@ func TestSha1Tohex(t *testing.T) {
expectedResult := "fcfbfcd7d31d994ef660f6972399ab5d7a890149"
actualResult := Sha1ToHex("Testing Sha1ToHex")
if actualResult != expectedResult {
t.Errorf("Test failed. Expected '%s'. Actual '%s'",
t.Errorf("Expected '%s'. Actual '%s'",
expectedResult, actualResult)
}
}

View File

@@ -10,7 +10,7 @@ func TestCalculateFee(t *testing.T) {
actualResult := CalculateFee(originalInput, fee)
if expectedOutput != actualResult {
t.Errorf(
"Test failed. Expected '%f'. Actual '%f'.", expectedOutput, actualResult)
"Expected '%f'. Actual '%f'.", expectedOutput, actualResult)
}
}
@@ -22,7 +22,7 @@ func TestCalculateAmountWithFee(t *testing.T) {
actualResult := CalculateAmountWithFee(originalInput, fee)
if expectedOutput != actualResult {
t.Errorf(
"Test failed. Expected '%f'. Actual '%f'.", expectedOutput, actualResult)
"Expected '%f'. Actual '%f'.", expectedOutput, actualResult)
}
}
@@ -34,7 +34,7 @@ func TestCalculatePercentageGainOrLoss(t *testing.T) {
actualResult := CalculatePercentageGainOrLoss(originalInput, secondInput)
if expectedOutput != actualResult {
t.Errorf(
"Test failed. Expected '%f'. Actual '%f'.", expectedOutput, actualResult)
"Expected '%f'. Actual '%f'.", expectedOutput, actualResult)
}
}
@@ -46,7 +46,7 @@ func TestCalculatePercentageDifference(t *testing.T) {
actualResult := CalculatePercentageDifference(originalInput, secondAmount)
if expectedOutput != actualResult {
t.Errorf(
"Test failed. Expected '%f'. Actual '%f'.", expectedOutput, actualResult)
"Expected '%f'. Actual '%f'.", expectedOutput, actualResult)
}
}
@@ -60,7 +60,7 @@ func TestCalculateNetProfit(t *testing.T) {
actualResult := CalculateNetProfit(amount, priceThen, priceNow, costs)
if expectedOutput != actualResult {
t.Errorf(
"Test failed. Expected '%f'. Actual '%f'.", expectedOutput, actualResult)
"Expected '%f'. Actual '%f'.", expectedOutput, actualResult)
}
}
@@ -74,7 +74,7 @@ func TestRoundFloat(t *testing.T) {
for testInput, expectedOutput := range testTable {
actualOutput := RoundFloat(testInput, 2)
if actualOutput != expectedOutput {
t.Errorf("Test failed. RoundFloat Expected '%f'. Actual '%f'.",
t.Errorf("RoundFloat Expected '%f'. Actual '%f'.",
expectedOutput, actualOutput)
}
}