From e5b480b6387231e0aa1866a9a1c118b88eae619c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Mon, 11 Jan 2016 16:53:06 +0200 Subject: core: fix invalid state reuse in chain maker based tests --- core/chain_makers.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'core') 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 -- cgit v1.2.3