OSDN Git Service

edit code while reviewing the code (#255)
[bytom/vapor.git] / database / utxo_view_test.go
index 525624a..0d6bc82 100644 (file)
@@ -14,7 +14,10 @@ import (
 func TestSaveUtxoView(t *testing.T) {
        testDB := dbm.NewDB("testdb", "leveldb", "temp")
        batch := testDB.NewBatch()
-       defer os.RemoveAll("temp")
+       defer func() {
+               testDB.Close()
+               os.RemoveAll("temp")
+       }()
 
        cases := []struct {
                hash      bc.Hash
@@ -23,24 +26,44 @@ func TestSaveUtxoView(t *testing.T) {
        }{
                {
                        hash:      bc.Hash{V0: 0},
-                       utxoEntry: storage.NewUtxoEntry(true, 0, true),
+                       utxoEntry: storage.NewUtxoEntry(storage.CoinbaseUTXOType, 0, true),
                        exist:     true,
                },
                {
                        hash:      bc.Hash{V0: 1},
-                       utxoEntry: storage.NewUtxoEntry(true, 0, false),
+                       utxoEntry: storage.NewUtxoEntry(storage.CoinbaseUTXOType, 0, false),
                        exist:     true,
                },
                {
                        hash:      bc.Hash{V0: 2},
-                       utxoEntry: storage.NewUtxoEntry(false, 0, false),
+                       utxoEntry: storage.NewUtxoEntry(storage.NormalUTXOType, 0, false),
                        exist:     true,
                },
                {
                        hash:      bc.Hash{V0: 3},
-                       utxoEntry: storage.NewUtxoEntry(false, 0, true),
+                       utxoEntry: storage.NewUtxoEntry(storage.NormalUTXOType, 0, true),
+                       exist:     false,
+               },
+               {
+                       hash:      bc.Hash{V0: 4},
+                       utxoEntry: storage.NewUtxoEntry(storage.CrosschainUTXOType, 0, true),
+                       exist:     true,
+               },
+               {
+                       hash:      bc.Hash{V0: 5},
+                       utxoEntry: storage.NewUtxoEntry(storage.CrosschainUTXOType, 0, false),
                        exist:     false,
                },
+               {
+                       hash:      bc.Hash{V0: 6},
+                       utxoEntry: storage.NewUtxoEntry(storage.VoteUTXOType, 0, true),
+                       exist:     true,
+               },
+               {
+                       hash:      bc.Hash{V0: 7},
+                       utxoEntry: storage.NewUtxoEntry(storage.VoteUTXOType, 0, false),
+                       exist:     true,
+               },
        }
 
        view := state.NewUtxoViewpoint()
@@ -74,7 +97,7 @@ func TestGetTransactionsUtxo(t *testing.T) {
        batch := testDB.NewBatch()
        inputView := state.NewUtxoViewpoint()
        for i := 0; i <= 2; i++ {
-               inputView.Entries[bc.Hash{V0: uint64(i)}] = storage.NewUtxoEntry(false, uint64(i), false)
+               inputView.Entries[bc.Hash{V0: uint64(i)}] = storage.NewUtxoEntry(storage.NormalUTXOType, uint64(i), false)
        }
        saveUtxoView(batch, inputView)
        batch.Write()
@@ -105,7 +128,7 @@ func TestGetTransactionsUtxo(t *testing.T) {
                        inputView: state.NewUtxoViewpoint(),
                        fetchView: &state.UtxoViewpoint{
                                Entries: map[bc.Hash]*storage.UtxoEntry{
-                                       bc.Hash{V0: 0}: storage.NewUtxoEntry(false, 0, false),
+                                       bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, false),
                                },
                        },
                        err: false,
@@ -122,8 +145,8 @@ func TestGetTransactionsUtxo(t *testing.T) {
                        inputView: state.NewUtxoViewpoint(),
                        fetchView: &state.UtxoViewpoint{
                                Entries: map[bc.Hash]*storage.UtxoEntry{
-                                       bc.Hash{V0: 0}: storage.NewUtxoEntry(false, 0, false),
-                                       bc.Hash{V0: 1}: storage.NewUtxoEntry(false, 1, false),
+                                       bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, false),
+                                       bc.Hash{V0: 1}: storage.NewUtxoEntry(storage.NormalUTXOType, 1, false),
                                },
                        },
                        err: false,
@@ -145,9 +168,9 @@ func TestGetTransactionsUtxo(t *testing.T) {
                        inputView: state.NewUtxoViewpoint(),
                        fetchView: &state.UtxoViewpoint{
                                Entries: map[bc.Hash]*storage.UtxoEntry{
-                                       bc.Hash{V0: 0}: storage.NewUtxoEntry(false, 0, false),
-                                       bc.Hash{V0: 1}: storage.NewUtxoEntry(false, 1, false),
-                                       bc.Hash{V0: 2}: storage.NewUtxoEntry(false, 2, false),
+                                       bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, false),
+                                       bc.Hash{V0: 1}: storage.NewUtxoEntry(storage.NormalUTXOType, 1, false),
+                                       bc.Hash{V0: 2}: storage.NewUtxoEntry(storage.NormalUTXOType, 2, false),
                                },
                        },
                        err: false,
@@ -160,12 +183,12 @@ func TestGetTransactionsUtxo(t *testing.T) {
                        },
                        inputView: &state.UtxoViewpoint{
                                Entries: map[bc.Hash]*storage.UtxoEntry{
-                                       bc.Hash{V0: 0}: storage.NewUtxoEntry(false, 1, false),
+                                       bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 1, false),
                                },
                        },
                        fetchView: &state.UtxoViewpoint{
                                Entries: map[bc.Hash]*storage.UtxoEntry{
-                                       bc.Hash{V0: 0}: storage.NewUtxoEntry(false, 1, false),
+                                       bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 1, false),
                                },
                        },
                        err: false,