9 dbm "github.com/tendermint/tmlibs/db"
11 "github.com/vapor/protocol/bc"
12 "github.com/vapor/testutil"
15 func TestAddUnconfirmedUtxo(t *testing.T) {
23 unconfirmed: map[bc.Hash]*UTXO{},
26 unconfirmed: map[bc.Hash]*UTXO{},
32 unconfirmed: map[bc.Hash]*UTXO{},
35 unconfirmed: map[bc.Hash]*UTXO{
36 bc.NewHash([32]byte{0x01}): &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
40 &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
45 unconfirmed: map[bc.Hash]*UTXO{
46 bc.NewHash([32]byte{0x01}): &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
50 unconfirmed: map[bc.Hash]*UTXO{
51 bc.NewHash([32]byte{0x01}): &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
55 &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
60 unconfirmed: map[bc.Hash]*UTXO{
61 bc.NewHash([32]byte{0x01}): &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
65 unconfirmed: map[bc.Hash]*UTXO{
66 bc.NewHash([32]byte{0x01}): &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
67 bc.NewHash([32]byte{0x02}): &UTXO{OutputID: bc.NewHash([32]byte{0x02})},
68 bc.NewHash([32]byte{0x03}): &UTXO{OutputID: bc.NewHash([32]byte{0x03})},
72 &UTXO{OutputID: bc.NewHash([32]byte{0x02})},
73 &UTXO{OutputID: bc.NewHash([32]byte{0x03})},
78 for i, c := range cases {
79 c.before.AddUnconfirmedUtxo(c.addUtxos)
80 if !testutil.DeepEqual(c.before, c.after) {
81 t.Errorf("case %d: got %v want %v", i, c.before, c.after)
86 func TestCancel(t *testing.T) {
94 reserved: map[bc.Hash]uint64{},
95 reservations: map[uint64]*reservation{},
98 reserved: map[bc.Hash]uint64{},
99 reservations: map[uint64]*reservation{},
105 reserved: map[bc.Hash]uint64{
106 bc.NewHash([32]byte{0x01}): 1,
108 reservations: map[uint64]*reservation{
112 &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
115 expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
120 reserved: map[bc.Hash]uint64{},
121 reservations: map[uint64]*reservation{},
127 reserved: map[bc.Hash]uint64{
128 bc.NewHash([32]byte{0x01}): 1,
130 reservations: map[uint64]*reservation{
134 &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
137 expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
142 reserved: map[bc.Hash]uint64{
143 bc.NewHash([32]byte{0x01}): 1,
145 reservations: map[uint64]*reservation{
149 &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
152 expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
160 reserved: map[bc.Hash]uint64{
161 bc.NewHash([32]byte{0x01}): 1,
162 bc.NewHash([32]byte{0x02}): 3,
163 bc.NewHash([32]byte{0x03}): 3,
164 bc.NewHash([32]byte{0x04}): 3,
166 reservations: map[uint64]*reservation{
170 &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
173 expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
178 &UTXO{OutputID: bc.NewHash([32]byte{0x02})},
179 &UTXO{OutputID: bc.NewHash([32]byte{0x03})},
180 &UTXO{OutputID: bc.NewHash([32]byte{0x04})},
183 expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
188 reserved: map[bc.Hash]uint64{
189 bc.NewHash([32]byte{0x01}): 1,
191 reservations: map[uint64]*reservation{
195 &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
198 expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
206 for i, c := range cases {
207 c.before.cancel(c.cancelRid)
208 if !testutil.DeepEqual(c.before, c.after) {
209 t.Errorf("case %d: got %v want %v", i, c.before, c.after)
214 func TestRemoveUnconfirmedUtxo(t *testing.T) {
218 removeUtxos []*bc.Hash
222 unconfirmed: map[bc.Hash]*UTXO{},
225 unconfirmed: map[bc.Hash]*UTXO{},
227 removeUtxos: []*bc.Hash{},
231 unconfirmed: map[bc.Hash]*UTXO{
232 bc.Hash{V0: 1}: &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
236 unconfirmed: map[bc.Hash]*UTXO{},
238 removeUtxos: []*bc.Hash{
244 unconfirmed: map[bc.Hash]*UTXO{
245 bc.Hash{V0: 1}: &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
246 bc.Hash{V0: 2}: &UTXO{OutputID: bc.NewHash([32]byte{0x02})},
247 bc.Hash{V0: 3}: &UTXO{OutputID: bc.NewHash([32]byte{0x03})},
248 bc.Hash{V0: 4}: &UTXO{OutputID: bc.NewHash([32]byte{0x04})},
249 bc.Hash{V0: 5}: &UTXO{OutputID: bc.NewHash([32]byte{0x05})},
253 unconfirmed: map[bc.Hash]*UTXO{
254 bc.Hash{V0: 2}: &UTXO{OutputID: bc.NewHash([32]byte{0x02})},
255 bc.Hash{V0: 4}: &UTXO{OutputID: bc.NewHash([32]byte{0x04})},
258 removeUtxos: []*bc.Hash{
266 for i, c := range cases {
267 c.before.RemoveUnconfirmedUtxo(c.removeUtxos)
268 if !testutil.DeepEqual(c.before, c.after) {
269 t.Errorf("case %d: got %v want %v", i, c.before, c.after)
274 func TestReserve(t *testing.T) {
275 currentHeight := func() uint64 { return 9527 }
276 testDB := dbm.NewDB("testdb", "leveldb", "temp")
277 defer os.RemoveAll("temp")
289 currentHeight: currentHeight,
290 reserved: map[bc.Hash]uint64{},
291 reservations: map[uint64]*reservation{},
295 currentHeight: currentHeight,
296 reserved: map[bc.Hash]uint64{},
297 reservations: map[uint64]*reservation{},
300 err: ErrInsufficient,
305 currentHeight: currentHeight,
306 unconfirmed: map[bc.Hash]*UTXO{
307 bc.NewHash([32]byte{0x01}): &UTXO{
308 OutputID: bc.NewHash([32]byte{0x01}),
309 AccountID: "testAccount",
313 reserved: map[bc.Hash]uint64{},
314 reservations: map[uint64]*reservation{},
318 currentHeight: currentHeight,
319 unconfirmed: map[bc.Hash]*UTXO{
320 bc.NewHash([32]byte{0x01}): &UTXO{
321 OutputID: bc.NewHash([32]byte{0x01}),
322 AccountID: "testAccount",
326 reserved: map[bc.Hash]uint64{},
327 reservations: map[uint64]*reservation{},
330 err: ErrInsufficient,
335 currentHeight: currentHeight,
336 unconfirmed: map[bc.Hash]*UTXO{
337 bc.NewHash([32]byte{0x01}): &UTXO{
338 OutputID: bc.NewHash([32]byte{0x01}),
339 AccountID: "testAccount",
344 reserved: map[bc.Hash]uint64{},
345 reservations: map[uint64]*reservation{},
349 currentHeight: currentHeight,
350 unconfirmed: map[bc.Hash]*UTXO{
351 bc.NewHash([32]byte{0x01}): &UTXO{
352 OutputID: bc.NewHash([32]byte{0x01}),
353 AccountID: "testAccount",
358 reserved: map[bc.Hash]uint64{},
359 reservations: map[uint64]*reservation{},
367 currentHeight: currentHeight,
368 unconfirmed: map[bc.Hash]*UTXO{
369 bc.NewHash([32]byte{0x01}): &UTXO{
370 OutputID: bc.NewHash([32]byte{0x01}),
371 AccountID: "testAccount",
375 reserved: map[bc.Hash]uint64{
376 bc.NewHash([32]byte{0x01}): 0,
378 reservations: map[uint64]*reservation{},
382 currentHeight: currentHeight,
383 unconfirmed: map[bc.Hash]*UTXO{
384 bc.NewHash([32]byte{0x01}): &UTXO{
385 OutputID: bc.NewHash([32]byte{0x01}),
386 AccountID: "testAccount",
390 reserved: map[bc.Hash]uint64{
391 bc.NewHash([32]byte{0x01}): 0,
393 reservations: map[uint64]*reservation{},
401 currentHeight: currentHeight,
402 unconfirmed: map[bc.Hash]*UTXO{
403 bc.NewHash([32]byte{0x01}): &UTXO{
404 OutputID: bc.NewHash([32]byte{0x01}),
405 AccountID: "testAccount",
409 reserved: map[bc.Hash]uint64{},
410 reservations: map[uint64]*reservation{},
414 currentHeight: currentHeight,
415 unconfirmed: map[bc.Hash]*UTXO{
416 bc.NewHash([32]byte{0x01}): &UTXO{
417 OutputID: bc.NewHash([32]byte{0x01}),
418 AccountID: "testAccount",
422 reserved: map[bc.Hash]uint64{
423 bc.NewHash([32]byte{0x01}): 1,
425 reservations: map[uint64]*reservation{
430 OutputID: bc.NewHash([32]byte{0x01}),
431 AccountID: "testAccount",
436 expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
442 exp: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
447 currentHeight: currentHeight,
449 unconfirmed: map[bc.Hash]*UTXO{
450 bc.NewHash([32]byte{0x01}): &UTXO{
451 OutputID: bc.NewHash([32]byte{0x01}),
452 AccountID: "testAccount",
455 bc.NewHash([32]byte{0x02}): &UTXO{
456 OutputID: bc.NewHash([32]byte{0x02}),
457 AccountID: "testAccount",
460 bc.NewHash([32]byte{0x03}): &UTXO{
461 OutputID: bc.NewHash([32]byte{0x03}),
462 AccountID: "testAccount",
466 reserved: map[bc.Hash]uint64{
467 bc.NewHash([32]byte{0x01}): 1,
469 reservations: map[uint64]*reservation{},
473 currentHeight: currentHeight,
474 unconfirmed: map[bc.Hash]*UTXO{
475 bc.NewHash([32]byte{0x01}): &UTXO{
476 OutputID: bc.NewHash([32]byte{0x01}),
477 AccountID: "testAccount",
480 bc.NewHash([32]byte{0x02}): &UTXO{
481 OutputID: bc.NewHash([32]byte{0x02}),
482 AccountID: "testAccount",
485 bc.NewHash([32]byte{0x03}): &UTXO{
486 OutputID: bc.NewHash([32]byte{0x03}),
487 AccountID: "testAccount",
491 reserved: map[bc.Hash]uint64{
492 bc.NewHash([32]byte{0x01}): 1,
493 bc.NewHash([32]byte{0x02}): 2,
494 bc.NewHash([32]byte{0x03}): 2,
496 reservations: map[uint64]*reservation{
501 OutputID: bc.NewHash([32]byte{0x03}),
502 AccountID: "testAccount",
506 OutputID: bc.NewHash([32]byte{0x02}),
507 AccountID: "testAccount",
512 expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
518 exp: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
522 for i, c := range cases {
523 if _, err := c.before.Reserve("testAccount", &bc.AssetID{}, c.reserveAmount, true, c.exp); err != c.err {
524 t.Errorf("case %d: got error %v want error %v", i, err, c.err)
526 checkUtxoKeeperEqual(t, i, &c.before, &c.after)
530 func TestReserveParticular(t *testing.T) {
531 currentHeight := func() uint64 { return 9527 }
532 testDB := dbm.NewDB("testdb", "leveldb", "temp")
533 defer os.RemoveAll("temp")
545 currentHeight: currentHeight,
546 unconfirmed: map[bc.Hash]*UTXO{
547 bc.NewHash([32]byte{0x01}): &UTXO{
548 OutputID: bc.NewHash([32]byte{0x01}),
549 AccountID: "testAccount",
553 reserved: map[bc.Hash]uint64{
554 bc.NewHash([32]byte{0x01}): 0,
556 reservations: map[uint64]*reservation{},
560 currentHeight: currentHeight,
561 unconfirmed: map[bc.Hash]*UTXO{
562 bc.NewHash([32]byte{0x01}): &UTXO{
563 OutputID: bc.NewHash([32]byte{0x01}),
564 AccountID: "testAccount",
568 reserved: map[bc.Hash]uint64{
569 bc.NewHash([32]byte{0x01}): 0,
571 reservations: map[uint64]*reservation{},
573 reserveHash: bc.NewHash([32]byte{0x01}),
579 currentHeight: currentHeight,
580 unconfirmed: map[bc.Hash]*UTXO{
581 bc.NewHash([32]byte{0x01}): &UTXO{
582 OutputID: bc.NewHash([32]byte{0x01}),
583 AccountID: "testAccount",
588 reserved: map[bc.Hash]uint64{},
589 reservations: map[uint64]*reservation{},
593 currentHeight: currentHeight,
594 unconfirmed: map[bc.Hash]*UTXO{
595 bc.NewHash([32]byte{0x01}): &UTXO{
596 OutputID: bc.NewHash([32]byte{0x01}),
597 AccountID: "testAccount",
602 reserved: map[bc.Hash]uint64{},
603 reservations: map[uint64]*reservation{},
605 reserveHash: bc.NewHash([32]byte{0x01}),
611 currentHeight: currentHeight,
612 unconfirmed: map[bc.Hash]*UTXO{
613 bc.NewHash([32]byte{0x01}): &UTXO{
614 OutputID: bc.NewHash([32]byte{0x01}),
615 AccountID: "testAccount",
619 reserved: map[bc.Hash]uint64{},
620 reservations: map[uint64]*reservation{},
624 currentHeight: currentHeight,
625 unconfirmed: map[bc.Hash]*UTXO{
626 bc.NewHash([32]byte{0x01}): &UTXO{
627 OutputID: bc.NewHash([32]byte{0x01}),
628 AccountID: "testAccount",
632 reserved: map[bc.Hash]uint64{
633 bc.NewHash([32]byte{0x01}): 1,
635 reservations: map[uint64]*reservation{
640 OutputID: bc.NewHash([32]byte{0x01}),
641 AccountID: "testAccount",
646 expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
650 reserveHash: bc.NewHash([32]byte{0x01}),
652 exp: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC),
656 for i, c := range cases {
657 if _, err := c.before.ReserveParticular(c.reserveHash, true, c.exp); err != c.err {
658 t.Errorf("case %d: got error %v want error %v", i, err, c.err)
660 checkUtxoKeeperEqual(t, i, &c.before, &c.after)
664 func TestExpireReservation(t *testing.T) {
665 before := &utxoKeeper{
666 reservations: map[uint64]*reservation{
667 1: &reservation{expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC)},
668 2: &reservation{expiry: time.Date(3016, 8, 10, 0, 0, 0, 0, time.UTC)},
669 3: &reservation{expiry: time.Date(2016, 8, 10, 0, 0, 0, 0, time.UTC)},
670 4: &reservation{expiry: time.Date(3016, 8, 10, 0, 0, 0, 0, time.UTC)},
671 5: &reservation{expiry: time.Date(3016, 8, 10, 0, 0, 0, 0, time.UTC)},
674 after := &utxoKeeper{
675 reservations: map[uint64]*reservation{
676 2: &reservation{expiry: time.Date(3016, 8, 10, 0, 0, 0, 0, time.UTC)},
677 4: &reservation{expiry: time.Date(3016, 8, 10, 0, 0, 0, 0, time.UTC)},
678 5: &reservation{expiry: time.Date(3016, 8, 10, 0, 0, 0, 0, time.UTC)},
681 before.expireReservation(time.Date(2017, 8, 10, 0, 0, 0, 0, time.UTC))
682 checkUtxoKeeperEqual(t, 0, before, after)
685 func TestFindUtxos(t *testing.T) {
686 currentHeight := func() uint64 { return 9527 }
687 testDB := dbm.NewDB("testdb", "leveldb", "temp")
688 defer os.RemoveAll("temp")
695 immatureAmount uint64
700 currentHeight: currentHeight,
701 unconfirmed: map[bc.Hash]*UTXO{},
704 useUnconfirmed: true,
705 wantUtxos: []*UTXO{},
711 currentHeight: currentHeight,
712 unconfirmed: map[bc.Hash]*UTXO{},
716 OutputID: bc.NewHash([32]byte{0x01}),
717 AccountID: "testAccount",
721 OutputID: bc.NewHash([32]byte{0x02}),
722 AccountID: "testAccount",
723 AssetID: bc.AssetID{V0: 6},
727 useUnconfirmed: false,
730 OutputID: bc.NewHash([32]byte{0x01}),
731 AccountID: "testAccount",
740 currentHeight: currentHeight,
741 unconfirmed: map[bc.Hash]*UTXO{},
745 OutputID: bc.NewHash([32]byte{0x02}),
746 AccountID: "testAccount",
751 useUnconfirmed: false,
752 wantUtxos: []*UTXO{},
758 currentHeight: currentHeight,
759 unconfirmed: map[bc.Hash]*UTXO{
760 bc.NewHash([32]byte{0x01}): &UTXO{
761 OutputID: bc.NewHash([32]byte{0x01}),
762 AccountID: "testAccount",
769 OutputID: bc.NewHash([32]byte{0x02}),
770 AccountID: "testAccount",
774 useUnconfirmed: false,
777 OutputID: bc.NewHash([32]byte{0x02}),
778 AccountID: "testAccount",
787 currentHeight: currentHeight,
788 unconfirmed: map[bc.Hash]*UTXO{
789 bc.NewHash([32]byte{0x11}): &UTXO{
790 OutputID: bc.NewHash([32]byte{0x01}),
791 AccountID: "testAccount",
798 OutputID: bc.NewHash([32]byte{0x02}),
799 AccountID: "testAccount",
803 useUnconfirmed: true,
806 OutputID: bc.NewHash([32]byte{0x02}),
807 AccountID: "testAccount",
811 OutputID: bc.NewHash([32]byte{0x01}),
812 AccountID: "testAccount",
821 currentHeight: currentHeight,
822 unconfirmed: map[bc.Hash]*UTXO{
823 bc.NewHash([32]byte{0x01}): &UTXO{
824 OutputID: bc.NewHash([32]byte{0x01}),
825 AccountID: "testAccount",
828 bc.NewHash([32]byte{0x02}): &UTXO{
829 OutputID: bc.NewHash([32]byte{0x02}),
837 OutputID: bc.NewHash([32]byte{0x03}),
838 AccountID: "testAccount",
842 OutputID: bc.NewHash([32]byte{0x04}),
847 useUnconfirmed: true,
850 OutputID: bc.NewHash([32]byte{0x03}),
851 AccountID: "testAccount",
855 OutputID: bc.NewHash([32]byte{0x01}),
856 AccountID: "testAccount",
864 for i, c := range cases {
865 for _, u := range c.dbUtxos {
866 data, err := json.Marshal(u)
870 testDB.Set(StandardUTXOKey(u.OutputID), data)
873 gotUtxos, immatureAmount := c.uk.findUtxos("testAccount", &bc.AssetID{}, c.useUnconfirmed)
874 if !testutil.DeepEqual(gotUtxos, c.wantUtxos) {
875 t.Errorf("case %d: got %v want %v", i, gotUtxos, c.wantUtxos)
877 if immatureAmount != c.immatureAmount {
878 t.Errorf("case %d: got %v want %v", i, immatureAmount, c.immatureAmount)
881 for _, u := range c.dbUtxos {
882 testDB.Delete(StandardUTXOKey(u.OutputID))
887 func TestFindUtxo(t *testing.T) {
888 currentHeight := func() uint64 { return 9527 }
889 testDB := dbm.NewDB("testdb", "leveldb", "temp")
890 defer os.RemoveAll("temp")
894 dbUtxos map[string]*UTXO
903 currentHeight: currentHeight,
904 unconfirmed: map[bc.Hash]*UTXO{},
906 dbUtxos: map[string]*UTXO{},
907 outHash: bc.NewHash([32]byte{0x01}),
914 currentHeight: currentHeight,
915 unconfirmed: map[bc.Hash]*UTXO{
916 bc.NewHash([32]byte{0x01}): &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
919 dbUtxos: map[string]*UTXO{},
920 outHash: bc.NewHash([32]byte{0x01}),
922 useUnconfirmed: false,
928 currentHeight: currentHeight,
929 unconfirmed: map[bc.Hash]*UTXO{
930 bc.NewHash([32]byte{0x01}): &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
933 dbUtxos: map[string]*UTXO{},
934 outHash: bc.NewHash([32]byte{0x01}),
935 wantUtxo: &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
936 useUnconfirmed: true,
942 currentHeight: currentHeight,
943 unconfirmed: map[bc.Hash]*UTXO{},
945 dbUtxos: map[string]*UTXO{
946 string(StandardUTXOKey(bc.NewHash([32]byte{0x01}))): &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
948 outHash: bc.NewHash([32]byte{0x01}),
949 wantUtxo: &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
950 useUnconfirmed: false,
956 currentHeight: currentHeight,
957 unconfirmed: map[bc.Hash]*UTXO{},
959 dbUtxos: map[string]*UTXO{
960 string(ContractUTXOKey(bc.NewHash([32]byte{0x01}))): &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
962 outHash: bc.NewHash([32]byte{0x01}),
963 wantUtxo: &UTXO{OutputID: bc.NewHash([32]byte{0x01})},
964 useUnconfirmed: false,
969 for i, c := range cases {
970 for k, u := range c.dbUtxos {
971 data, err := json.Marshal(u)
975 testDB.Set([]byte(k), data)
978 gotUtxo, err := c.uk.findUtxo(c.outHash, c.useUnconfirmed)
979 if !testutil.DeepEqual(gotUtxo, c.wantUtxo) {
980 t.Errorf("case %d: got %v want %v", i, gotUtxo, c.wantUtxo)
983 t.Errorf("case %d: got %v want %v", i, err, c.err)
986 for _, u := range c.dbUtxos {
987 testDB.Delete(StandardUTXOKey(u.OutputID))
992 func TestOptUTXOs(t *testing.T) {
999 reservedAmount uint64
1003 reserved: map[bc.Hash]uint64{
1004 bc.NewHash([32]byte{0x01}): 1,
1009 wantUtxos: []*UTXO{},
1015 reserved: map[bc.Hash]uint64{
1016 bc.NewHash([32]byte{0x01}): 1,
1020 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1023 wantUtxos: []*UTXO{},
1029 reserved: map[bc.Hash]uint64{
1030 bc.NewHash([32]byte{0x01}): 1,
1034 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1035 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 3},
1036 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 5},
1040 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 5},
1041 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 3},
1048 reserved: map[bc.Hash]uint64{
1049 bc.NewHash([32]byte{0x01}): 1,
1050 bc.NewHash([32]byte{0x02}): 2,
1051 bc.NewHash([32]byte{0x03}): 3,
1055 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1056 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 3},
1057 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 5},
1060 wantUtxos: []*UTXO{},
1067 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1068 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 3},
1069 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 5},
1073 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1081 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 2},
1082 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 3},
1083 &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 5},
1087 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 3},
1088 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 2},
1096 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1097 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 1},
1098 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 1},
1099 &UTXO{OutputID: bc.NewHash([32]byte{0x04}), Amount: 1},
1100 &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 1},
1101 &UTXO{OutputID: bc.NewHash([32]byte{0x06}), Amount: 1},
1102 &UTXO{OutputID: bc.NewHash([32]byte{0x08}), Amount: 6},
1106 &UTXO{OutputID: bc.NewHash([32]byte{0x08}), Amount: 6},
1114 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1115 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 1},
1116 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 1},
1117 &UTXO{OutputID: bc.NewHash([32]byte{0x04}), Amount: 1},
1118 &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 1},
1119 &UTXO{OutputID: bc.NewHash([32]byte{0x06}), Amount: 1},
1120 &UTXO{OutputID: bc.NewHash([32]byte{0x08}), Amount: 6},
1124 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 1},
1125 &UTXO{OutputID: bc.NewHash([32]byte{0x04}), Amount: 1},
1126 &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 1},
1127 &UTXO{OutputID: bc.NewHash([32]byte{0x06}), Amount: 1},
1128 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1136 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1137 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 3},
1138 &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 5},
1139 &UTXO{OutputID: bc.NewHash([32]byte{0x07}), Amount: 7},
1140 &UTXO{OutputID: bc.NewHash([32]byte{0x11}), Amount: 11},
1141 &UTXO{OutputID: bc.NewHash([32]byte{0x13}), Amount: 13},
1142 &UTXO{OutputID: bc.NewHash([32]byte{0x23}), Amount: 23},
1143 &UTXO{OutputID: bc.NewHash([32]byte{0x31}), Amount: 31},
1147 &UTXO{OutputID: bc.NewHash([32]byte{0x07}), Amount: 7},
1148 &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 5},
1149 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 3},
1157 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1161 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1169 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1170 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 2},
1171 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 3},
1172 &UTXO{OutputID: bc.NewHash([32]byte{0x04}), Amount: 4},
1173 &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 5},
1174 &UTXO{OutputID: bc.NewHash([32]byte{0x06}), Amount: 6},
1175 &UTXO{OutputID: bc.NewHash([32]byte{0x07}), Amount: 7},
1176 &UTXO{OutputID: bc.NewHash([32]byte{0x08}), Amount: 8},
1177 &UTXO{OutputID: bc.NewHash([32]byte{0x09}), Amount: 9},
1178 &UTXO{OutputID: bc.NewHash([32]byte{0x10}), Amount: 10},
1179 &UTXO{OutputID: bc.NewHash([32]byte{0x11}), Amount: 11},
1180 &UTXO{OutputID: bc.NewHash([32]byte{0x12}), Amount: 12},
1184 &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 5},
1185 &UTXO{OutputID: bc.NewHash([32]byte{0x04}), Amount: 4},
1186 &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 3},
1187 &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 2},
1188 &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
1195 for i, c := range cases {
1196 got, optAmount, reservedAmount := c.uk.optUTXOs(c.input, c.inputAmount)
1197 if !testutil.DeepEqual(got, c.wantUtxos) {
1198 t.Errorf("case %d: utxos got %v want %v", i, got, c.wantUtxos)
1200 if optAmount != c.optAmount {
1201 t.Errorf("case %d: utxos got %v want %v", i, optAmount, c.optAmount)
1203 if reservedAmount != c.reservedAmount {
1204 t.Errorf("case %d: reservedAmount got %v want %v", i, reservedAmount, c.reservedAmount)
1209 func checkUtxoKeeperEqual(t *testing.T, i int, a, b *utxoKeeper) {
1210 if !testutil.DeepEqual(a.unconfirmed, b.unconfirmed) {
1211 t.Errorf("case %d: unconfirmed got %v want %v", i, a.unconfirmed, b.unconfirmed)
1213 if !testutil.DeepEqual(a.reserved, b.reserved) {
1214 t.Errorf("case %d: reserved got %v want %v", i, a.reserved, b.reserved)
1216 if !testutil.DeepEqual(a.reservations, b.reservations) {
1217 t.Errorf("case %d: reservations got %v want %v", i, a.reservations, b.reservations)