OSDN Git Service

add TestGetAccountIndex
authorChengcheng Zhang <943420582@qq.com>
Tue, 16 Jul 2019 08:46:30 +0000 (16:46 +0800)
committerChengcheng Zhang <943420582@qq.com>
Tue, 16 Jul 2019 08:46:30 +0000 (16:46 +0800)
database/account_store_test.go

index c6c276f..8d52dcd 100644 (file)
@@ -4,6 +4,11 @@ import (
        "os"
        "testing"
 
+       "github.com/vapor/testutil"
+
+       "github.com/vapor/blockchain/signers"
+       "github.com/vapor/crypto/ed25519/chainkd"
+
        acc "github.com/vapor/account"
        dbm "github.com/vapor/database/leveldb"
        "github.com/vapor/protocol/bc"
@@ -247,3 +252,43 @@ func TestDeleteStandardUTXO(t *testing.T) {
                }
        }
 }
+
+func TestGetAccountIndex(t *testing.T) {
+       testDB := dbm.NewDB("testdb", "leveldb", "temp")
+       defer func() {
+               testDB.Close()
+               os.RemoveAll("temp")
+       }()
+
+       cases := []struct {
+               account      *acc.Account
+               currentIndex uint64
+               want         uint64
+       }{
+               {
+                       account: &acc.Account{
+                               Signer: &signers.Signer{
+                                       XPubs: []chainkd.XPub{
+                                               [64]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, 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},
+                                               [64]byte{0x09, 0x09, 0x09, 0x01, 0x01, 0x00, 0x04, 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, 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},
+                                       },
+                               },
+                       },
+                       currentIndex: uint64(0),
+                       want:         uint64(0),
+               },
+       }
+
+       accountStore := NewAccountStore(testDB)
+       for i, c := range cases {
+               as := accountStore.InitBatch()
+               as.SetAccountIndex(c.account)
+               if err := as.CommitBatch(); err != nil {
+                       t.Fatal(err)
+               }
+               gotIndex := as.GetAccountIndex(c.account.XPubs)
+               if !testutil.DeepEqual(gotIndex, c.want) {
+                       t.Errorf("case %v: got incorrect account index, got: %v, want: %v.", i, gotIndex, c.want)
+               }
+       }
+}