X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=test%2Fchain_test_util.go;h=2f5fdb028b335a1df5431ceb39c9c6a3c045b8f1;hp=c358ddea2ad8f2872834cd7411df24f09c72c9ae;hb=refs%2Fheads%2Ftest_protocol;hpb=f6ec2b987c394f065e527bcdf5942d1f9f0dad66 diff --git a/test/chain_test_util.go b/test/chain_test_util.go index c358ddea..2f5fdb02 100644 --- a/test/chain_test_util.go +++ b/test/chain_test_util.go @@ -5,12 +5,11 @@ import ( "os" "time" - dbm "github.com/tendermint/tmlibs/db" - "github.com/golang/protobuf/proto" "github.com/vapor/blockchain/txbuilder" "github.com/vapor/consensus" - "github.com/vapor/database/leveldb" + "github.com/vapor/database" + dbm "github.com/vapor/database/leveldb" "github.com/vapor/database/storage" "github.com/vapor/protocol" "github.com/vapor/protocol/bc" @@ -23,7 +22,7 @@ const utxoPrefix = "UT:" type chainTestContext struct { Chain *protocol.Chain DB dbm.DB - Store *leveldb.Store + Store *database.Store } func (ctx *chainTestContext) validateStatus(block *types.Block) error { @@ -63,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") @@ -98,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 } @@ -209,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 } @@ -250,7 +262,7 @@ func (cfg *chainTestConfig) Run() error { if err != nil { return err } - err = SolveAndUpdate(ctx.Chain, block) + _, err = ctx.Chain.ProcessBlock(block) if err != nil && blk.Invalid { continue }