keva-stratum/util/util_test.go

41 lines
857 B
Go
Raw Normal View History

2015-07-05 09:49:07 +00:00
package util
import (
"encoding/hex"
"testing"
)
func TestGetTargetHex(t *testing.T) {
2016-12-07 21:35:16 +00:00
targetHex := GetTargetHex(500)
2015-07-05 09:49:07 +00:00
expectedHex := "6e128300"
if targetHex != expectedHex {
t.Error("Invalid targetHex")
}
2016-12-07 21:35:16 +00:00
targetHex = GetTargetHex(15000)
2015-07-05 09:49:07 +00:00
expectedHex = "7b5e0400"
if targetHex != expectedHex {
t.Error("Invalid targetHex")
}
}
func TestGetHashDifficulty(t *testing.T) {
hash := "8e3c1865f22801dc3df0a688da80701e2390e7838e65c142604cc00eafe34000"
hashBytes, _ := hex.DecodeString(hash)
2018-02-10 00:08:43 +00:00
shareDiff, ok := GetHashDifficulty(hashBytes)
2015-07-05 09:49:07 +00:00
2018-02-10 00:08:43 +00:00
if !ok && shareDiff.String() != "1009" {
2015-07-05 09:49:07 +00:00
t.Error("Invalid diff")
}
}
2018-02-10 00:08:43 +00:00
2018-03-14 16:28:07 +00:00
func TestGetHashDifficultyWithBrokenHash(t *testing.T) {
2018-02-10 00:08:43 +00:00
hash := ""
hashBytes, _ := hex.DecodeString(hash)
shareDiff, ok := GetHashDifficulty(hashBytes)
if ok || shareDiff != nil {
t.Error("Must be no result and not ok")
}
}