OSDN Git Service

add test
authoroys <oys@oysdeMBP.localdomain>
Thu, 4 Jul 2019 08:20:16 +0000 (16:20 +0800)
committeroys <oys@oysdeMBP.localdomain>
Thu, 4 Jul 2019 08:20:16 +0000 (16:20 +0800)
protocol/state/utxo_view.go
protocol/state/utxo_view_test.go

index d1d403d..90c71b1 100644 (file)
@@ -96,10 +96,10 @@ func (view *UtxoViewpoint) ApplyTransaction(block *bc.Block, tx *bc.Tx, statusFa
 
                switch output := entryOutput.(type) {
                case *bc.IntraChainOutput:
-                       assetID = *output.Source.Value.AssetId
                        if output.Source.Value.Amount == uint64(0) {
                                continue
                        }
+                       assetID = *output.Source.Value.AssetId
                case *bc.VoteOutput:
                        assetID = *output.Source.Value.AssetId
                        utxoType = storage.VoteUTXOType
@@ -205,10 +205,10 @@ func (view *UtxoViewpoint) DetachTransaction(tx *bc.Tx, statusFail bool) error {
                utxoType := storage.NormalUTXOType
                switch output := entryOutput.(type) {
                case *bc.IntraChainOutput:
-                       assetID = *output.Source.Value.AssetId
                        if output.Source.Value.Amount == uint64(0) {
                                continue
                        }
+                       assetID = *output.Source.Value.AssetId
                case *bc.VoteOutput:
                        assetID = *output.Source.Value.AssetId
                        utxoType = storage.VoteUTXOType
index e2697fa..a41285c 100644 (file)
@@ -19,6 +19,24 @@ var defaultEntry = map[bc.Hash]bc.Entry{
        },
 }
 
+var coinbaseEntry = map[bc.Hash]bc.Entry{
+       bc.Hash{V0: 0}: &bc.IntraChainOutput{
+               Source: &bc.ValueSource{
+                       Value: &bc.AssetAmount{
+                               AssetId: consensus.BTMAssetID,
+                       },
+               },
+       },
+       bc.Hash{V0: 1}: &bc.IntraChainOutput{
+               Source: &bc.ValueSource{
+                       Value: &bc.AssetAmount{
+                               AssetId: consensus.BTMAssetID,
+                               Amount:  uint64(100),
+                       },
+               },
+       },
+}
+
 var voteEntry = map[bc.Hash]bc.Entry{
        bc.Hash{V0: 0}: &bc.VoteOutput{
                Source: &bc.ValueSource{
@@ -216,17 +234,18 @@ func TestApplyBlock(t *testing.T) {
                                                TxHeader: &bc.TxHeader{
                                                        ResultIds: []*bc.Hash{
                                                                &bc.Hash{V0: 0},
+                                                               &bc.Hash{V0: 1},
                                                        },
                                                },
                                                SpentOutputIDs: []bc.Hash{},
-                                               Entries:        defaultEntry,
+                                               Entries:        coinbaseEntry,
                                        },
                                },
                        },
                        inputView: NewUtxoViewpoint(),
                        fetchView: &UtxoViewpoint{
                                Entries: map[bc.Hash]*storage.UtxoEntry{
-                                       bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.CoinbaseUTXOType, 0, false),
+                                       bc.Hash{V0: 1}: storage.NewUtxoEntry(storage.CoinbaseUTXOType, 0, false),
                                },
                        },
                        err: false,
@@ -285,11 +304,7 @@ func TestApplyBlock(t *testing.T) {
                                },
                        },
                        inputView: NewUtxoViewpoint(),
-                       fetchView: &UtxoViewpoint{
-                               Entries: map[bc.Hash]*storage.UtxoEntry{
-                                       bc.Hash{V1: 0}: storage.NewUtxoEntry(storage.CoinbaseUTXOType, 0, false),
-                               },
-                       },
+                       fetchView: NewUtxoViewpoint(),
                        gasOnlyTx: true,
                        err:       false,
                },
@@ -411,17 +426,22 @@ func TestDetachBlock(t *testing.T) {
                                                TxHeader: &bc.TxHeader{
                                                        ResultIds: []*bc.Hash{
                                                                &bc.Hash{V0: 0},
+                                                               &bc.Hash{V0: 1},
                                                        },
                                                },
                                                SpentOutputIDs: []bc.Hash{},
-                                               Entries:        defaultEntry,
+                                               Entries:        coinbaseEntry,
                                        },
                                },
                        },
-                       inputView: NewUtxoViewpoint(),
+                       inputView: &UtxoViewpoint{
+                               Entries: map[bc.Hash]*storage.UtxoEntry{
+                                       bc.Hash{V0: 1}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, false),
+                               },
+                       },
                        fetchView: &UtxoViewpoint{
                                Entries: map[bc.Hash]*storage.UtxoEntry{
-                                       bc.Hash{V0: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, true),
+                                       bc.Hash{V0: 1}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, true),
                                },
                        },
                        err: false,
@@ -531,11 +551,7 @@ func TestDetachBlock(t *testing.T) {
                                },
                        },
                        inputView: NewUtxoViewpoint(),
-                       fetchView: &UtxoViewpoint{
-                               Entries: map[bc.Hash]*storage.UtxoEntry{
-                                       bc.Hash{V1: 0}: storage.NewUtxoEntry(storage.NormalUTXOType, 0, true),
-                               },
-                       },
+                       fetchView: NewUtxoViewpoint(),
                        gasOnlyTx: true,
                        err:       false,
                },