OSDN Git Service

add TestGetBip44ContractIndex
authorChengcheng Zhang <943420582@qq.com>
Tue, 16 Jul 2019 10:32:53 +0000 (18:32 +0800)
committerChengcheng Zhang <943420582@qq.com>
Tue, 16 Jul 2019 10:32:53 +0000 (18:32 +0800)
database/account_store_test.go

index d3185e4..a7827a8 100644 (file)
@@ -357,3 +357,53 @@ func TestGetAccountIndex(t *testing.T) {
                }
        }
 }
+
+func TestGetBip44ContractIndex(t *testing.T) {
+       testDB := dbm.NewDB("testdb", "leveldb", "temp")
+       defer func() {
+               testDB.Close()
+               os.RemoveAll("temp")
+       }()
+
+       cases := []struct {
+               accountID string
+               change    bool
+               index     uint64
+       }{
+               {
+                       accountID: "",
+                       change:    false,
+                       index:     uint64(0),
+               },
+               {
+                       accountID: "account1",
+                       change:    true,
+                       index:     uint64(0),
+               },
+               {
+                       accountID: "account1",
+                       change:    false,
+                       index:     uint64(0),
+               },
+               {
+                       accountID: "account1",
+                       change:    true,
+                       index:     uint64(100),
+               },
+       }
+
+       accountStore := NewAccountStore(testDB)
+       for i, c := range cases {
+               as := accountStore.InitBatch()
+               as.SetBip44ContractIndex(c.accountID, c.change, c.index)
+               if err := as.CommitBatch(); err != nil {
+                       t.Fatal(err)
+               }
+
+               gotIndex := as.GetBip44ContractIndex(c.accountID, c.change)
+               if !testutil.DeepEqual(gotIndex, c.index) {
+                       t.Errorf("case %v: got incorrect bip44 contract index, got: %v, want: %v.", i, gotIndex, c.index)
+               }
+       }
+
+}