OSDN Git Service

fix log (#388)
[bytom/vapor.git] / test / chain_test_util.go
index fc9b9ec..2f5fdb0 100644 (file)
@@ -62,13 +62,26 @@ func (ctx *chainTestContext) validateStatus(block *types.Block) error {
 
 func (ctx *chainTestContext) validateExecution(block *types.Block) error {
        for _, tx := range block.Transactions {
+               for _, mainchainOutputID := range tx.MainchainOutputIDs {
+                       utxoEntry, _ := ctx.Store.GetUtxo(&mainchainOutputID)
+                       if utxoEntry == nil {
+                               continue
+                       }
+                       if utxoEntry.Type != storage.CrosschainUTXOType {
+                               return fmt.Errorf("found non-mainchain utxo entry")
+                       }
+                       if !utxoEntry.Spent {
+                               return fmt.Errorf("utxo entry status should be spent")
+                       }
+               }
+
                for _, spentOutputID := range tx.SpentOutputIDs {
                        utxoEntry, _ := ctx.Store.GetUtxo(&spentOutputID)
                        if utxoEntry == nil {
                                continue
                        }
-                       if !utxoEntry.IsCoinBase {
-                               return fmt.Errorf("found non-coinbase spent utxo entry")
+                       if utxoEntry.Type == storage.NormalUTXOType {
+                               return fmt.Errorf("found normal utxo entry")
                        }
                        if !utxoEntry.Spent {
                                return fmt.Errorf("utxo entry status should be spent")
@@ -97,12 +110,12 @@ func (ctx *chainTestContext) getUtxoEntries() map[string]*storage.UtxoEntry {
        defer iter.Release()
 
        for iter.Next() {
-               utxoEntry := storage.UtxoEntry{}
-               if err := proto.Unmarshal(iter.Value(), &utxoEntry); err != nil {
+               utxoEntry := new(storage.UtxoEntry)
+               if err := proto.Unmarshal(iter.Value(), utxoEntry); err != nil {
                        return nil
                }
                key := string(iter.Key())
-               utxoEntries[key] = &utxoEntry
+               utxoEntries[key] = utxoEntry
        }
        return utxoEntries
 }
@@ -208,7 +221,7 @@ func (t *ctTransaction) createTransaction(ctx *chainTestContext, txs []*types.Tx
        }
 
        for _, amount := range t.Outputs {
-               output := types.NewTxOutput(*consensus.BTMAssetID, amount, []byte{byte(vm.OP_TRUE)})
+               output := types.NewIntraChainOutput(*consensus.BTMAssetID, amount, []byte{byte(vm.OP_TRUE)})
                if err := builder.AddOutput(output); err != nil {
                        return nil, err
                }