-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkeystore_test.go
47 lines (38 loc) · 1011 Bytes
/
keystore_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
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"testing"
"github.com/ethereum/go-ethereum/accounts/keystore"
)
func createKs() {
ks := keystore.NewKeyStore("./tmp", keystore.StandardScryptN, keystore.StandardScryptP)
password := "secret"
account, err := ks.NewAccount(password)
if err != nil {
log.Fatal(err)
}
fmt.Println(account.Address.Hex()) // 0x20F8D42FB0F667F2E53930fed426f225752453b3
}
func importKs() {
file := "./tmp/UTC--2018-07-04T09-58-30.122808598Z--20f8d42fb0f667f2e53930fed426f225752453b3"
ks := keystore.NewKeyStore("./tmp", keystore.StandardScryptN, keystore.StandardScryptP)
jsonBytes, err := ioutil.ReadFile(file)
if err != nil {
log.Fatal(err)
}
password := "secret"
account, err := ks.Import(jsonBytes, password, password)
if err != nil {
log.Fatal(err)
}
fmt.Println(account.Address.Hex()) // 0x20F8D42FB0F667F2E53930fed426f225752453b3
if err := os.Remove(file); err != nil {
log.Fatal(err)
}
}
func TestKeyStore(t *testing.T) {
createKs()
}