OSDN Git Service

feat: add build crosschain input (#91)
[bytom/vapor.git] / database / store_test.go
index deffc05..e9d7527 100644 (file)
@@ -15,9 +15,13 @@ import (
 )
 
 func TestLoadBlockIndex(t *testing.T) {
-       defer os.RemoveAll("temp")
+       config.CommonConfig = config.DefaultConfig()
        testDB := dbm.NewDB("testdb", "leveldb", "temp")
        store := NewStore(testDB)
+       defer func() {
+               testDB.Close()
+               os.RemoveAll("temp")
+       }()
 
        block := config.GenesisBlock()
        txStatus := bc.NewTransactionStatus()
@@ -70,8 +74,11 @@ func TestLoadBlockIndexBestHeight(t *testing.T) {
                },
        }
 
-       defer os.RemoveAll("temp")
        testDB := dbm.NewDB("testdb", "leveldb", "temp")
+       defer func() {
+               testDB.Close()
+               os.RemoveAll("temp")
+       }()
        store := NewStore(testDB)
        var savedBlocks []types.Block
 
@@ -104,9 +111,12 @@ func TestLoadBlockIndexBestHeight(t *testing.T) {
 }
 
 func TestLoadBlockIndexEquals(t *testing.T) {
-       defer os.RemoveAll("temp")
        testDB := dbm.NewDB("testdb", "leveldb", "temp")
        store := NewStore(testDB)
+       defer func() {
+               testDB.Close()
+               os.RemoveAll("temp")
+       }()
 
        block := config.GenesisBlock()
        txStatus := bc.NewTransactionStatus()
@@ -141,17 +151,24 @@ func TestLoadBlockIndexEquals(t *testing.T) {
                t.Errorf("got block index:%v, expect block index:%v", index, expectBlockIndex)
        }
 }
+
 func TestSaveChainStatus(t *testing.T) {
-       defer os.RemoveAll("temp")
        testDB := dbm.NewDB("testdb", "leveldb", "temp")
+       defer func() {
+               testDB.Close()
+               os.RemoveAll("temp")
+       }()
+
        store := NewStore(testDB)
 
        node := &state.BlockNode{Height: 100, Hash: bc.Hash{V0: 0, V1: 1, V2: 2, V3: 3}}
        view := &state.UtxoViewpoint{
                Entries: map[bc.Hash]*storage.UtxoEntry{
-                       bc.Hash{V0: 1, V1: 2, V2: 3, V3: 4}: &storage.UtxoEntry{IsCoinBase: false, BlockHeight: 100, Spent: false},
-                       bc.Hash{V0: 1, V1: 2, V2: 3, V3: 4}: &storage.UtxoEntry{IsCoinBase: true, BlockHeight: 100, Spent: true},
-                       bc.Hash{V0: 1, V1: 1, V2: 3, V3: 4}: &storage.UtxoEntry{IsCoinBase: false, BlockHeight: 100, Spent: true},
+                       bc.Hash{V0: 1, V1: 2, V2: 3, V3: 4}: &storage.UtxoEntry{Type: storage.NormalUTXOType, BlockHeight: 100, Spent: false},
+                       bc.Hash{V0: 1, V1: 2, V2: 3, V3: 4}: &storage.UtxoEntry{Type: storage.CoinbaseUTXOType, BlockHeight: 100, Spent: true},
+                       bc.Hash{V0: 1, V1: 1, V2: 3, V3: 4}: &storage.UtxoEntry{Type: storage.NormalUTXOType, BlockHeight: 100, Spent: true},
+                       bc.Hash{V0: 1, V1: 1, V2: 3, V3: 5}: &storage.UtxoEntry{Type: storage.CrosschainUTXOType, BlockHeight: 100, Spent: false},
+                       bc.Hash{V0: 1, V1: 1, V2: 3, V3: 6}: &storage.UtxoEntry{Type: storage.CrosschainUTXOType, BlockHeight: 100, Spent: true},
                },
        }
 
@@ -165,7 +182,10 @@ func TestSaveChainStatus(t *testing.T) {
        }
 
        for hash, utxo := range view.Entries {
-               if utxo.Spent && !utxo.IsCoinBase {
+               if (utxo.Type == storage.NormalUTXOType) && utxo.Spent {
+                       continue
+               }
+               if (utxo.Type == storage.CrosschainUTXOType) && (!utxo.Spent) {
                        continue
                }
 
@@ -181,8 +201,12 @@ func TestSaveChainStatus(t *testing.T) {
 }
 
 func TestSaveBlock(t *testing.T) {
-       defer os.RemoveAll("temp")
        testDB := dbm.NewDB("testdb", "leveldb", "temp")
+       defer func() {
+               testDB.Close()
+               os.RemoveAll("temp")
+       }()
+
        store := NewStore(testDB)
 
        block := config.GenesisBlock()