-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbase_test.go
49 lines (41 loc) · 1.15 KB
/
base_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
package secp256k1
import (
"fmt"
"github.com/stretchr/testify/assert"
"io/ioutil"
"strings"
"testing"
)
const (
EcdsaTestVectors = "sign_vectors.yaml"
PubkeyCreateTestVectors = "pubkey_vectors.yaml"
PubkeyTweakAddTestVectors = "pubkey_tweak_add_vectors.yaml"
PubkeyTweakMulTestVectors = "pubkey_tweak_mul_vectors.yaml"
PrivkeyTweakAddTestVectors = "privkey_tweak_add_vectors.yaml"
PrivkeyTweakMulTestVectors = "privkey_tweak_mul_vectors.yaml"
TestCaseFmt = "Test case %d"
)
func desc(i int) string {
return fmt.Sprintf(TestCaseFmt, i)
}
func spOK(t *testing.T, result int, err error) {
assert.NoError(t, err)
assert.Equal(t, 1, result)
}
func readFile(filename string) []byte {
source, err := ioutil.ReadFile(filename)
if err != nil {
panic(err)
}
return source
}
func removeSigHash(sig string) string {
return strings.TrimSuffix(sig, "01")
}
func assertCanReadAndWritePublicKey(t *testing.T, ctx *Context, pkBytes []byte, flag uint) {
r, pubkey, err := EcPubkeyParse(ctx, pkBytes)
spOK(t, r, err)
r, serialized, err := EcPubkeySerialize(ctx, pubkey, flag)
spOK(t, r, err)
assert.Equal(t, pkBytes, serialized)
}