Skip to content

Commit c1d70ea

Browse files
committed
accounts/abi, core: add AddTxWithChain in BlockGen for simulation
1 parent 05ade19 commit c1d70ea

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
@@ -293,9 +293,9 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
293293

294294
blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {
295295
for _, tx := range b.pendingBlock.Transactions() {
296-
block.AddTx(tx)
296+
block.AddTxWithChain(b.blockchain, tx)
297297
}
298-
block.AddTx(tx)
298+
block.AddTxWithChain(b.blockchain, tx)
299299
})
300300
b.pendingBlock = blocks[0]
301301
b.pendingState, _ = state.New(b.pendingBlock.Root(), state.NewDatabase(b.database))

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)