Skip to content

Commit faed47b

Browse files
authored
Merge pull request #15990 from markya0616/sim_backend_block_hash
accounts/abi, core: add AddTxWithChain in BlockGen for simulation
2 parents fe6cf00 + c1d70ea commit faed47b

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

accounts/abi/bind/backends/simulated.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,9 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
307307

308308
blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {
309309
for _, tx := range b.pendingBlock.Transactions() {
310-
block.AddTx(tx)
310+
block.AddTxWithChain(b.blockchain, tx)
311311
}
312-
block.AddTx(tx)
312+
block.AddTxWithChain(b.blockchain, tx)
313313
})
314314
statedb, _ := b.blockchain.State()
315315

core/chain_makers.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,23 @@ func (b *BlockGen) SetExtra(data []byte) {
8282
// added. Notably, contract code relying on the BLOCKHASH instruction
8383
// will panic during execution.
8484
func (b *BlockGen) AddTx(tx *types.Transaction) {
85+
b.AddTxWithChain(nil, tx)
86+
}
87+
88+
// AddTxWithChain adds a transaction to the generated block. If no coinbase has
89+
// been set, the block's coinbase is set to the zero address.
90+
//
91+
// AddTxWithChain panics if the transaction cannot be executed. In addition to
92+
// the protocol-imposed limitations (gas limit, etc.), there are some
93+
// further limitations on the content of transactions that can be
94+
// added. If contract code relies on the BLOCKHASH instruction,
95+
// the block in chain will be returned.
96+
func (b *BlockGen) AddTxWithChain(bc *BlockChain, tx *types.Transaction) {
8597
if b.gasPool == nil {
8698
b.SetCoinbase(common.Address{})
8799
}
88100
b.statedb.Prepare(tx.Hash(), common.Hash{}, len(b.txs))
89-
receipt, _, err := ApplyTransaction(b.config, nil, &b.header.Coinbase, b.gasPool, b.statedb, b.header, tx, &b.header.GasUsed, vm.Config{})
101+
receipt, _, err := ApplyTransaction(b.config, bc, &b.header.Coinbase, b.gasPool, b.statedb, b.header, tx, &b.header.GasUsed, vm.Config{})
90102
if err != nil {
91103
panic(err)
92104
}

0 commit comments

Comments
 (0)