-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsecp256k1_test.go
58 lines (46 loc) · 1.06 KB
/
secp256k1_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
package secp256k1
import (
"crypto/rand"
"fmt"
"io"
"testing"
"github.com/stretchr/testify/assert"
)
func testingRand32() [32]byte {
key := [32]byte{}
_, err := io.ReadFull(rand.Reader, key[:])
if err != nil {
panic(err)
}
return key
}
func testingRand(n int) []byte {
key := make([]byte, n)
_, err := io.ReadFull(rand.Reader, key[:])
if err != nil {
panic(err)
}
return key
}
func TestRand256(t *testing.T) {
rnd := [2][32]byte{Random256(), Random256()}
fmt.Printf("Random256(): %x\nRandom256(): %x\n", rnd[0], rnd[1])
assert.NotEmpty(t, rnd[0][:])
assert.NotEmpty(t, rnd[1][:])
assert.NotEqual(t, rnd[0], rnd[1])
}
func Test_ContextCreate1(t *testing.T) {
params := uint(ContextSign | ContextVerify)
ctx, err := ContextCreate(params)
assert.NoError(t, err)
assert.NotNil(t, ctx)
assert.IsType(t, Context{}, *ctx)
clone, err := ContextClone(ctx)
assert.NoError(t, err)
assert.NotNil(t, ctx)
assert.IsType(t, Context{}, *ctx)
ContextDestroy(clone)
res := ContextRandomize(ctx, testingRand32())
assert.Equal(t, 1, res)
ContextDestroy(ctx)
}