OSDN Git Service

Wallet store interface (#217)
[bytom/vapor.git] / database / wallet_store_test.go
diff --git a/database/wallet_store_test.go b/database/wallet_store_test.go
new file mode 100644 (file)
index 0000000..f2aa943
--- /dev/null
@@ -0,0 +1,44 @@
+package database
+
+import (
+       "io/ioutil"
+       "os"
+       "reflect"
+       "testing"
+
+       "github.com/vapor/blockchain/pseudohsm"
+       "github.com/vapor/crypto/ed25519/chainkd"
+)
+
+func TestAccountIndexKey(t *testing.T) {
+       dirPath, err := ioutil.TempDir(".", "TestAccount")
+       if err != nil {
+               t.Fatal(err)
+       }
+       defer os.RemoveAll(dirPath)
+
+       hsm, err := pseudohsm.New(dirPath)
+       if err != nil {
+               t.Fatal(err)
+       }
+
+       xpub1, _, err := hsm.XCreate("TestAccountIndex1", "password", "en")
+       if err != nil {
+               t.Fatal(err)
+       }
+
+       xpub2, _, err := hsm.XCreate("TestAccountIndex2", "password", "en")
+       if err != nil {
+               t.Fatal(err)
+       }
+
+       xpubs1 := []chainkd.XPub{xpub1.XPub, xpub2.XPub}
+       xpubs2 := []chainkd.XPub{xpub2.XPub, xpub1.XPub}
+       if !reflect.DeepEqual(accountIndexKey(xpubs1), accountIndexKey(xpubs2)) {
+               t.Fatal("accountIndexKey test err")
+       }
+
+       if reflect.DeepEqual(xpubs1, xpubs2) {
+               t.Fatal("accountIndexKey test err")
+       }
+}