neoneo-go/pkg/core/random_util_test.go
Roman Khimov ec7e17ffa6 pkg: make use of the new crypto/hash package
Simplifies a lot of code and removes some duplication. Unfortunately I had to
move test_util random functions in same commit to avoid cycle
dependencies. One of these random functions was also used in core/transaction
testing, to simplify things I've just dropped it there and used a static
string (which is nice to have for a test anyway).

There is still sha256 left in wallet (but it needs to pass Hash structure into
the signing function).
2019-08-26 13:32:19 +03:00

40 lines
806 B
Go

package core
import (
"math/rand"
"time"
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
"github.com/CityOfZion/neo-go/pkg/util"
)
// RandomString returns a random string with the n as its length.
func randomString(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = byte(randomInt(65, 90))
}
return string(b)
}
// RandomInt returns a random integer between min and max.
func randomInt(min, max int) int {
return min + rand.Intn(max-min)
}
// RandomUint256 returns a random Uint256.
func randomUint256() util.Uint256 {
str := randomString(20)
return hash.Sha256([]byte(str))
}
// RandomUint160 returns a random Uint160.
func randomUint160() util.Uint160 {
str := randomString(20)
return hash.RipeMD160([]byte(str))
}
func init() {
rand.Seed(time.Now().UTC().UnixNano())
}