OSDN Git Service

add TestGetCoinbaseArbitrary
[bytom/vapor.git] / database / account_store_test.go
1 package database
2
3 import (
4         "os"
5         "testing"
6
7         "github.com/vapor/common"
8         "github.com/vapor/testutil"
9
10         "github.com/vapor/blockchain/signers"
11         "github.com/vapor/crypto/ed25519/chainkd"
12
13         acc "github.com/vapor/account"
14         dbm "github.com/vapor/database/leveldb"
15         "github.com/vapor/protocol/bc"
16 )
17
18 func TestDeleteAccount(t *testing.T) {
19         testDB := dbm.NewDB("testdb", "leveldb", "temp")
20         defer func() {
21                 testDB.Close()
22                 os.RemoveAll("temp")
23         }()
24
25         cases := []struct {
26                 accounts      []*acc.Account
27                 deleteAccount *acc.Account
28                 want          []*acc.Account
29         }{
30                 {
31                         accounts:      []*acc.Account{},
32                         deleteAccount: &acc.Account{},
33                         want:          []*acc.Account{},
34                 },
35                 {
36                         accounts: []*acc.Account{},
37                         deleteAccount: &acc.Account{
38                                 ID:    "id-1",
39                                 Alias: "alias-1",
40                         },
41                         want: []*acc.Account{},
42                 },
43                 {
44                         accounts: []*acc.Account{
45                                 &acc.Account{
46                                         ID:    "id-1",
47                                         Alias: "alias-1",
48                                 },
49                                 &acc.Account{
50                                         ID:    "id-2",
51                                         Alias: "alias-2",
52                                 },
53                         },
54                         deleteAccount: &acc.Account{},
55                         want: []*acc.Account{
56                                 &acc.Account{
57                                         ID:    "id-1",
58                                         Alias: "alias-1",
59                                 },
60                                 &acc.Account{
61                                         ID:    "id-2",
62                                         Alias: "alias-2",
63                                 },
64                         },
65                 },
66                 {
67                         accounts: []*acc.Account{
68                                 &acc.Account{
69                                         ID:    "id-1",
70                                         Alias: "alias-1",
71                                 },
72                                 &acc.Account{
73                                         ID:    "id-2",
74                                         Alias: "alias-2",
75                                 },
76                         },
77                         deleteAccount: &acc.Account{
78                                 ID:    "id-3",
79                                 Alias: "alias-3",
80                         },
81                         want: []*acc.Account{
82                                 &acc.Account{
83                                         ID:    "id-1",
84                                         Alias: "alias-1",
85                                 },
86                                 &acc.Account{
87                                         ID:    "id-2",
88                                         Alias: "alias-2",
89                                 },
90                         },
91                 },
92                 {
93                         accounts: []*acc.Account{
94                                 &acc.Account{
95                                         ID:    "id-1",
96                                         Alias: "alias-1",
97                                 },
98                                 &acc.Account{
99                                         ID:    "id-2",
100                                         Alias: "alias-2",
101                                 },
102                         },
103                         deleteAccount: &acc.Account{
104                                 ID:    "id-1",
105                                 Alias: "alias-1",
106                         },
107                         want: []*acc.Account{
108                                 &acc.Account{
109                                         ID:    "id-2",
110                                         Alias: "alias-2",
111                                 },
112                         },
113                 },
114         }
115
116         accountStore := NewAccountStore(testDB)
117         for i, c := range cases {
118                 as := accountStore.InitBatch()
119                 // store mock accounts
120                 for _, a := range c.accounts {
121                         if err := as.SetAccount(a); err != nil {
122                                 t.Fatal(err)
123                         }
124                 }
125
126                 // delete account
127                 if err := as.DeleteAccount(c.deleteAccount); err != nil {
128                         t.Fatal(err)
129                 }
130
131                 if err := as.CommitBatch(); err != nil {
132                         t.Fatal(err)
133                 }
134
135                 // get account by deleteAccount.ID, it should print ErrFindAccount
136                 if _, err := as.GetAccountByID(c.deleteAccount.ID); err != acc.ErrFindAccount {
137                         t.Fatal(err)
138                 }
139
140                 for _, a := range c.want {
141                         if _, err := as.GetAccountByID(a.ID); err != nil {
142                                 t.Errorf("case %v: cann't find account, err: %v", i, err)
143                         }
144
145                         if _, err := as.GetAccountByAlias(a.Alias); err != nil {
146                                 t.Errorf("case %v: cann't find account, err: %v", i, err)
147                         }
148                 }
149         }
150 }
151
152 func TestDeleteStandardUTXO(t *testing.T) {
153         testDB := dbm.NewDB("testdb", "leveldb", "temp")
154         defer func() {
155                 testDB.Close()
156                 os.RemoveAll("temp")
157         }()
158
159         cases := []struct {
160                 utxos      []*acc.UTXO
161                 deleteUTXO *acc.UTXO
162                 want       []*acc.UTXO
163         }{
164                 {
165                         utxos:      []*acc.UTXO{},
166                         deleteUTXO: &acc.UTXO{},
167                         want:       []*acc.UTXO{},
168                 },
169                 {
170                         utxos: []*acc.UTXO{
171                                 &acc.UTXO{
172                                         OutputID: bc.NewHash([32]byte{0x3e, 0x94, 0x5d, 0x35, 0x70, 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}),
173                                 },
174                         },
175                         deleteUTXO: &acc.UTXO{
176                                 OutputID: bc.NewHash([32]byte{0x3e, 0x94, 0x5d, 0x35, 0x70, 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}),
177                         },
178                         want: []*acc.UTXO{},
179                 },
180                 {
181                         utxos: []*acc.UTXO{
182                                 &acc.UTXO{
183                                         OutputID: bc.NewHash([32]byte{0x3e, 0x94, 0x5d, 0x35, 0x70, 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}),
184                                 },
185                         },
186                         deleteUTXO: &acc.UTXO{},
187                         want: []*acc.UTXO{
188                                 &acc.UTXO{
189                                         OutputID: bc.NewHash([32]byte{0x3e, 0x94, 0x5d, 0x35, 0x70, 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}),
190                                 },
191                         },
192                 },
193                 {
194                         utxos: []*acc.UTXO{},
195                         deleteUTXO: &acc.UTXO{
196                                 OutputID: bc.NewHash([32]byte{0x3e, 0x94, 0x5d, 0x35, 0x70, 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}),
197                         },
198                         want: []*acc.UTXO{},
199                 },
200                 {
201                         utxos: []*acc.UTXO{
202                                 &acc.UTXO{
203                                         OutputID: bc.NewHash([32]byte{0x0e, 0x04, 0x50, 0x35, 0x70, 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}),
204                                 },
205                                 &acc.UTXO{
206                                         OutputID: bc.NewHash([32]byte{0x00, 0x01, 0x02, 0x35, 0x70, 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}),
207                                 },
208                                 &acc.UTXO{
209                                         OutputID: 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}),
210                                 },
211                                 &acc.UTXO{
212                                         OutputID: bc.NewHash([32]byte{0x01, 0x01, 0x02, 0x39, 0x70, 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}),
213                                 },
214                         },
215                         deleteUTXO: &acc.UTXO{
216                                 OutputID: bc.NewHash([32]byte{0x01, 0x01, 0x02, 0x39, 0x70, 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}),
217                         },
218                         want: []*acc.UTXO{
219                                 &acc.UTXO{
220                                         OutputID: bc.NewHash([32]byte{0x0e, 0x04, 0x50, 0x35, 0x70, 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}),
221                                 },
222                                 &acc.UTXO{
223                                         OutputID: bc.NewHash([32]byte{0x00, 0x01, 0x02, 0x35, 0x70, 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}),
224                                 },
225                                 &acc.UTXO{
226                                         OutputID: 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}),
227                                 },
228                         },
229                 },
230         }
231
232         accountStore := NewAccountStore(testDB)
233         for _, c := range cases {
234                 as := accountStore.InitBatch()
235                 // store mock utxos
236                 for _, utxo := range c.utxos {
237                         if err := as.SetStandardUTXO(utxo.OutputID, utxo); err != nil {
238                                 t.Fatal(err)
239                         }
240                 }
241
242                 // delete utxo
243                 as.DeleteStandardUTXO(c.deleteUTXO.OutputID)
244                 if err := as.CommitBatch(); err != nil {
245                         t.Fatal(err)
246                 }
247
248                 // get utxo by outputID
249                 for _, utxo := range c.want {
250                         if _, err := as.GetUTXO(utxo.OutputID); err != nil {
251                                 t.Fatal(err)
252                         }
253                 }
254         }
255 }
256
257 func TestGetAccountIndex(t *testing.T) {
258         testDB := dbm.NewDB("testdb", "leveldb", "temp")
259         defer func() {
260                 testDB.Close()
261                 os.RemoveAll("temp")
262         }()
263
264         cases := []struct {
265                 account      *acc.Account
266                 currentIndex uint64
267                 want         uint64
268         }{
269                 {
270                         account: &acc.Account{
271                                 Signer: &signers.Signer{
272                                         XPubs: []chainkd.XPub{
273                                                 [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},
274                                                 [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},
275                                         },
276                                         KeyIndex: uint64(0),
277                                 },
278                         },
279                         currentIndex: uint64(0),
280                         want:         uint64(0),
281                 },
282                 {
283                         account: &acc.Account{
284                                 Signer: &signers.Signer{
285                                         XPubs: []chainkd.XPub{
286                                                 [64]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 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},
287                                                 [64]byte{0x00, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 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},
288                                         },
289                                         KeyIndex: uint64(1),
290                                 },
291                         },
292                         currentIndex: uint64(1),
293                         want:         uint64(1),
294                 },
295                 {
296                         account: &acc.Account{
297                                 Signer: &signers.Signer{
298                                         XPubs: []chainkd.XPub{
299                                                 [64]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 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},
300                                                 [64]byte{0x00, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 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},
301                                         },
302                                         KeyIndex: uint64(9),
303                                 },
304                         },
305                         currentIndex: uint64(1),
306                         want:         uint64(9),
307                 },
308                 {
309                         account: &acc.Account{
310                                 Signer: &signers.Signer{
311                                         XPubs: []chainkd.XPub{
312                                                 [64]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 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},
313                                                 [64]byte{0x00, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 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},
314                                         },
315                                         KeyIndex: uint64(10),
316                                 },
317                         },
318                         currentIndex: uint64(88),
319                         want:         uint64(88),
320                 },
321                 {
322                         account: &acc.Account{
323                                 Signer: &signers.Signer{
324                                         XPubs:    []chainkd.XPub{},
325                                         KeyIndex: uint64(0),
326                                 },
327                         },
328                         currentIndex: uint64(0),
329                         want:         uint64(0),
330                 },
331                 {
332                         account: &acc.Account{
333                                 Signer: &signers.Signer{
334                                         XPubs: []chainkd.XPub{
335                                                 [64]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 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},
336                                         },
337                                         KeyIndex: uint64(1),
338                                 },
339                         },
340                         currentIndex: uint64(77),
341                         want:         uint64(77),
342                 },
343         }
344
345         accountStore := NewAccountStore(testDB)
346         for i, c := range cases {
347                 as := accountStore.InitBatch()
348                 v := as.(*AccountStore)
349                 v.db.Set(accountIndexKey(c.account.XPubs), common.Unit64ToBytes(c.currentIndex))
350                 as.SetAccountIndex(c.account)
351                 if err := as.CommitBatch(); err != nil {
352                         t.Fatal(err)
353                 }
354                 gotIndex := as.GetAccountIndex(c.account.XPubs)
355                 if !testutil.DeepEqual(gotIndex, c.want) {
356                         t.Errorf("case %v: got incorrect account index, got: %v, want: %v.", i, gotIndex, c.want)
357                 }
358         }
359 }
360
361 func TestGetBip44ContractIndex(t *testing.T) {
362         testDB := dbm.NewDB("testdb", "leveldb", "temp")
363         defer func() {
364                 testDB.Close()
365                 os.RemoveAll("temp")
366         }()
367
368         cases := []struct {
369                 accountID string
370                 change    bool
371                 index     uint64
372         }{
373                 {
374                         accountID: "",
375                         change:    false,
376                         index:     uint64(0),
377                 },
378                 {
379                         accountID: "account1",
380                         change:    true,
381                         index:     uint64(0),
382                 },
383                 {
384                         accountID: "account1",
385                         change:    false,
386                         index:     uint64(0),
387                 },
388                 {
389                         accountID: "account1",
390                         change:    true,
391                         index:     uint64(100),
392                 },
393         }
394
395         accountStore := NewAccountStore(testDB)
396         for i, c := range cases {
397                 as := accountStore.InitBatch()
398                 as.SetBip44ContractIndex(c.accountID, c.change, c.index)
399                 if err := as.CommitBatch(); err != nil {
400                         t.Fatal(err)
401                 }
402
403                 gotIndex := as.GetBip44ContractIndex(c.accountID, c.change)
404                 if !testutil.DeepEqual(gotIndex, c.index) {
405                         t.Errorf("case %v: got incorrect bip44 contract index, got: %v, want: %v.", i, gotIndex, c.index)
406                 }
407         }
408 }
409
410 func TestGetCoinbaseArbitrary(t *testing.T) {
411         testDB := dbm.NewDB("testdb", "leveldb", "temp")
412         defer func() {
413                 testDB.Close()
414                 os.RemoveAll("temp")
415         }()
416
417         cases := []struct {
418                 arbitrary []byte
419         }{
420                 {
421                         arbitrary: []byte{},
422                 },
423                 {
424                         arbitrary: []byte("test arbitrary"),
425                 },
426                 {
427                         arbitrary: []byte("test arbitrary test arbitrary test arbitrary test arbitrary test arbitrary"),
428                 },
429         }
430
431         accountStore := NewAccountStore(testDB)
432         for i, c := range cases {
433                 as := accountStore.InitBatch()
434                 as.SetCoinbaseArbitrary(c.arbitrary)
435                 if err := as.CommitBatch(); err != nil {
436                         t.Fatal(err)
437                 }
438
439                 gotArbitrary := as.GetCoinbaseArbitrary()
440                 if !testutil.DeepEqual(gotArbitrary, c.arbitrary) {
441                         t.Errorf("case %v: got incorrect arbitrary, got: %v, want: %v.", i, gotArbitrary, c.arbitrary)
442                 }
443         }
444 }