OSDN Git Service

update
[bytom/vapor.git] / wallet / utxo_test.go
index 75ddc60..30c55c8 100644 (file)
@@ -14,12 +14,13 @@ import (
        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")
@@ -94,18 +95,31 @@ func TestGetAccountUtxos(t *testing.T) {
                },
                {
                        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{
@@ -194,10 +208,14 @@ func TestGetAccountUtxos(t *testing.T) {
                        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)
                }
 
-               acccountStore := database.NewAccountStore(testDB)
+               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)
@@ -206,6 +224,8 @@ func TestGetAccountUtxos(t *testing.T) {
                }
 
                for k := range c.dbUtxos {
+                       // newKey, _ := hex.DecodeString(k)
+                       // testDB.Delete([]byte(k))
                        testDB.Delete([]byte(k))
                }
        }
@@ -213,7 +233,7 @@ func TestGetAccountUtxos(t *testing.T) {
 
 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")
@@ -367,6 +387,7 @@ func TestFilterAccountUtxo(t *testing.T) {
                        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