9 dbm "github.com/vapor/database/leveldb"
10 "github.com/vapor/protocol/bc"
11 "github.com/vapor/testutil"
14 func TestAddUnconfirmedUtxo(t *testing.T) {
22 unconfirmed: map[bc.Hash]*UTXO{},
25 unconfirmed: map[bc.Hash]*UTXO{},
31 unconfirmed: map[bc.Hash]*UTXO{},
34 unconfirmed: map[bc.Hash]*UTXO{
35 bc.NewHash([32]byte{0x01}): &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
39 &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
44 unconfirmed: map[bc.Hash]*UTXO{
45 bc.NewHash([32]byte{0x01}): &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
49 unconfirmed: map[bc.Hash]*UTXO{
50 bc.NewHash([32]byte{0x01}): &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
54 &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
59 unconfirmed: map[bc.Hash]*UTXO{
60 bc.NewHash([32]byte{0x01}): &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
64 unconfirmed: map[bc.Hash]*UTXO{
65 bc.NewHash([32]byte{0x01}): &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
66 bc.NewHash([32]byte{0x02}): &UTXO{OutputID: bc.NewHash([32]byte{0x02})},
67 bc.NewHash([32]byte{0x03}): &UTXO{OutputID: bc.NewHash([32]byte{0x03})},
71 &UTXO{OutputID: bc.NewHash([32]byte{0x02})},
72 &UTXO{OutputID: bc.NewHash([32]byte{0x03})},
77 for i, c := range cases {
78 c.before.AddUnconfirmedUtxo(c.addUtxos)
79 if !testutil.DeepEqual(c.before, c.after) {
80 t.Errorf("case %d: got %v want %v", i, c.before, c.after)
85 func TestCancel(t *testing.T) {
93 reserved: map[bc.Hash]uint64{},
94 reservations: map[uint64]*reservation{},
97 reserved: map[bc.Hash]uint64{},
98 reservations: map[uint64]*reservation{},
104 reserved: map[bc.Hash]uint64{
105 bc.NewHash([32]byte{0x01}): 1,
107 reservations: map[uint64]*reservation{
111 &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
114 expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
119 reserved: map[bc.Hash]uint64{},
120 reservations: map[uint64]*reservation{},
126 reserved: map[bc.Hash]uint64{
127 bc.NewHash([32]byte{0x01}): 1,
129 reservations: map[uint64]*reservation{
133 &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
136 expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
141 reserved: map[bc.Hash]uint64{
142 bc.NewHash([32]byte{0x01}): 1,
144 reservations: map[uint64]*reservation{
148 &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
151 expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
159 reserved: map[bc.Hash]uint64{
160 bc.NewHash([32]byte{0x01}): 1,
161 bc.NewHash([32]byte{0x02}): 3,
162 bc.NewHash([32]byte{0x03}): 3,
163 bc.NewHash([32]byte{0x04}): 3,
165 reservations: map[uint64]*reservation{
169 &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
172 expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
177 &UTXO{OutputID: bc.NewHash([32]byte{0x02})},
178 &UTXO{OutputID: bc.NewHash([32]byte{0x03})},
179 &UTXO{OutputID: bc.NewHash([32]byte{0x04})},
182 expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
187 reserved: map[bc.Hash]uint64{
188 bc.NewHash([32]byte{0x01}): 1,
190 reservations: map[uint64]*reservation{
194 &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
197 expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
205 for i, c := range cases {
206 c.before.cancel(c.cancelRid)
207 if !testutil.DeepEqual(c.before, c.after) {
208 t.Errorf("case %d: got %v want %v", i, c.before, c.after)
213 func TestRemoveUnconfirmedUtxo(t *testing.T) {
217 removeUtxos []*bc.Hash
221 unconfirmed: map[bc.Hash]*UTXO{},
224 unconfirmed: map[bc.Hash]*UTXO{},
226 removeUtxos: []*bc.Hash{},
230 unconfirmed: map[bc.Hash]*UTXO{
231 bc.Hash{V0: 1}: &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
235 unconfirmed: map[bc.Hash]*UTXO{},
237 removeUtxos: []*bc.Hash{
243 unconfirmed: map[bc.Hash]*UTXO{
244 bc.Hash{V0: 1}: &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
245 bc.Hash{V0: 2}: &UTXO{OutputID: bc.NewHash([32]byte{0x02})},
246 bc.Hash{V0: 3}: &UTXO{OutputID: bc.NewHash([32]byte{0x03})},
247 bc.Hash{V0: 4}: &UTXO{OutputID: bc.NewHash([32]byte{0x04})},
248 bc.Hash{V0: 5}: &UTXO{OutputID: bc.NewHash([32]byte{0x05})},
252 unconfirmed: map[bc.Hash]*UTXO{
253 bc.Hash{V0: 2}: &UTXO{OutputID: bc.NewHash([32]byte{0x02})},
254 bc.Hash{V0: 4}: &UTXO{OutputID: bc.NewHash([32]byte{0x04})},
257 removeUtxos: []*bc.Hash{
265 for i, c := range cases {
266 c.before.RemoveUnconfirmedUtxo(c.removeUtxos)
267 if !testutil.DeepEqual(c.before, c.after) {
268 t.Errorf("case %d: got %v want %v", i, c.before, c.after)
273 func TestReserve(t *testing.T) {
274 currentHeight := func() uint64 { return 9527 }
275 testDB := dbm.NewDB("testdb", "leveldb", "temp")
276 defer os.RemoveAll("temp")
288 currentHeight: currentHeight,
289 reserved: map[bc.Hash]uint64{},
290 reservations: map[uint64]*reservation{},
294 currentHeight: currentHeight,
295 reserved: map[bc.Hash]uint64{},
296 reservations: map[uint64]*reservation{},
299 err: ErrInsufficient,
304 currentHeight: currentHeight,
305 unconfirmed: map[bc.Hash]*UTXO{
306 bc.NewHash([32]byte{0x01}): &UTXO{
307 OutputID: bc.NewHash([32]byte{0x01}),
308 AccountID: "testAccount",
312 reserved: map[bc.Hash]uint64{},
313 reservations: map[uint64]*reservation{},
317 currentHeight: currentHeight,
318 unconfirmed: map[bc.Hash]*UTXO{
319 bc.NewHash([32]byte{0x01}): &UTXO{
320 OutputID: bc.NewHash([32]byte{0x01}),
321 AccountID: "testAccount",
325 reserved: map[bc.Hash]uint64{},
326 reservations: map[uint64]*reservation{},
329 err: ErrInsufficient,
334 currentHeight: currentHeight,
335 unconfirmed: map[bc.Hash]*UTXO{
336 bc.NewHash([32]byte{0x01}): &UTXO{
337 OutputID: bc.NewHash([32]byte{0x01}),
338 AccountID: "testAccount",
343 reserved: map[bc.Hash]uint64{},
344 reservations: map[uint64]*reservation{},
348 currentHeight: currentHeight,
349 unconfirmed: map[bc.Hash]*UTXO{
350 bc.NewHash([32]byte{0x01}): &UTXO{
351 OutputID: bc.NewHash([32]byte{0x01}),
352 AccountID: "testAccount",
357 reserved: map[bc.Hash]uint64{},
358 reservations: map[uint64]*reservation{},
366 currentHeight: currentHeight,
367 unconfirmed: map[bc.Hash]*UTXO{
368 bc.NewHash([32]byte{0x01}): &UTXO{
369 OutputID: bc.NewHash([32]byte{0x01}),
370 AccountID: "testAccount",
374 reserved: map[bc.Hash]uint64{
375 bc.NewHash([32]byte{0x01}): 0,
377 reservations: map[uint64]*reservation{},
381 currentHeight: currentHeight,
382 unconfirmed: map[bc.Hash]*UTXO{
383 bc.NewHash([32]byte{0x01}): &UTXO{
384 OutputID: bc.NewHash([32]byte{0x01}),
385 AccountID: "testAccount",
389 reserved: map[bc.Hash]uint64{
390 bc.NewHash([32]byte{0x01}): 0,
392 reservations: map[uint64]*reservation{},
400 currentHeight: currentHeight,
401 unconfirmed: map[bc.Hash]*UTXO{
402 bc.NewHash([32]byte{0x01}): &UTXO{
403 OutputID: bc.NewHash([32]byte{0x01}),
404 AccountID: "testAccount",
408 reserved: map[bc.Hash]uint64{},
409 reservations: map[uint64]*reservation{},
413 currentHeight: currentHeight,
414 unconfirmed: map[bc.Hash]*UTXO{
415 bc.NewHash([32]byte{0x01}): &UTXO{
416 OutputID: bc.NewHash([32]byte{0x01}),
417 AccountID: "testAccount",
421 reserved: map[bc.Hash]uint64{
422 bc.NewHash([32]byte{0x01}): 1,
424 reservations: map[uint64]*reservation{
429 OutputID: bc.NewHash([32]byte{0x01}),
430 AccountID: "testAccount",
435 expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
441 exp: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
446 currentHeight: currentHeight,
448 unconfirmed: map[bc.Hash]*UTXO{
449 bc.NewHash([32]byte{0x01}): &UTXO{
450 OutputID: bc.NewHash([32]byte{0x01}),
451 AccountID: "testAccount",
454 bc.NewHash([32]byte{0x02}): &UTXO{
455 OutputID: bc.NewHash([32]byte{0x02}),
456 AccountID: "testAccount",
459 bc.NewHash([32]byte{0x03}): &UTXO{
460 OutputID: bc.NewHash([32]byte{0x03}),
461 AccountID: "testAccount",
465 reserved: map[bc.Hash]uint64{
466 bc.NewHash([32]byte{0x01}): 1,
468 reservations: map[uint64]*reservation{},
472 currentHeight: currentHeight,
473 unconfirmed: map[bc.Hash]*UTXO{
474 bc.NewHash([32]byte{0x01}): &UTXO{
475 OutputID: bc.NewHash([32]byte{0x01}),
476 AccountID: "testAccount",
479 bc.NewHash([32]byte{0x02}): &UTXO{
480 OutputID: bc.NewHash([32]byte{0x02}),
481 AccountID: "testAccount",
484 bc.NewHash([32]byte{0x03}): &UTXO{
485 OutputID: bc.NewHash([32]byte{0x03}),
486 AccountID: "testAccount",
490 reserved: map[bc.Hash]uint64{
491 bc.NewHash([32]byte{0x01}): 1,
492 bc.NewHash([32]byte{0x02}): 2,
493 bc.NewHash([32]byte{0x03}): 2,
495 reservations: map[uint64]*reservation{
500 OutputID: bc.NewHash([32]byte{0x03}),
501 AccountID: "testAccount",
505 OutputID: bc.NewHash([32]byte{0x02}),
506 AccountID: "testAccount",
511 expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
517 exp: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
521 for i, c := range cases {
522 if _, err := c.before.Reserve("testAccount", &bc.AssetID{}, c.reserveAmount, true, c.exp); err != c.err {
523 t.Errorf("case %d: got error %v want error %v", i, err, c.err)
525 checkUtxoKeeperEqual(t, i, &c.before, &c.after)
529 func TestReserveParticular(t *testing.T) {
530 currentHeight := func() uint64 { return 9527 }
531 testDB := dbm.NewDB("testdb", "leveldb", "temp")
532 defer os.RemoveAll("temp")
544 currentHeight: currentHeight,
545 unconfirmed: map[bc.Hash]*UTXO{
546 bc.NewHash([32]byte{0x01}): &UTXO{
547 OutputID: bc.NewHash([32]byte{0x01}),
548 AccountID: "testAccount",
552 reserved: map[bc.Hash]uint64{
553 bc.NewHash([32]byte{0x01}): 0,
555 reservations: map[uint64]*reservation{},
559 currentHeight: currentHeight,
560 unconfirmed: map[bc.Hash]*UTXO{
561 bc.NewHash([32]byte{0x01}): &UTXO{
562 OutputID: bc.NewHash([32]byte{0x01}),
563 AccountID: "testAccount",
567 reserved: map[bc.Hash]uint64{
568 bc.NewHash([32]byte{0x01}): 0,
570 reservations: map[uint64]*reservation{},
572 reserveHash: bc.NewHash([32]byte{0x01}),
578 currentHeight: currentHeight,
579 unconfirmed: map[bc.Hash]*UTXO{
580 bc.NewHash([32]byte{0x01}): &UTXO{
581 OutputID: bc.NewHash([32]byte{0x01}),
582 AccountID: "testAccount",
587 reserved: map[bc.Hash]uint64{},
588 reservations: map[uint64]*reservation{},
592 currentHeight: currentHeight,
593 unconfirmed: map[bc.Hash]*UTXO{
594 bc.NewHash([32]byte{0x01}): &UTXO{
595 OutputID: bc.NewHash([32]byte{0x01}),
596 AccountID: "testAccount",
601 reserved: map[bc.Hash]uint64{},
602 reservations: map[uint64]*reservation{},
604 reserveHash: bc.NewHash([32]byte{0x01}),
610 currentHeight: currentHeight,
611 unconfirmed: map[bc.Hash]*UTXO{
612 bc.NewHash([32]byte{0x01}): &UTXO{
613 OutputID: bc.NewHash([32]byte{0x01}),
614 AccountID: "testAccount",
618 reserved: map[bc.Hash]uint64{},
619 reservations: map[uint64]*reservation{},
623 currentHeight: currentHeight,
624 unconfirmed: map[bc.Hash]*UTXO{
625 bc.NewHash([32]byte{0x01}): &UTXO{
626 OutputID: bc.NewHash([32]byte{0x01}),
627 AccountID: "testAccount",
631 reserved: map[bc.Hash]uint64{
632 bc.NewHash([32]byte{0x01}): 1,
634 reservations: map[uint64]*reservation{
639 OutputID: bc.NewHash([32]byte{0x01}),
640 AccountID: "testAccount",
645 expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
649 reserveHash: bc.NewHash([32]byte{0x01}),
651 exp: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
655 for i, c := range cases {
656 if _, err := c.before.ReserveParticular(c.reserveHash, true, c.exp); err != c.err {
657 t.Errorf("case %d: got error %v want error %v", i, err, c.err)
659 checkUtxoKeeperEqual(t, i, &c.before, &c.after)
663 func TestExpireReservation(t *testing.T) {
664 before := &utxoKeeper{
665 reservations: map[uint64]*reservation{
666 1: &reservation{expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC)},
667 2: &reservation{expiry: time.Date(3016, 8, 10, 0, 0, 0, 0, time.UTC)},
668 3: &reservation{expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC)},
669 4: &reservation{expiry: time.Date(3016, 8, 10, 0, 0, 0, 0, time.UTC)},
670 5: &reservation{expiry: time.Date(3016, 8, 10, 0, 0, 0, 0, time.UTC)},
673 after := &utxoKeeper{
674 reservations: map[uint64]*reservation{
675 2: &reservation{expiry: time.Date(3016, 8, 10, 0, 0, 0, 0, time.UTC)},
676 4: &reservation{expiry: time.Date(3016, 8, 10, 0, 0, 0, 0, time.UTC)},
677 5: &reservation{expiry: time.Date(3016, 8, 10, 0, 0, 0, 0, time.UTC)},
680 before.expireReservation(time.Date(2017, 8, 10, 0, 0, 0, 0, time.UTC))
681 checkUtxoKeeperEqual(t, 0, before, after)
684 func TestFindUtxos(t *testing.T) {
685 currentHeight := func() uint64 { return 9527 }
686 testDB := dbm.NewDB("testdb", "leveldb", "temp")
687 defer os.RemoveAll("temp")
694 immatureAmount uint64
699 currentHeight: currentHeight,
700 unconfirmed: map[bc.Hash]*UTXO{},
703 useUnconfirmed: true,
704 wantUtxos: []*UTXO{},
710 currentHeight: currentHeight,
711 unconfirmed: map[bc.Hash]*UTXO{},
715 OutputID: bc.NewHash([32]byte{0x01}),
716 AccountID: "testAccount",
720 OutputID: bc.NewHash([32]byte{0x02}),
721 AccountID: "testAccount",
722 AssetID: bc.AssetID{V0: 6},
726 useUnconfirmed: false,
729 OutputID: bc.NewHash([32]byte{0x01}),
730 AccountID: "testAccount",
739 currentHeight: currentHeight,
740 unconfirmed: map[bc.Hash]*UTXO{},
744 OutputID: bc.NewHash([32]byte{0x02}),
745 AccountID: "testAccount",
750 useUnconfirmed: false,
751 wantUtxos: []*UTXO{},
757 currentHeight: currentHeight,
758 unconfirmed: map[bc.Hash]*UTXO{
759 bc.NewHash([32]byte{0x01}): &UTXO{
760 OutputID: bc.NewHash([32]byte{0x01}),
761 AccountID: "testAccount",
768 OutputID: bc.NewHash([32]byte{0x02}),
769 AccountID: "testAccount",
773 useUnconfirmed: false,
776 OutputID: bc.NewHash([32]byte{0x02}),
777 AccountID: "testAccount",
786 currentHeight: currentHeight,
787 unconfirmed: map[bc.Hash]*UTXO{
788 bc.NewHash([32]byte{0x11}): &UTXO{
789 OutputID: bc.NewHash([32]byte{0x01}),
790 AccountID: "testAccount",
797 OutputID: bc.NewHash([32]byte{0x02}),
798 AccountID: "testAccount",
802 useUnconfirmed: true,
805 OutputID: bc.NewHash([32]byte{0x02}),
806 AccountID: "testAccount",
810 OutputID: bc.NewHash([32]byte{0x01}),
811 AccountID: "testAccount",
820 currentHeight: currentHeight,
821 unconfirmed: map[bc.Hash]*UTXO{
822 bc.NewHash([32]byte{0x01}): &UTXO{
823 OutputID: bc.NewHash([32]byte{0x01}),
824 AccountID: "testAccount",
827 bc.NewHash([32]byte{0x02}): &UTXO{
828 OutputID: bc.NewHash([32]byte{0x02}),
836 OutputID: bc.NewHash([32]byte{0x03}),
837 AccountID: "testAccount",
841 OutputID: bc.NewHash([32]byte{0x04}),
846 useUnconfirmed: true,
849 OutputID: bc.NewHash([32]byte{0x03}),
850 AccountID: "testAccount",
854 OutputID: bc.NewHash([32]byte{0x01}),
855 AccountID: "testAccount",
863 for i, c := range cases {
864 for _, u := range c.dbUtxos {
865 data, err := json.Marshal(u)
869 testDB.Set(StandardUTXOKey(u.OutputID), data)
872 gotUtxos, immatureAmount := c.uk.findUtxos("testAccount", &bc.AssetID{}, c.useUnconfirmed)
873 if !testutil.DeepEqual(gotUtxos, c.wantUtxos) {
874 t.Errorf("case %d: got %v want %v", i, gotUtxos, c.wantUtxos)
876 if immatureAmount != c.immatureAmount {
877 t.Errorf("case %d: got %v want %v", i, immatureAmount, c.immatureAmount)
880 for _, u := range c.dbUtxos {
881 testDB.Delete(StandardUTXOKey(u.OutputID))
886 func TestFindUtxo(t *testing.T) {
887 currentHeight := func() uint64 { return 9527 }
888 testDB := dbm.NewDB("testdb", "leveldb", "temp")
889 defer os.RemoveAll("temp")
893 dbUtxos map[string]*UTXO
902 currentHeight: currentHeight,
903 unconfirmed: map[bc.Hash]*UTXO{},
905 dbUtxos: map[string]*UTXO{},
906 outHash: bc.NewHash([32]byte{0x01}),
913 currentHeight: currentHeight,
914 unconfirmed: map[bc.Hash]*UTXO{
915 bc.NewHash([32]byte{0x01}): &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
918 dbUtxos: map[string]*UTXO{},
919 outHash: bc.NewHash([32]byte{0x01}),
921 useUnconfirmed: false,
927 currentHeight: currentHeight,
928 unconfirmed: map[bc.Hash]*UTXO{
929 bc.NewHash([32]byte{0x01}): &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
932 dbUtxos: map[string]*UTXO{},
933 outHash: bc.NewHash([32]byte{0x01}),
934 wantUtxo: &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
935 useUnconfirmed: true,
941 currentHeight: currentHeight,
942 unconfirmed: map[bc.Hash]*UTXO{},
944 dbUtxos: map[string]*UTXO{
945 string(StandardUTXOKey(bc.NewHash([32]byte{0x01}))): &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
947 outHash: bc.NewHash([32]byte{0x01}),
948 wantUtxo: &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
949 useUnconfirmed: false,
955 currentHeight: currentHeight,
956 unconfirmed: map[bc.Hash]*UTXO{},
958 dbUtxos: map[string]*UTXO{
959 string(ContractUTXOKey(bc.NewHash([32]byte{0x01}))): &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
961 outHash: bc.NewHash([32]byte{0x01}),
962 wantUtxo: &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
963 useUnconfirmed: false,
968 for i, c := range cases {
969 for k, u := range c.dbUtxos {
970 data, err := json.Marshal(u)
974 testDB.Set([]byte(k), data)
977 gotUtxo, err := c.uk.findUtxo(c.outHash, c.useUnconfirmed)
978 if !testutil.DeepEqual(gotUtxo, c.wantUtxo) {
979 t.Errorf("case %d: got %v want %v", i, gotUtxo, c.wantUtxo)
982 t.Errorf("case %d: got %v want %v", i, err, c.err)
985 for _, u := range c.dbUtxos {
986 testDB.Delete(StandardUTXOKey(u.OutputID))
991 func TestOptUTXOs(t *testing.T) {
998 reservedAmount uint64
1002 reserved: map[bc.Hash]uint64{
1003 bc.NewHash([32]byte{0x01}): 1,
1008 wantUtxos: []*UTXO{},
1014 reserved: map[bc.Hash]uint64{
1015 bc.NewHash([32]byte{0x01}): 1,
1019 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1022 wantUtxos: []*UTXO{},
1028 reserved: map[bc.Hash]uint64{
1029 bc.NewHash([32]byte{0x01}): 1,
1033 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1034 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 3},
1035 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 5},
1039 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 5},
1040 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 3},
1047 reserved: map[bc.Hash]uint64{
1048 bc.NewHash([32]byte{0x01}): 1,
1049 bc.NewHash([32]byte{0x02}): 2,
1050 bc.NewHash([32]byte{0x03}): 3,
1054 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1055 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 3},
1056 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 5},
1059 wantUtxos: []*UTXO{},
1066 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1067 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 3},
1068 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 5},
1072 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1080 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 2},
1081 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 3},
1082 &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 5},
1086 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 3},
1087 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 2},
1095 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1096 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 1},
1097 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 1},
1098 &UTXO{OutputID: bc.NewHash([32]byte{0x04}), Amount: 1},
1099 &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 1},
1100 &UTXO{OutputID: bc.NewHash([32]byte{0x06}), Amount: 1},
1101 &UTXO{OutputID: bc.NewHash([32]byte{0x08}), Amount: 6},
1105 &UTXO{OutputID: bc.NewHash([32]byte{0x08}), Amount: 6},
1113 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1114 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 1},
1115 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 1},
1116 &UTXO{OutputID: bc.NewHash([32]byte{0x04}), Amount: 1},
1117 &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 1},
1118 &UTXO{OutputID: bc.NewHash([32]byte{0x06}), Amount: 1},
1119 &UTXO{OutputID: bc.NewHash([32]byte{0x08}), Amount: 6},
1123 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 1},
1124 &UTXO{OutputID: bc.NewHash([32]byte{0x04}), Amount: 1},
1125 &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 1},
1126 &UTXO{OutputID: bc.NewHash([32]byte{0x06}), Amount: 1},
1127 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1135 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1136 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 3},
1137 &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 5},
1138 &UTXO{OutputID: bc.NewHash([32]byte{0x07}), Amount: 7},
1139 &UTXO{OutputID: bc.NewHash([32]byte{0x11}), Amount: 11},
1140 &UTXO{OutputID: bc.NewHash([32]byte{0x13}), Amount: 13},
1141 &UTXO{OutputID: bc.NewHash([32]byte{0x23}), Amount: 23},
1142 &UTXO{OutputID: bc.NewHash([32]byte{0x31}), Amount: 31},
1146 &UTXO{OutputID: bc.NewHash([32]byte{0x07}), Amount: 7},
1147 &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 5},
1148 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 3},
1156 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1160 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1168 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1169 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 2},
1170 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 3},
1171 &UTXO{OutputID: bc.NewHash([32]byte{0x04}), Amount: 4},
1172 &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 5},
1173 &UTXO{OutputID: bc.NewHash([32]byte{0x06}), Amount: 6},
1174 &UTXO{OutputID: bc.NewHash([32]byte{0x07}), Amount: 7},
1175 &UTXO{OutputID: bc.NewHash([32]byte{0x08}), Amount: 8},
1176 &UTXO{OutputID: bc.NewHash([32]byte{0x09}), Amount: 9},
1177 &UTXO{OutputID: bc.NewHash([32]byte{0x10}), Amount: 10},
1178 &UTXO{OutputID: bc.NewHash([32]byte{0x11}), Amount: 11},
1179 &UTXO{OutputID: bc.NewHash([32]byte{0x12}), Amount: 12},
1183 &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 5},
1184 &UTXO{OutputID: bc.NewHash([32]byte{0x04}), Amount: 4},
1185 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 3},
1186 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 2},
1187 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1194 for i, c := range cases {
1195 got, optAmount, reservedAmount := c.uk.optUTXOs(c.input, c.inputAmount)
1196 if !testutil.DeepEqual(got, c.wantUtxos) {
1197 t.Errorf("case %d: utxos got %v want %v", i, got, c.wantUtxos)
1199 if optAmount != c.optAmount {
1200 t.Errorf("case %d: utxos got %v want %v", i, optAmount, c.optAmount)
1202 if reservedAmount != c.reservedAmount {
1203 t.Errorf("case %d: reservedAmount got %v want %v", i, reservedAmount, c.reservedAmount)
1208 func checkUtxoKeeperEqual(t *testing.T, i int, a, b *utxoKeeper) {
1209 if !testutil.DeepEqual(a.unconfirmed, b.unconfirmed) {
1210 t.Errorf("case %d: unconfirmed got %v want %v", i, a.unconfirmed, b.unconfirmed)
1212 if !testutil.DeepEqual(a.reserved, b.reserved) {
1213 t.Errorf("case %d: reserved got %v want %v", i, a.reserved, b.reserved)
1215 if !testutil.DeepEqual(a.reservations, b.reservations) {
1216 t.Errorf("case %d: reservations got %v want %v", i, a.reservations, b.reservations)