"testing"
"time"
- dbm "github.com/tendermint/tmlibs/db"
-
"github.com/bytom/protocol/bc"
"github.com/bytom/testutil"
+ dbm "github.com/bytom/database/leveldb"
)
func TestAddUnconfirmedUtxo(t *testing.T) {
id: 2,
utxos: []*UTXO{
&UTXO{
- OutputID: bc.NewHash([32]byte{0x02}),
+ OutputID: bc.NewHash([32]byte{0x03}),
AccountID: "testAccount",
- Amount: 5,
+ Amount: 7,
},
&UTXO{
- OutputID: bc.NewHash([32]byte{0x03}),
+ OutputID: bc.NewHash([32]byte{0x02}),
AccountID: "testAccount",
- Amount: 7,
+ Amount: 5,
},
},
change: 4,
},
},
input: []*UTXO{
- &UTXO{
- OutputID: bc.NewHash([32]byte{0x01}),
- Amount: 1,
- },
+ &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
},
inputAmount: 13,
wantUtxos: []*UTXO{},
},
},
input: []*UTXO{
- &UTXO{
- OutputID: bc.NewHash([32]byte{0x01}),
- Amount: 1,
- },
- &UTXO{
- OutputID: bc.NewHash([32]byte{0x02}),
- Amount: 3,
- },
- &UTXO{
- OutputID: bc.NewHash([32]byte{0x03}),
- Amount: 5,
- },
+ &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 3},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 5},
},
inputAmount: 13,
wantUtxos: []*UTXO{
- &UTXO{
- OutputID: bc.NewHash([32]byte{0x02}),
- Amount: 3,
- },
- &UTXO{
- OutputID: bc.NewHash([32]byte{0x03}),
- Amount: 5,
- },
+ &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 5},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 3},
},
optAmount: 8,
reservedAmount: 1,
},
+ {
+ uk: utxoKeeper{
+ reserved: map[bc.Hash]uint64{
+ bc.NewHash([32]byte{0x01}): 1,
+ bc.NewHash([32]byte{0x02}): 2,
+ bc.NewHash([32]byte{0x03}): 3,
+ },
+ },
+ input: []*UTXO{
+ &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 3},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 5},
+ },
+ inputAmount: 1,
+ wantUtxos: []*UTXO{},
+ optAmount: 0,
+ reservedAmount: 9,
+ },
+ {
+ uk: utxoKeeper{},
+ input: []*UTXO{
+ &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 3},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 5},
+ },
+ inputAmount: 1,
+ wantUtxos: []*UTXO{
+ &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
+ },
+ optAmount: 1,
+ reservedAmount: 0,
+ },
+ {
+ uk: utxoKeeper{},
+ input: []*UTXO{
+ &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 2},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 3},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 5},
+ },
+ inputAmount: 5,
+ wantUtxos: []*UTXO{
+ &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 3},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 2},
+ },
+ optAmount: 5,
+ reservedAmount: 0,
+ },
+ {
+ uk: utxoKeeper{},
+ input: []*UTXO{
+ &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x04}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x06}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x08}), Amount: 6},
+ },
+ inputAmount: 6,
+ wantUtxos: []*UTXO{
+ &UTXO{OutputID: bc.NewHash([32]byte{0x08}), Amount: 6},
+ },
+ optAmount: 6,
+ reservedAmount: 0,
+ },
+ {
+ uk: utxoKeeper{},
+ input: []*UTXO{
+ &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x04}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x06}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x08}), Amount: 6},
+ },
+ inputAmount: 5,
+ wantUtxos: []*UTXO{
+ &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x04}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x06}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
+ },
+ optAmount: 5,
+ reservedAmount: 0,
+ },
+ {
+ uk: utxoKeeper{},
+ input: []*UTXO{
+ &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 3},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 5},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x07}), Amount: 7},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x11}), Amount: 11},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x13}), Amount: 13},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x23}), Amount: 23},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x31}), Amount: 31},
+ },
+ inputAmount: 13,
+ wantUtxos: []*UTXO{
+ &UTXO{OutputID: bc.NewHash([32]byte{0x07}), Amount: 7},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 5},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 3},
+ },
+ optAmount: 15,
+ reservedAmount: 0,
+ },
+ {
+ uk: utxoKeeper{},
+ input: []*UTXO{
+ &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
+ },
+ inputAmount: 1,
+ wantUtxos: []*UTXO{
+ &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
+ },
+ optAmount: 1,
+ reservedAmount: 0,
+ },
+ {
+ uk: utxoKeeper{},
+ input: []*UTXO{
+ &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 2},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 3},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x04}), Amount: 4},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 5},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x06}), Amount: 6},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x07}), Amount: 7},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x08}), Amount: 8},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x09}), Amount: 9},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x10}), Amount: 10},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x11}), Amount: 11},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x12}), Amount: 12},
+ },
+ inputAmount: 15,
+ wantUtxos: []*UTXO{
+ &UTXO{OutputID: bc.NewHash([32]byte{0x05}), Amount: 5},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x04}), Amount: 4},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x03}), Amount: 3},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x02}), Amount: 2},
+ &UTXO{OutputID: bc.NewHash([32]byte{0x01}), Amount: 1},
+ },
+ optAmount: 15,
+ reservedAmount: 0,
+ },
}
for i, c := range cases {