tests: add dummy ChainContext impl to read config

This commit is contained in:
lightclient 2025-01-30 20:31:05 -07:00
parent b16db48789
commit d47bcafb30
No known key found for this signature in database
GPG key ID: 657913021EF45A6A
2 changed files with 12 additions and 2 deletions

View file

@ -303,7 +303,7 @@ func runBenchmark(b *testing.B, t *StateTest) {
// Prepare the EVM. // Prepare the EVM.
txContext := core.NewEVMTxContext(msg) txContext := core.NewEVMTxContext(msg)
context := core.NewEVMBlockContext(block.Header(), nil, &t.json.Env.Coinbase) context := core.NewEVMBlockContext(block.Header(), &dummyChain{config: config}, &t.json.Env.Coinbase)
context.GetHash = vmTestBlockHash context.GetHash = vmTestBlockHash
context.BaseFee = baseFee context.BaseFee = baseFee
evm := vm.NewEVM(context, state.StateDB, config, vmconfig) evm := vm.NewEVM(context, state.StateDB, config, vmconfig)

View file

@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/misc/eip4844" "github.com/ethereum/go-ethereum/consensus/misc/eip4844"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
@ -299,7 +300,7 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh
} }
// Prepare the EVM. // Prepare the EVM.
context := core.NewEVMBlockContext(block.Header(), nil, &t.json.Env.Coinbase) context := core.NewEVMBlockContext(block.Header(), &dummyChain{config: config}, &t.json.Env.Coinbase)
context.GetHash = vmTestBlockHash context.GetHash = vmTestBlockHash
context.BaseFee = baseFee context.BaseFee = baseFee
context.Random = nil context.Random = nil
@ -548,3 +549,12 @@ func (st *StateTestState) Close() {
st.Snapshots = nil st.Snapshots = nil
} }
} }
// dummyChain implements the core.ChainContext interface.
type dummyChain struct {
config *params.ChainConfig
}
func (d *dummyChain) Engine() consensus.Engine { return nil }
func (d *dummyChain) GetHeader(h common.Hash, n uint64) *types.Header { return nil }
func (d *dummyChain) Config() *params.ChainConfig { return d.config }