keva-stratum/util/util_test.go

34 lines
681 B
Go
Raw Normal View History

2015-07-05 14:49:07 +05:00
package util
import (
"encoding/hex"
"math/big"
"testing"
)
func TestGetTargetHex(t *testing.T) {
2016-12-08 02:35:16 +05:00
targetHex := GetTargetHex(500)
2015-07-05 14:49:07 +05:00
expectedHex := "6e128300"
if targetHex != expectedHex {
t.Error("Invalid targetHex")
}
2016-12-08 02:35:16 +05:00
targetHex = GetTargetHex(15000)
2015-07-05 14:49:07 +05:00
expectedHex = "7b5e0400"
if targetHex != expectedHex {
t.Error("Invalid targetHex")
}
}
func TestGetHashDifficulty(t *testing.T) {
hash := "8e3c1865f22801dc3df0a688da80701e2390e7838e65c142604cc00eafe34000"
hashBytes, _ := hex.DecodeString(hash)
diff := new(big.Int)
diff.SetBytes(reverse(hashBytes))
shareDiff := GetHashDifficulty(hashBytes)
if shareDiff.String() != "1009" {
t.Error("Invalid diff")
}
}