diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-01-11 22:53:06 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-01-11 22:53:06 +0800 |
commit | e5b480b6387231e0aa1866a9a1c118b88eae619c (patch) | |
tree | d21744b8a13c0853066e6d349e7c673c99399fcc /core | |
parent | 0ab8a175d812462a5233065f3c729cd67d6ccc90 (diff) | |
download | go-tangerine-e5b480b6387231e0aa1866a9a1c118b88eae619c.tar go-tangerine-e5b480b6387231e0aa1866a9a1c118b88eae619c.tar.gz go-tangerine-e5b480b6387231e0aa1866a9a1c118b88eae619c.tar.bz2 go-tangerine-e5b480b6387231e0aa1866a9a1c118b88eae619c.tar.lz go-tangerine-e5b480b6387231e0aa1866a9a1c118b88eae619c.tar.xz go-tangerine-e5b480b6387231e0aa1866a9a1c118b88eae619c.tar.zst go-tangerine-e5b480b6387231e0aa1866a9a1c118b88eae619c.zip |
core: fix invalid state reuse in chain maker based tests
Diffstat (limited to 'core')
-rw-r--r-- | core/chain_makers.go | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/core/chain_makers.go b/core/chain_makers.go index 5a8f380a3..c62618e6c 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -91,15 +91,10 @@ func (b *BlockGen) AddTx(tx *types.Transaction) { b.SetCoinbase(common.Address{}) } b.statedb.StartRecord(tx.Hash(), common.Hash{}, len(b.txs)) - _, gas, err := ApplyMessage(NewEnv(b.statedb, nil, tx, b.header), tx, b.gasPool) + receipt, _, _, err := ApplyTransaction(nil, b.gasPool, b.statedb, b.header, tx, b.header.GasUsed) if err != nil { panic(err) } - root := b.statedb.IntermediateRoot() - b.header.GasUsed.Add(b.header.GasUsed, gas) - receipt := types.NewReceipt(root.Bytes(), b.header.GasUsed) - receipt.Logs = b.statedb.GetLogs(tx.Hash()) - receipt.Bloom = types.CreateBloom(types.Receipts{receipt}) b.txs = append(b.txs, tx) b.receipts = append(b.receipts, receipt) } @@ -169,12 +164,8 @@ func (b *BlockGen) OffsetTime(seconds int64) { // values. Inserting them into BlockChain requires use of FakePow or // a similar non-validating proof of work implementation. func GenerateChain(parent *types.Block, db ethdb.Database, n int, gen func(int, *BlockGen)) ([]*types.Block, []types.Receipts) { - statedb, err := state.New(parent.Root(), db) - if err != nil { - panic(err) - } blocks, receipts := make(types.Blocks, n), make([]types.Receipts, n) - genblock := func(i int, h *types.Header) (*types.Block, types.Receipts) { + genblock := func(i int, h *types.Header, statedb *state.StateDB) (*types.Block, types.Receipts) { b := &BlockGen{parent: parent, i: i, chain: blocks, header: h, statedb: statedb} if gen != nil { gen(i, b) @@ -188,8 +179,12 @@ func GenerateChain(parent *types.Block, db ethdb.Database, n int, gen func(int, return types.NewBlock(h, b.txs, b.uncles, b.receipts), b.receipts } for i := 0; i < n; i++ { + statedb, err := state.New(parent.Root(), db) + if err != nil { + panic(err) + } header := makeHeader(parent, statedb) - block, receipt := genblock(i, header) + block, receipt := genblock(i, header, statedb) blocks[i] = block receipts[i] = receipt parent = block |