OSDN Git Service

uxto view test (#396)
authorwyjDoraemon <46176410+wyjDoraemon@users.noreply.github.com>
Thu, 5 Sep 2019 08:10:18 +0000 (16:10 +0800)
committerPaladz <yzhu101@uottawa.ca>
Thu, 5 Sep 2019 08:10:18 +0000 (16:10 +0800)
* add database utxo test

* add database utxo_view test case

* db close

database/utxo_view_test.go

index 0d6bc82..b776b54 100644 (file)
@@ -92,13 +92,20 @@ func TestSaveUtxoView(t *testing.T) {
 
 func TestGetTransactionsUtxo(t *testing.T) {
        testDB := dbm.NewDB("testdb", "leveldb", "temp")
-       defer os.RemoveAll("temp")
+       defer func() {
+               testDB.Close()
+               os.RemoveAll("temp")
+       }()
 
        batch := testDB.NewBatch()
        inputView := state.NewUtxoViewpoint()
        for i := 0; i <= 2; i++ {
                inputView.Entries[bc.Hash{V0: uint64(i)}] = storage.NewUtxoEntry(storage.NormalUTXOType, uint64(i), false)
        }
+       inputView.Entries[bc.Hash{V0: uint64(3)}] = storage.NewUtxoEntry(storage.CrosschainUTXOType, uint64(3), true)
+       inputView.Entries[bc.Hash{V0: uint64(4)}] = storage.NewUtxoEntry(storage.CoinbaseUTXOType, uint64(4), false)
+       inputView.Entries[bc.Hash{V0: uint64(5)}] = storage.NewUtxoEntry(storage.VoteUTXOType, uint64(5), false)
+
        saveUtxoView(batch, inputView)
        batch.Write()
 
@@ -122,6 +129,43 @@ func TestGetTransactionsUtxo(t *testing.T) {
                {
                        txs: []*bc.Tx{
                                &bc.Tx{
+                                       MainchainOutputIDs: []bc.Hash{
+                                               bc.Hash{V0: 10},
+                                               bc.Hash{V0: 3},
+                                       },
+                               },
+                       },
+                       inputView: state.NewUtxoViewpoint(),
+                       fetchView: &state.UtxoViewpoint{
+                               Entries: map[bc.Hash]*storage.UtxoEntry{
+                                       bc.Hash{V0: 10}: storage.NewUtxoEntry(storage.CrosschainUTXOType, 0, false),
+                                       bc.Hash{V0: 3}:  storage.NewUtxoEntry(storage.CrosschainUTXOType, 3, true),
+                               },
+                       },
+                       err: false,
+               },
+               {
+                       txs: []*bc.Tx{
+                               &bc.Tx{
+                                       SpentOutputIDs: []bc.Hash{
+                                               bc.Hash{V0: 4},
+                                               bc.Hash{V0: 5},
+                                               bc.Hash{V0: 6},//no spentOutputID store
+                                       },
+                               },
+                       },
+                       inputView: state.NewUtxoViewpoint(),
+                       fetchView: &state.UtxoViewpoint{
+                               Entries: map[bc.Hash]*storage.UtxoEntry{
+                                       bc.Hash{V0: 4}: storage.NewUtxoEntry(storage.CoinbaseUTXOType, 4, false),
+                                       bc.Hash{V0: 5}: storage.NewUtxoEntry(storage.VoteUTXOType, 5, false),
+                               },
+                       },
+                       err: false,
+               },
+               {
+                       txs: []*bc.Tx{
+                               &bc.Tx{
                                        SpentOutputIDs: []bc.Hash{bc.Hash{V0: 0}},
                                },
                        },