-
Notifications
You must be signed in to change notification settings - Fork 1
/
hash_test.go
42 lines (34 loc) · 992 Bytes
/
hash_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
package go_bitpay_client
import (
"encoding/hex"
"testing"
)
var sampleKey = []byte("02F840A04114081690223B7069071A70D6DABB891763B638CC20C7EC3BD58E6C86")
func TestShaHash(t *testing.T) {
src, dst := sampleKey, make([]byte, 32)
DoubleShaHash(dst, src)
ehash := "eb5b348d7000a12b4de1ef7450b223e47ff7b2716f84e74a7c5816cc300e3300"
hash := hex.EncodeToString(dst)
if ehash != hash {
t.Errorf("got:\n%s\nwanted:\n%s", hash, ehash)
}
}
func TestRimpHash(t *testing.T) {
dst := make([]byte, 20)
src := make([]byte, hex.DecodedLen(len(sampleKey)))
hex.Decode(src, sampleKey)
RimpHash(dst, src)
e := "cb1f4a4d793731842732c153b8e9923bdb462553"
if e != hex.EncodeToString(dst) {
t.Errorf("got:\n%x\nwanted:\n%s", string(dst), e)
}
}
var dhash []byte
func BenchmarkDoubleShaHash(b *testing.B) {
in := []byte("02F840A04114081690223B7069071A70D6DABB891763B638CC20C7EC3BD58E6C86")
test := make([]byte, 32)
for n := 0; n < b.N; n++ {
DoubleShaHash(test, in)
}
dhash = test
}