OSDN Git Service

init push for spend 0 confirm utxo (#1112)
[bytom/bytom.git] / wallet / utxo_test.go
1 package wallet
2
3 import (
4         "encoding/hex"
5         "encoding/json"
6         "fmt"
7         "os"
8         "sort"
9         "testing"
10
11         dbm "github.com/tendermint/tmlibs/db"
12
13         "github.com/bytom/account"
14         "github.com/bytom/consensus"
15         "github.com/bytom/protocol/bc"
16         "github.com/bytom/protocol/bc/types"
17         "github.com/bytom/testutil"
18 )
19
20 func TestGetAccountUtxos(t *testing.T) {
21         testDB := dbm.NewDB("testdb", "leveldb", "temp")
22         defer os.RemoveAll("temp")
23
24         cases := []struct {
25                 dbUtxos         map[string]*account.UTXO
26                 id              string
27                 isSmartContract bool
28                 wantUtxos       []*account.UTXO
29         }{
30                 {
31                         dbUtxos:         map[string]*account.UTXO{},
32                         id:              "",
33                         isSmartContract: false,
34                         wantUtxos:       []*account.UTXO{},
35                 },
36                 {
37                         dbUtxos: map[string]*account.UTXO{
38                                 string(account.StandardUTXOKey(bc.Hash{V0: 1})): &account.UTXO{
39                                         OutputID: bc.Hash{V0: 1},
40                                 },
41                                 string(account.StandardUTXOKey(bc.Hash{V0: 2})): &account.UTXO{
42                                         OutputID: bc.Hash{V0: 2},
43                                 },
44                                 string(account.StandardUTXOKey(bc.Hash{V0: 3})): &account.UTXO{
45                                         OutputID: bc.Hash{V0: 3},
46                                 },
47                                 string(account.ContractUTXOKey(bc.Hash{V0: 4})): &account.UTXO{
48                                         OutputID: bc.Hash{V0: 4},
49                                 },
50                         },
51                         id:              "",
52                         isSmartContract: false,
53                         wantUtxos: []*account.UTXO{
54                                 &account.UTXO{OutputID: bc.Hash{V0: 1}},
55                                 &account.UTXO{OutputID: bc.Hash{V0: 2}},
56                                 &account.UTXO{OutputID: bc.Hash{V0: 3}},
57                         },
58                 },
59                 {
60                         dbUtxos: map[string]*account.UTXO{
61                                 string(account.StandardUTXOKey(bc.Hash{V0: 1})): &account.UTXO{
62                                         OutputID: bc.Hash{V0: 1},
63                                 },
64                                 string(account.StandardUTXOKey(bc.Hash{V0: 2})): &account.UTXO{
65                                         OutputID: bc.Hash{V0: 2},
66                                 },
67                                 string(account.StandardUTXOKey(bc.Hash{V0: 3})): &account.UTXO{
68                                         OutputID: bc.Hash{V0: 3},
69                                 },
70                                 string(account.ContractUTXOKey(bc.Hash{V0: 4})): &account.UTXO{
71                                         OutputID: bc.Hash{V0: 4},
72                                 },
73                         },
74                         id:              "",
75                         isSmartContract: true,
76                         wantUtxos: []*account.UTXO{
77                                 &account.UTXO{OutputID: bc.Hash{V0: 4}},
78                         },
79                 },
80                 {
81                         dbUtxos: map[string]*account.UTXO{
82                                 string(account.StandardUTXOKey(bc.Hash{V0: 1})): &account.UTXO{
83                                         OutputID: bc.Hash{V0: 1},
84                                 },
85                                 string(account.StandardUTXOKey(bc.Hash{V0: 1, V1: 2})): &account.UTXO{
86                                         OutputID: bc.Hash{V0: 1, V1: 2},
87                                 },
88                                 string(account.StandardUTXOKey(bc.Hash{V0: 2})): &account.UTXO{
89                                         OutputID: bc.Hash{V0: 2},
90                                 },
91                                 string(account.StandardUTXOKey(bc.Hash{V0: 2, V1: 2})): &account.UTXO{
92                                         OutputID: bc.Hash{V0: 2, V1: 2},
93                                 },
94                         },
95                         id:              "0000000000000002",
96                         isSmartContract: false,
97                         wantUtxos: []*account.UTXO{
98                                 &account.UTXO{OutputID: bc.Hash{V0: 2}},
99                                 &account.UTXO{OutputID: bc.Hash{V0: 2, V1: 2}},
100                         },
101                 },
102         }
103
104         w := &Wallet{DB: testDB}
105         for i, c := range cases {
106                 for k, u := range c.dbUtxos {
107                         data, err := json.Marshal(u)
108                         if err != nil {
109                                 t.Error(err)
110                         }
111                         testDB.Set([]byte(k), data)
112                 }
113
114                 gotUtxos := w.GetAccountUtxos(c.id, c.isSmartContract)
115                 if !testutil.DeepEqual(gotUtxos, c.wantUtxos) {
116                         t.Errorf("case %d: got %v want %v", i, gotUtxos, c.wantUtxos)
117                 }
118
119                 for k := range c.dbUtxos {
120                         testDB.Delete([]byte(k))
121                 }
122         }
123 }
124
125 func TestFilterAccountUtxo(t *testing.T) {
126         testDB := dbm.NewDB("testdb", "leveldb", "temp")
127         defer os.RemoveAll("temp")
128
129         cases := []struct {
130                 dbPrograms map[string]*account.CtrlProgram
131                 input      []*account.UTXO
132                 wantUtxos  []*account.UTXO
133         }{
134                 {
135                         dbPrograms: map[string]*account.CtrlProgram{},
136                         input:      []*account.UTXO{},
137                         wantUtxos:  []*account.UTXO{},
138                 },
139                 {
140                         dbPrograms: map[string]*account.CtrlProgram{
141                                 "436f6e74726163743a2a37a64a4e15a772ab43bf3f5956d0d1f353946496788e7f40d0ff1796286a6f": &account.CtrlProgram{
142                                         AccountID: "testAccount",
143                                         Address:   "testAddress",
144                                         KeyIndex:  53,
145                                         Change:    true,
146                                 },
147                         },
148                         input: []*account.UTXO{
149                                 &account.UTXO{
150                                         ControlProgram: []byte{0x00, 0x14, 0x62, 0x50, 0x18, 0xb6, 0x85, 0x77, 0xba, 0x9b, 0x26, 0x19, 0xc8, 0x1d, 0x2e, 0x96, 0xba, 0x22, 0xbe, 0x77, 0x77, 0xd7},
151                                         AssetID:        bc.AssetID{V0: 1},
152                                         Amount:         3,
153                                 },
154                                 &account.UTXO{
155                                         ControlProgram: []byte{0x91},
156                                         AssetID:        bc.AssetID{V0: 1},
157                                         Amount:         4,
158                                 },
159                         },
160                         wantUtxos: []*account.UTXO{
161                                 &account.UTXO{
162                                         ControlProgram:      []byte{0x00, 0x14, 0x62, 0x50, 0x18, 0xb6, 0x85, 0x77, 0xba, 0x9b, 0x26, 0x19, 0xc8, 0x1d, 0x2e, 0x96, 0xba, 0x22, 0xbe, 0x77, 0x77, 0xd7},
163                                         AssetID:             bc.AssetID{V0: 1},
164                                         Amount:              3,
165                                         AccountID:           "testAccount",
166                                         Address:             "testAddress",
167                                         ControlProgramIndex: 53,
168                                         Change:              true,
169                                 },
170                                 &account.UTXO{
171                                         ControlProgram: []byte{0x91},
172                                         AssetID:        bc.AssetID{V0: 1},
173                                         Amount:         4,
174                                 },
175                         },
176                 },
177                 {
178                         dbPrograms: map[string]*account.CtrlProgram{},
179                         input: []*account.UTXO{
180                                 &account.UTXO{
181                                         ControlProgram: []byte{0x00, 0x14, 0x62, 0x50, 0x18, 0xb6, 0x85, 0x77, 0xba, 0x9b, 0x26, 0x19, 0xc8, 0x1d, 0x2e, 0x96, 0xba, 0x22, 0xbe, 0x77, 0x77, 0xd7},
182                                         AssetID:        bc.AssetID{V0: 1},
183                                         Amount:         3,
184                                 },
185                                 &account.UTXO{
186                                         ControlProgram: []byte{0x91},
187                                         AssetID:        bc.AssetID{V0: 1},
188                                         Amount:         3,
189                                 },
190                         },
191                         wantUtxos: []*account.UTXO{
192                                 &account.UTXO{
193                                         ControlProgram: []byte{0x91},
194                                         AssetID:        bc.AssetID{V0: 1},
195                                         Amount:         3,
196                                 },
197                         },
198                 },
199                 {
200                         dbPrograms: map[string]*account.CtrlProgram{
201                                 "436f6e74726163743a2a37a64a4e15a772ab43bf3f5956d0d1f353946496788e7f40d0ff1796286a6f": &account.CtrlProgram{
202                                         AccountID: "testAccount",
203                                         Address:   "testAddress",
204                                         KeyIndex:  53,
205                                         Change:    true,
206                                 },
207                                 "436f6e74726163743adb4d86262c12ba70d50b3ca3ae102d5682436243bd1e8c79569603f75675036a": &account.CtrlProgram{
208                                         AccountID: "testAccount2",
209                                         Address:   "testAddress2",
210                                         KeyIndex:  72,
211                                         Change:    false,
212                                 },
213                         },
214                         input: []*account.UTXO{
215                                 &account.UTXO{
216                                         ControlProgram: []byte{0x00, 0x14, 0x62, 0x50, 0x18, 0xb6, 0x85, 0x77, 0xba, 0x9b, 0x26, 0x19, 0xc8, 0x1d, 0x2e, 0x96, 0xba, 0x22, 0xbe, 0x77, 0x77, 0xd7},
217                                         AssetID:        bc.AssetID{V0: 1},
218                                         Amount:         3,
219                                 },
220                                 &account.UTXO{
221                                         ControlProgram: []byte{0x00, 0x14, 0x62, 0x50, 0x18, 0xb6, 0x85, 0x77, 0xba, 0x9b, 0x26, 0x19, 0xc8, 0x1d, 0x2e, 0x96, 0xba, 0x22, 0xbe, 0x77, 0x77, 0xd7},
222                                         AssetID:        bc.AssetID{V0: 1},
223                                         Amount:         5,
224                                 },
225                                 &account.UTXO{
226                                         ControlProgram: []byte{0x00, 0x14, 0xc6, 0xbf, 0x22, 0x19, 0x64, 0x2a, 0xc5, 0x9e, 0x5b, 0xe4, 0xeb, 0xdf, 0x5b, 0x22, 0x49, 0x56, 0xa7, 0x98, 0xa4, 0xdf},
227                                         AssetID:        bc.AssetID{V0: 1},
228                                         Amount:         7,
229                                 },
230                         },
231                         wantUtxos: []*account.UTXO{
232                                 &account.UTXO{
233                                         ControlProgram:      []byte{0x00, 0x14, 0x62, 0x50, 0x18, 0xb6, 0x85, 0x77, 0xba, 0x9b, 0x26, 0x19, 0xc8, 0x1d, 0x2e, 0x96, 0xba, 0x22, 0xbe, 0x77, 0x77, 0xd7},
234                                         AssetID:             bc.AssetID{V0: 1},
235                                         Amount:              3,
236                                         AccountID:           "testAccount",
237                                         Address:             "testAddress",
238                                         ControlProgramIndex: 53,
239                                         Change:              true,
240                                 },
241                                 &account.UTXO{
242                                         ControlProgram:      []byte{0x00, 0x14, 0x62, 0x50, 0x18, 0xb6, 0x85, 0x77, 0xba, 0x9b, 0x26, 0x19, 0xc8, 0x1d, 0x2e, 0x96, 0xba, 0x22, 0xbe, 0x77, 0x77, 0xd7},
243                                         AssetID:             bc.AssetID{V0: 1},
244                                         Amount:              5,
245                                         AccountID:           "testAccount",
246                                         Address:             "testAddress",
247                                         ControlProgramIndex: 53,
248                                         Change:              true,
249                                 },
250                                 &account.UTXO{
251                                         ControlProgram:      []byte{0x00, 0x14, 0xc6, 0xbf, 0x22, 0x19, 0x64, 0x2a, 0xc5, 0x9e, 0x5b, 0xe4, 0xeb, 0xdf, 0x5b, 0x22, 0x49, 0x56, 0xa7, 0x98, 0xa4, 0xdf},
252                                         AssetID:             bc.AssetID{V0: 1},
253                                         Amount:              7,
254                                         AccountID:           "testAccount2",
255                                         Address:             "testAddress2",
256                                         ControlProgramIndex: 72,
257                                         Change:              false,
258                                 },
259                         },
260                 },
261         }
262
263         w := &Wallet{DB: testDB}
264         for i, c := range cases {
265                 for s, p := range c.dbPrograms {
266                         data, err := json.Marshal(p)
267                         if err != nil {
268                                 t.Error(err)
269                         }
270                         key, err := hex.DecodeString(s)
271                         if err != nil {
272                                 t.Error(err)
273                         }
274                         testDB.Set(key, data)
275                 }
276
277                 gotUtxos := w.filterAccountUtxo(c.input)
278                 sort.Slice(gotUtxos[:], func(i, j int) bool {
279                         return gotUtxos[i].Amount < gotUtxos[j].Amount
280                 })
281
282                 if !testutil.DeepEqual(gotUtxos, c.wantUtxos) {
283                         t.Errorf("case %d: got %v want %v", i, gotUtxos, c.wantUtxos)
284                 }
285                 for s := range c.dbPrograms {
286                         key, err := hex.DecodeString(s)
287                         if err != nil {
288                                 t.Error(err)
289                         }
290                         testDB.Delete(key)
291                 }
292         }
293 }
294
295 func TestTxInToUtxos(t *testing.T) {
296         cases := []struct {
297                 tx         *types.Tx
298                 statusFail bool
299                 wantUtxos  []*account.UTXO
300         }{
301                 {
302                         tx: types.NewTx(types.TxData{
303                                 Inputs: []*types.TxInput{
304                                         types.NewCoinbaseInput([]byte{0x51}),
305                                 },
306                                 Outputs: []*types.TxOutput{
307                                         types.NewTxOutput(*consensus.BTMAssetID, 41250000000, []byte{0x51}),
308                                 },
309                         }),
310                         statusFail: false,
311                         wantUtxos:  []*account.UTXO{},
312                 },
313                 {
314                         tx: types.NewTx(types.TxData{
315                                 Inputs: []*types.TxInput{
316                                         types.NewIssuanceInput([]byte{}, 4125, []byte{0x51}, [][]byte{}, []byte{}),
317                                 },
318                                 Outputs: []*types.TxOutput{
319                                         types.NewTxOutput(*consensus.BTMAssetID, 4125, []byte{0x51}),
320                                 },
321                         }),
322                         statusFail: false,
323                         wantUtxos:  []*account.UTXO{},
324                 },
325                 {
326                         tx: types.NewTx(types.TxData{
327                                 Inputs: []*types.TxInput{
328                                         types.NewSpendInput([][]byte{}, bc.Hash{V0: 1}, bc.AssetID{V0: 1}, 1, 1, []byte{0x51}),
329                                         types.NewSpendInput([][]byte{}, bc.Hash{V0: 2}, bc.AssetID{V0: 1}, 3, 2, []byte{0x52}),
330                                         types.NewSpendInput([][]byte{}, bc.Hash{V0: 3}, *consensus.BTMAssetID, 5, 3, []byte{0x53}),
331                                         types.NewSpendInput([][]byte{}, bc.Hash{V0: 4}, *consensus.BTMAssetID, 7, 4, []byte{0x54}),
332                                 },
333                                 Outputs: []*types.TxOutput{
334                                         types.NewTxOutput(bc.AssetID{V0: 1}, 4, []byte{0x51}),
335                                         types.NewTxOutput(*consensus.BTMAssetID, 12, []byte{0x53}),
336                                 },
337                         }),
338                         statusFail: false,
339                         wantUtxos: []*account.UTXO{
340                                 &account.UTXO{
341                                         OutputID:       bc.NewHash([32]byte{0x9c, 0x0d, 0xfd, 0x17, 0x4a, 0x63, 0x02, 0x0f, 0xf1, 0xda, 0xe9, 0x2d, 0xc8, 0xdb, 0x3c, 0x1c, 0x46, 0xda, 0xf2, 0x8f, 0xef, 0xe9, 0x5c, 0xef, 0x38, 0x82, 0xe0, 0xaf, 0xc5, 0x28, 0x39, 0x3c}),
342                                         AssetID:        bc.AssetID{V0: 1},
343                                         Amount:         1,
344                                         ControlProgram: []byte{0x51},
345                                         SourceID:       bc.Hash{V0: 1},
346                                         SourcePos:      1,
347                                 },
348                                 &account.UTXO{
349                                         OutputID:       bc.NewHash([32]byte{0xc1, 0xf6, 0xa3, 0xb8, 0x32, 0x20, 0xbc, 0xde, 0x95, 0x23, 0x23, 0xf8, 0xe4, 0xe9, 0x82, 0x45, 0x86, 0xfb, 0xf9, 0x43, 0x0d, 0xfb, 0xfc, 0x7c, 0xcf, 0xf9, 0x6c, 0x2a, 0xbf, 0x35, 0xb7, 0xe1}),
350                                         AssetID:        bc.AssetID{V0: 1},
351                                         Amount:         3,
352                                         ControlProgram: []byte{0x52},
353                                         SourceID:       bc.Hash{V0: 2},
354                                         SourcePos:      2,
355                                 },
356                                 &account.UTXO{
357                                         OutputID:       bc.NewHash([32]byte{0x3d, 0x0c, 0x52, 0xb0, 0x59, 0xe6, 0xdd, 0xcd, 0x31, 0xe1, 0x25, 0xc4, 0x33, 0xfc, 0x2c, 0x9c, 0xbe, 0xe3, 0x0c, 0x3e, 0x72, 0xb4, 0xac, 0x36, 0x5b, 0xbb, 0x8d, 0x44, 0xa0, 0x82, 0x27, 0xe4}),
358                                         AssetID:        *consensus.BTMAssetID,
359                                         Amount:         5,
360                                         ControlProgram: []byte{0x53},
361                                         SourceID:       bc.Hash{V0: 3},
362                                         SourcePos:      3,
363                                 },
364                                 &account.UTXO{
365                                         OutputID:       bc.NewHash([32]byte{0x88, 0x9e, 0x88, 0xd6, 0x21, 0x74, 0x7f, 0xa0, 0x01, 0x79, 0x29, 0x9a, 0xd8, 0xa3, 0xe9, 0xc7, 0x67, 0xac, 0x39, 0x1c, 0x2b, 0x3a, 0xd1, 0x56, 0x50, 0x42, 0xe1, 0x6b, 0x43, 0x2c, 0x05, 0x91}),
366                                         AssetID:        *consensus.BTMAssetID,
367                                         Amount:         7,
368                                         ControlProgram: []byte{0x54},
369                                         SourceID:       bc.Hash{V0: 4},
370                                         SourcePos:      4,
371                                 },
372                         },
373                 },
374                 {
375                         tx: types.NewTx(types.TxData{
376                                 Inputs: []*types.TxInput{
377                                         types.NewSpendInput([][]byte{}, bc.Hash{V0: 1}, bc.AssetID{V0: 1}, 1, 1, []byte{0x51}),
378                                         types.NewSpendInput([][]byte{}, bc.Hash{V0: 2}, bc.AssetID{V0: 1}, 3, 2, []byte{0x52}),
379                                         types.NewSpendInput([][]byte{}, bc.Hash{V0: 3}, *consensus.BTMAssetID, 5, 3, []byte{0x53}),
380                                         types.NewSpendInput([][]byte{}, bc.Hash{V0: 4}, *consensus.BTMAssetID, 7, 4, []byte{0x54}),
381                                 },
382                                 Outputs: []*types.TxOutput{
383                                         types.NewTxOutput(bc.AssetID{V0: 1}, 4, []byte{0x51}),
384                                         types.NewTxOutput(*consensus.BTMAssetID, 12, []byte{0x53}),
385                                 },
386                         }),
387                         statusFail: true,
388                         wantUtxos: []*account.UTXO{
389                                 &account.UTXO{
390                                         OutputID:       bc.NewHash([32]byte{0x3d, 0x0c, 0x52, 0xb0, 0x59, 0xe6, 0xdd, 0xcd, 0x31, 0xe1, 0x25, 0xc4, 0x33, 0xfc, 0x2c, 0x9c, 0xbe, 0xe3, 0x0c, 0x3e, 0x72, 0xb4, 0xac, 0x36, 0x5b, 0xbb, 0x8d, 0x44, 0xa0, 0x82, 0x27, 0xe4}),
391                                         AssetID:        *consensus.BTMAssetID,
392                                         Amount:         5,
393                                         ControlProgram: []byte{0x53},
394                                         SourceID:       bc.Hash{V0: 3},
395                                         SourcePos:      3,
396                                 },
397                                 &account.UTXO{
398                                         OutputID:       bc.NewHash([32]byte{0x88, 0x9e, 0x88, 0xd6, 0x21, 0x74, 0x7f, 0xa0, 0x01, 0x79, 0x29, 0x9a, 0xd8, 0xa3, 0xe9, 0xc7, 0x67, 0xac, 0x39, 0x1c, 0x2b, 0x3a, 0xd1, 0x56, 0x50, 0x42, 0xe1, 0x6b, 0x43, 0x2c, 0x05, 0x91}),
399                                         AssetID:        *consensus.BTMAssetID,
400                                         Amount:         7,
401                                         ControlProgram: []byte{0x54},
402                                         SourceID:       bc.Hash{V0: 4},
403                                         SourcePos:      4,
404                                 },
405                         },
406                 },
407         }
408
409         for i, c := range cases {
410                 if gotUtxos := txInToUtxos(c.tx, c.statusFail); !testutil.DeepEqual(gotUtxos, c.wantUtxos) {
411                         for k, v := range gotUtxos {
412                                 data, _ := json.Marshal(v)
413                                 fmt.Println(k, string(data))
414                         }
415                         for k, v := range c.wantUtxos {
416                                 data, _ := json.Marshal(v)
417                                 fmt.Println(k, string(data))
418                         }
419                         t.Errorf("case %d: got %v want %v", i, gotUtxos, c.wantUtxos)
420                 }
421         }
422 }
423
424 func TestTxOutToUtxos(t *testing.T) {
425         cases := []struct {
426                 tx          *types.Tx
427                 statusFail  bool
428                 vaildHeight uint64
429                 wantUtxos   []*account.UTXO
430         }{
431                 {
432                         tx: types.NewTx(types.TxData{
433                                 Inputs: []*types.TxInput{
434                                         types.NewCoinbaseInput([]byte{0x51}),
435                                 },
436                                 Outputs: []*types.TxOutput{
437                                         types.NewTxOutput(*consensus.BTMAssetID, 41250000000, []byte{0x51}),
438                                 },
439                         }),
440                         statusFail:  false,
441                         vaildHeight: 98,
442                         wantUtxos: []*account.UTXO{
443                                 &account.UTXO{
444                                         OutputID:       bc.NewHash([32]byte{0x67, 0x13, 0xec, 0x34, 0x57, 0xf8, 0xdc, 0xf1, 0xb2, 0x95, 0x71, 0x4c, 0xe0, 0xca, 0x94, 0xef, 0x81, 0x84, 0x6b, 0xa4, 0xc0, 0x8b, 0xb4, 0x40, 0xd3, 0xc0, 0x55, 0xc2, 0x7a, 0x9c, 0x04, 0x0a}),
445                                         AssetID:        *consensus.BTMAssetID,
446                                         Amount:         41250000000,
447                                         ControlProgram: []byte{0x51},
448                                         SourceID:       bc.NewHash([32]byte{0xb4, 0x7e, 0x94, 0x31, 0x88, 0xfe, 0xd3, 0xe9, 0xac, 0x99, 0x7c, 0xfc, 0x99, 0x6d, 0xd7, 0x4d, 0x04, 0x10, 0x77, 0xcb, 0x1c, 0xf8, 0x95, 0x14, 0x00, 0xe3, 0x42, 0x00, 0x8d, 0x05, 0xec, 0xdc}),
449                                         SourcePos:      0,
450                                         ValidHeight:    98,
451                                 },
452                         },
453                 },
454                 {
455                         tx: types.NewTx(types.TxData{
456                                 Inputs: []*types.TxInput{
457                                         types.NewSpendInput([][]byte{}, bc.Hash{V0: 1}, bc.AssetID{V0: 1}, 5, 1, []byte{0x51}),
458                                         types.NewSpendInput([][]byte{}, bc.Hash{V0: 2}, *consensus.BTMAssetID, 7, 1, []byte{0x51}),
459                                 },
460                                 Outputs: []*types.TxOutput{
461                                         types.NewTxOutput(bc.AssetID{V0: 1}, 2, []byte{0x51}),
462                                         types.NewTxOutput(bc.AssetID{V0: 1}, 3, []byte{0x52}),
463                                         types.NewTxOutput(*consensus.BTMAssetID, 2, []byte{0x53}),
464                                         types.NewTxOutput(*consensus.BTMAssetID, 5, []byte{0x54}),
465                                 },
466                         }),
467                         statusFail:  false,
468                         vaildHeight: 0,
469                         wantUtxos: []*account.UTXO{
470                                 &account.UTXO{
471                                         OutputID:       bc.NewHash([32]byte{0xff, 0xcd, 0xc4, 0xdc, 0xe8, 0x7e, 0xce, 0x93, 0x4b, 0x14, 0x2b, 0x2b, 0x84, 0xf2, 0x4d, 0x08, 0xca, 0x9f, 0x0b, 0x97, 0xa3, 0x0e, 0x38, 0x5a, 0xb0, 0xa7, 0x1e, 0x8f, 0x22, 0x55, 0xa6, 0x19}),
472                                         AssetID:        bc.AssetID{V0: 1},
473                                         Amount:         2,
474                                         ControlProgram: []byte{0x51},
475                                         SourceID:       bc.NewHash([32]byte{0x39, 0x4f, 0x89, 0xd4, 0xdc, 0x26, 0xb9, 0x57, 0x91, 0x2f, 0xe9, 0x7f, 0xba, 0x51, 0x68, 0xcf, 0xe4, 0xae, 0x0c, 0xef, 0x79, 0x56, 0xa0, 0x45, 0xda, 0x27, 0xdc, 0x69, 0xd8, 0xef, 0x32, 0x61}),
476                                         SourcePos:      0,
477                                 },
478                                 &account.UTXO{
479                                         OutputID:       bc.NewHash([32]byte{0x89, 0xcd, 0x38, 0x92, 0x6f, 0xee, 0xc6, 0x10, 0xae, 0x61, 0xef, 0x62, 0x70, 0x88, 0x94, 0x7c, 0x26, 0xaa, 0xfb, 0x05, 0xa2, 0x0a, 0x63, 0x9d, 0x21, 0x22, 0x0c, 0xe3, 0xc2, 0xe5, 0xf9, 0xbf}),
480                                         AssetID:        bc.AssetID{V0: 1},
481                                         Amount:         3,
482                                         ControlProgram: []byte{0x52},
483                                         SourceID:       bc.NewHash([32]byte{0x39, 0x4f, 0x89, 0xd4, 0xdc, 0x26, 0xb9, 0x57, 0x91, 0x2f, 0xe9, 0x7f, 0xba, 0x51, 0x68, 0xcf, 0xe4, 0xae, 0x0c, 0xef, 0x79, 0x56, 0xa0, 0x45, 0xda, 0x27, 0xdc, 0x69, 0xd8, 0xef, 0x32, 0x61}),
484                                         SourcePos:      1,
485                                 },
486                                 &account.UTXO{
487                                         OutputID:       bc.NewHash([32]byte{0xcf, 0xb9, 0xeb, 0xa3, 0xc8, 0xe8, 0xf1, 0x5a, 0x5c, 0x70, 0xf8, 0x9e, 0x7d, 0x9e, 0xf7, 0xb2, 0x66, 0x42, 0x8c, 0x97, 0x8e, 0xc2, 0x4d, 0x4b, 0x28, 0x57, 0xa7, 0x61, 0x1c, 0xf1, 0xea, 0x9d}),
488                                         AssetID:        *consensus.BTMAssetID,
489                                         Amount:         2,
490                                         ControlProgram: []byte{0x53},
491                                         SourceID:       bc.NewHash([32]byte{0x39, 0x4f, 0x89, 0xd4, 0xdc, 0x26, 0xb9, 0x57, 0x91, 0x2f, 0xe9, 0x7f, 0xba, 0x51, 0x68, 0xcf, 0xe4, 0xae, 0x0c, 0xef, 0x79, 0x56, 0xa0, 0x45, 0xda, 0x27, 0xdc, 0x69, 0xd8, 0xef, 0x32, 0x61}),
492                                         SourcePos:      2,
493                                 },
494                                 &account.UTXO{
495                                         OutputID:       bc.NewHash([32]byte{0x21, 0xf2, 0xe4, 0xee, 0xec, 0x1f, 0x82, 0xd8, 0xf2, 0xe1, 0x2b, 0x9e, 0x72, 0xfa, 0x91, 0x2b, 0x8c, 0xce, 0xbd, 0x18, 0x6d, 0x16, 0xf8, 0xc4, 0xf1, 0x71, 0x9d, 0x6b, 0x44, 0x41, 0xde, 0xb9}),
496                                         AssetID:        *consensus.BTMAssetID,
497                                         Amount:         5,
498                                         ControlProgram: []byte{0x54},
499                                         SourceID:       bc.NewHash([32]byte{0x39, 0x4f, 0x89, 0xd4, 0xdc, 0x26, 0xb9, 0x57, 0x91, 0x2f, 0xe9, 0x7f, 0xba, 0x51, 0x68, 0xcf, 0xe4, 0xae, 0x0c, 0xef, 0x79, 0x56, 0xa0, 0x45, 0xda, 0x27, 0xdc, 0x69, 0xd8, 0xef, 0x32, 0x61}),
500                                         SourcePos:      3,
501                                 },
502                         },
503                 },
504                 {
505                         tx: types.NewTx(types.TxData{
506                                 Inputs: []*types.TxInput{
507                                         types.NewSpendInput([][]byte{}, bc.Hash{V0: 1}, bc.AssetID{V0: 1}, 5, 1, []byte{0x51}),
508                                         types.NewSpendInput([][]byte{}, bc.Hash{V0: 2}, *consensus.BTMAssetID, 7, 1, []byte{0x51}),
509                                 },
510                                 Outputs: []*types.TxOutput{
511                                         types.NewTxOutput(bc.AssetID{V0: 1}, 2, []byte{0x51}),
512                                         types.NewTxOutput(bc.AssetID{V0: 1}, 3, []byte{0x52}),
513                                         types.NewTxOutput(*consensus.BTMAssetID, 2, []byte{0x53}),
514                                         types.NewTxOutput(*consensus.BTMAssetID, 5, []byte{0x54}),
515                                 },
516                         }),
517                         statusFail:  true,
518                         vaildHeight: 0,
519                         wantUtxos: []*account.UTXO{
520                                 &account.UTXO{
521                                         OutputID:       bc.NewHash([32]byte{0xcf, 0xb9, 0xeb, 0xa3, 0xc8, 0xe8, 0xf1, 0x5a, 0x5c, 0x70, 0xf8, 0x9e, 0x7d, 0x9e, 0xf7, 0xb2, 0x66, 0x42, 0x8c, 0x97, 0x8e, 0xc2, 0x4d, 0x4b, 0x28, 0x57, 0xa7, 0x61, 0x1c, 0xf1, 0xea, 0x9d}),
522                                         AssetID:        *consensus.BTMAssetID,
523                                         Amount:         2,
524                                         ControlProgram: []byte{0x53},
525                                         SourceID:       bc.NewHash([32]byte{0x39, 0x4f, 0x89, 0xd4, 0xdc, 0x26, 0xb9, 0x57, 0x91, 0x2f, 0xe9, 0x7f, 0xba, 0x51, 0x68, 0xcf, 0xe4, 0xae, 0x0c, 0xef, 0x79, 0x56, 0xa0, 0x45, 0xda, 0x27, 0xdc, 0x69, 0xd8, 0xef, 0x32, 0x61}),
526                                         SourcePos:      2,
527                                 },
528                                 &account.UTXO{
529                                         OutputID:       bc.NewHash([32]byte{0x21, 0xf2, 0xe4, 0xee, 0xec, 0x1f, 0x82, 0xd8, 0xf2, 0xe1, 0x2b, 0x9e, 0x72, 0xfa, 0x91, 0x2b, 0x8c, 0xce, 0xbd, 0x18, 0x6d, 0x16, 0xf8, 0xc4, 0xf1, 0x71, 0x9d, 0x6b, 0x44, 0x41, 0xde, 0xb9}),
530                                         AssetID:        *consensus.BTMAssetID,
531                                         Amount:         5,
532                                         ControlProgram: []byte{0x54},
533                                         SourceID:       bc.NewHash([32]byte{0x39, 0x4f, 0x89, 0xd4, 0xdc, 0x26, 0xb9, 0x57, 0x91, 0x2f, 0xe9, 0x7f, 0xba, 0x51, 0x68, 0xcf, 0xe4, 0xae, 0x0c, 0xef, 0x79, 0x56, 0xa0, 0x45, 0xda, 0x27, 0xdc, 0x69, 0xd8, 0xef, 0x32, 0x61}),
534                                         SourcePos:      3,
535                                 },
536                         },
537                 },
538         }
539
540         for i, c := range cases {
541                 if gotUtxos := txOutToUtxos(c.tx, c.statusFail, c.vaildHeight); !testutil.DeepEqual(gotUtxos, c.wantUtxos) {
542                         t.Errorf("case %d: got %v want %v", i, gotUtxos, c.wantUtxos)
543                 }
544         }
545 }