-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelper_test.go
56 lines (46 loc) · 1 KB
/
helper_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
package bip32_test
import (
"encoding/hex"
"encoding/json"
"errors"
"os"
"path/filepath"
"testing"
"github.com/sammyne/bip32"
)
type NewMasterKeyGoldie struct {
Seed []byte
KeyID bip32.Magic
PrivKey *bip32.PrivateKey
}
func (goldie *NewMasterKeyGoldie) UnmarshalJSON(data []byte) error {
var elem bip32.Goldie
if err := json.Unmarshal(data, &elem); nil != err {
return err
}
goldie.Seed, _ = hex.DecodeString(elem.Seed)
goldie.KeyID = *bip32.MainNetPrivateKey
for _, c := range elem.Chains {
if "m" == c.Path {
var err error
goldie.PrivKey, err = bip32.ParsePrivateKey(c.ExtendedPrivateKey)
if nil != err {
return err
}
}
}
if nil == goldie.PrivKey {
return errors.New("missing private key")
}
return nil
}
func ReadGoldenJSON(t *testing.T, name string, golden interface{}) {
fd, err := os.Open(filepath.Join(bip32.GoldenBase, name))
if nil != err {
t.Fatal(err)
}
defer fd.Close()
if err := json.NewDecoder(fd).Decode(golden); nil != err {
t.Fatal(err)
}
}