OSDN Git Service

add TestGetWalletInfo
authorChengcheng Zhang <943420582@qq.com>
Thu, 18 Jul 2019 06:13:19 +0000 (14:13 +0800)
committerChengcheng Zhang <943420582@qq.com>
Thu, 18 Jul 2019 06:13:19 +0000 (14:13 +0800)
database/wallet_store_test.go

index 6769c2f..7777d81 100644 (file)
@@ -234,7 +234,7 @@ func TestDeleteRecoveryStatus(t *testing.T) {
                }
 
                if !testutil.DeepEqual(gotState, c.state) {
-                       t.Errorf("case %v: got Delete Recovery Status, got: %v, want: %v.", i, gotState, c.state)
+                       t.Errorf("case %v: got recovery status, got: %v, want: %v.", i, gotState, c.state)
                }
 
                ws = walletStore.InitBatch()
@@ -252,3 +252,56 @@ func TestDeleteRecoveryStatus(t *testing.T) {
                os.RemoveAll("temp")
        }
 }
+
+func TestGetWalletInfo(t *testing.T) {
+       cases := []struct {
+               state *wallet.StatusInfo
+       }{
+               {
+                       state: &wallet.StatusInfo{},
+               },
+               {
+                       state: &wallet.StatusInfo{
+                               Version:    uint(0),
+                               WorkHeight: uint64(9),
+                               WorkHash:   bc.NewHash([32]byte{0x01, 0x01, 0x51, 0x31, 0x71, 0x30, 0xd4, 0x3b, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+                               BestHash:   bc.NewHash([32]byte{0x01, 0x01, 0x51, 0x31, 0x71, 0x30, 0xd4, 0x3b, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+                               BestHeight: uint64(0),
+                       },
+               },
+               {
+                       state: &wallet.StatusInfo{
+                               Version:    uint(9),
+                               WorkHeight: uint64(9999999),
+                               WorkHash:   bc.NewHash([32]byte{0x01, 0x01, 0x51, 0x31, 0x71, 0x30, 0xd4, 0x3b, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+                               BestHash:   bc.NewHash([32]byte{0x01, 0x01, 0x51, 0x31, 0x71, 0x30, 0xd4, 0x3b, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c}),
+                               BestHeight: uint64(100000),
+                       },
+               },
+       }
+
+       for i, c := range cases {
+               testDB := dbm.NewDB("testdb", "leveldb", "temp")
+               walletStore := NewWalletStore(testDB)
+               ws := walletStore.InitBatch()
+               if err := ws.SetWalletInfo(c.state); err != nil {
+                       t.Fatal(err)
+               }
+
+               if err := ws.CommitBatch(); err != nil {
+                       t.Fatal(err)
+               }
+
+               gotState, err := ws.GetWalletInfo()
+               if err != nil {
+                       t.Fatal(err)
+               }
+
+               if !testutil.DeepEqual(gotState, c.state) {
+                       t.Errorf("case %v: got wallet info, got: %v, want: %v.", i, gotState, c.state)
+               }
+
+               testDB.Close()
+               os.RemoveAll("temp")
+       }
+}