"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"
}
}
}
+
+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)
+ }
+ }
+}