OSDN Git Service

f2aa94346e33e8b22d0f6702e4f6a23577ee354d
[bytom/vapor.git] / database / wallet_store_test.go
1 package database
2
3 import (
4         "io/ioutil"
5         "os"
6         "reflect"
7         "testing"
8
9         "github.com/vapor/blockchain/pseudohsm"
10         "github.com/vapor/crypto/ed25519/chainkd"
11 )
12
13 func TestAccountIndexKey(t *testing.T) {
14         dirPath, err := ioutil.TempDir(".", "TestAccount")
15         if err != nil {
16                 t.Fatal(err)
17         }
18         defer os.RemoveAll(dirPath)
19
20         hsm, err := pseudohsm.New(dirPath)
21         if err != nil {
22                 t.Fatal(err)
23         }
24
25         xpub1, _, err := hsm.XCreate("TestAccountIndex1", "password", "en")
26         if err != nil {
27                 t.Fatal(err)
28         }
29
30         xpub2, _, err := hsm.XCreate("TestAccountIndex2", "password", "en")
31         if err != nil {
32                 t.Fatal(err)
33         }
34
35         xpubs1 := []chainkd.XPub{xpub1.XPub, xpub2.XPub}
36         xpubs2 := []chainkd.XPub{xpub2.XPub, xpub1.XPub}
37         if !reflect.DeepEqual(accountIndexKey(xpubs1), accountIndexKey(xpubs2)) {
38                 t.Fatal("accountIndexKey test err")
39         }
40
41         if reflect.DeepEqual(xpubs1, xpubs2) {
42                 t.Fatal("accountIndexKey test err")
43         }
44 }