aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-01-11 23:40:28 +0800
committerFelix Lange <fjl@twurst.com>2016-01-11 23:40:28 +0800
commit1b8566a7b137d68c5c7c42d6300378d7ebf21c49 (patch)
treed21744b8a13c0853066e6d349e7c673c99399fcc
parent0ab8a175d812462a5233065f3c729cd67d6ccc90 (diff)
parente5b480b6387231e0aa1866a9a1c118b88eae619c (diff)
downloaddexon-1b8566a7b137d68c5c7c42d6300378d7ebf21c49.tar.gz
dexon-1b8566a7b137d68c5c7c42d6300378d7ebf21c49.tar.zst
dexon-1b8566a7b137d68c5c7c42d6300378d7ebf21c49.zip
Merge pull request #2114 from karalabe/chain-maker-state-remake
core: fix invalid state reuse in chain maker based tests
-rw-r--r--core/chain_makers.go19
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