-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey_modal_test.go
74 lines (53 loc) · 2.04 KB
/
key_modal_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2018 ProximaX Limited. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package crypto
import (
"encoding/hex"
"testing"
"github.com/stretchr/testify/assert"
)
var testPrivatKeyHex = "2275227522752275227522752275227522752275227522752275227522752275"
var testPrivatKeyBytes, _ = hex.DecodeString(testPrivatKeyHex)
func TestNewPrivateKey(t *testing.T) {
val := testPrivatKeyHex
key := NewPrivateKey(testPrivatKeyBytes)
assertPrivateKey(t, key, val)
}
func assertPrivateKey(t *testing.T, key *PrivateKey, val string) {
assert.Equal(t, val, key.String(), `key.Raw and NewBigInteger("%s").Bytes must by equal !`, val)
}
const testHexKeyValue = "227F227F227F227F227F227F227F227F227F227F227F227F227F227F227F227F"
const testHexPrivatKeyWrongLength = "ABC"
const testHexKeyMalformed = "227F227F227F227F227F227F227F227F227F227F227F227F227F227F227FXXXX"
func TestNewPrivatKeyfromHexString_WrongLength(t *testing.T) {
_, err := NewPrivateKeyfromHexString(testHexPrivatKeyWrongLength)
assert.Error(t, err)
}
func TestNewPrivatKeyfromHexString_Malformed(t *testing.T) {
_, err := NewPrivateKeyfromHexString(testHexKeyMalformed)
assert.Error(t, err)
}
// publicKey tests
var (
testHexBytes = []byte{0x22, 0x7f, 0x22, 0x7f, 0x22, 0x7f, 0x22, 0x7f, 0x22, 0x7f, 0x22, 0x7f, 0x22, 0x7f, 0x22, 0x7f, 0x22, 0x7f, 0x22, 0x7f, 0x22, 0x7f, 0x22, 0x7f, 0x22, 0x7f, 0x22, 0x7f, 0x22, 0x7f, 0x22, 0x7f}
)
func TestNewPublicKey(t *testing.T) {
key := NewPublicKey(testHexBytes)
assert.Equal(t, testHexBytes, key.Raw, "not equal")
}
func TestNewPublicKeyfromHex(t *testing.T) {
key, err := NewPublicKeyfromHex(testHexKeyValue)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, testHexBytes, key.Raw, "not equal")
}
func TestNewPublicKeyfromHex_Malformed(t *testing.T) {
_, err := NewPublicKeyfromHex(testHexKeyMalformed)
assert.Error(t, err)
}
func TestPublicKey_String(t *testing.T) {
key := NewPublicKey(testHexBytes)
assert.Equal(t, testHexKeyValue, key.String(), "wrong string")
}