dbm "github.com/vapor/database/leveldb"
"github.com/vapor/protocol/bc"
"github.com/vapor/protocol/bc/types"
+ "github.com/vapor/test/mock"
"github.com/vapor/testutil"
)
func TestGetAccountUtxos(t *testing.T) {
testDB := dbm.NewDB("testdb", "leveldb", "temp")
- testStore := database.NewWalletStore(testDB)
+ testStore := mock.NewMockWalletStore(testDB)
defer func() {
testDB.Close()
os.RemoveAll("temp")
},
{
dbUtxos: map[string]*account.UTXO{
- string(database.StandardUTXOKey(bc.Hash{V0: 1})): &account.UTXO{
+ string(mock.StandardUTXOKey(bc.Hash{V0: 1})): &account.UTXO{
OutputID: bc.Hash{V0: 1},
},
- string(database.StandardUTXOKey(bc.Hash{V0: 1, V1: 2})): &account.UTXO{
+ string(mock.StandardUTXOKey(bc.Hash{V0: 1, V1: 2})): &account.UTXO{
OutputID: bc.Hash{V0: 1, V1: 2},
},
- string(database.StandardUTXOKey(bc.Hash{V0: 2})): &account.UTXO{
+ string(mock.StandardUTXOKey(bc.Hash{V0: 2})): &account.UTXO{
OutputID: bc.Hash{V0: 2},
},
- string(database.StandardUTXOKey(bc.Hash{V0: 2, V1: 2})): &account.UTXO{
+ string(mock.StandardUTXOKey(bc.Hash{V0: 2, V1: 2})): &account.UTXO{
OutputID: bc.Hash{V0: 2, V1: 2},
},
+
+ // hex.EncodeToString(mock.StandardUTXOKey(bc.Hash{V0: 1})): &account.UTXO{
+ // OutputID: bc.Hash{V0: 1},
+ // },
+ // hex.EncodeToString(mock.StandardUTXOKey(bc.Hash{V0: 1, V1: 2})): &account.UTXO{
+ // OutputID: bc.Hash{V0: 1, V1: 2},
+ // },
+ // hex.EncodeToString(mock.StandardUTXOKey(bc.Hash{V0: 2})): &account.UTXO{
+ // OutputID: bc.Hash{V0: 2},
+ // },
+ // hex.EncodeToString(mock.StandardUTXOKey(bc.Hash{V0: 2, V1: 2})): &account.UTXO{
+ // OutputID: bc.Hash{V0: 2, V1: 2},
+ // },
},
unconfirmedUtxos: []*account.UTXO{
&account.UTXO{
if err != nil {
t.Error(err)
}
+ fmt.Println("k:", []byte(k))
+ // newKey, _ := hex.DecodeString(k)
+ // fmt.Println("newkey:", newKey)
+ // testDB.Set([]byte(k), data)
testDB.Set([]byte(k), data)
}
- w.AccountMgr = account.NewManager(testDB, nil)
+ acccountStore := mock.NewMockAccountStore(testDB)
+ w.AccountMgr = account.NewManager(acccountStore, nil)
w.AccountMgr.AddUnconfirmedUtxo(c.unconfirmedUtxos)
gotUtxos := w.GetAccountUtxos("", c.id, c.unconfirmed, c.isSmartContract, false)
if !testutil.DeepEqual(gotUtxos, c.wantUtxos) {
}
for k := range c.dbUtxos {
+ // newKey, _ := hex.DecodeString(k)
+ // testDB.Delete([]byte(k))
testDB.Delete([]byte(k))
}
}
func TestFilterAccountUtxo(t *testing.T) {
testDB := dbm.NewDB("testdb", "leveldb", "temp")
- testStore := database.NewWalletStore(testDB)
+ testStore := mock.NewMockWalletStore(testDB)
defer func() {
testDB.Close()
os.RemoveAll("temp")
testDB.Set(key, data)
}
+ fmt.Println("len(c.input):", len(c.input))
gotUtxos := w.filterAccountUtxo(c.input)
sort.Slice(gotUtxos[:], func(i, j int) bool {
return gotUtxos[i].Amount < gotUtxos[j].Amount