2017-11-04 20:31:37 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
2018-01-12 18:02:15 +00:00
|
|
|
"math"
|
2018-01-12 18:04:20 +00:00
|
|
|
"testing"
|
2017-11-04 20:31:37 +00:00
|
|
|
)
|
|
|
|
|
2018-05-01 01:03:06 +00:00
|
|
|
const (
|
|
|
|
privateKeyFile = "./../testing/private_key"
|
|
|
|
)
|
|
|
|
|
2017-11-04 20:31:37 +00:00
|
|
|
func TestGeneratePrivateKey(t *testing.T) {
|
2017-12-05 19:00:04 +00:00
|
|
|
_, err := GeneratePrivateKey()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error while generating private key: %v", err)
|
|
|
|
}
|
2017-11-04 20:31:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoadPrivateKey(t *testing.T) {
|
2018-05-01 01:03:06 +00:00
|
|
|
_, err := LoadPrivateKeyFromFile(privateKeyFile)
|
2017-12-05 19:00:04 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error while loading private key from file: %v", err)
|
|
|
|
}
|
2017-11-04 20:31:37 +00:00
|
|
|
}
|
2018-01-12 18:02:15 +00:00
|
|
|
|
|
|
|
func TestGetRandNumber(t *testing.T) {
|
2018-01-12 18:04:20 +00:00
|
|
|
num := GetRandNumber()
|
|
|
|
if !num.IsUint64() || num.Uint64() > uint64(math.MaxUint32) {
|
|
|
|
t.Errorf("Error random number outside of expected bounds %v", num)
|
|
|
|
}
|
2018-01-12 18:02:15 +00:00
|
|
|
}
|
2018-05-01 01:03:06 +00:00
|
|
|
|
|
|
|
func TestGetOnionAddress(t *testing.T) {
|
|
|
|
privateKey, _ := LoadPrivateKeyFromFile(privateKeyFile)
|
|
|
|
address, err := GetOnionAddress(privateKey)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Error generating onion address from private key: %v", err)
|
|
|
|
}
|
|
|
|
if address != "kwke2hntvyfqm7dr" {
|
|
|
|
t.Errorf("Error: onion address for private key not expected value")
|
|
|
|
}
|
|
|
|
}
|