Skip to content

Commit 03e24d4

Browse files
committed
test: vm.Hooks.OverrideNewEVMArgs
1 parent e5ab795 commit 03e24d4

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

core/vm/evm.libevm_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package vm
2+
3+
import (
4+
"math/big"
5+
"testing"
6+
7+
"github.com/ethereum/go-ethereum/params"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
type chainIDOverrider struct {
12+
chainID int64
13+
}
14+
15+
func (o chainIDOverrider) OverrideNewEVMArgs(BlockContext, TxContext, StateDB, *params.ChainConfig, Config) (BlockContext, TxContext, StateDB, *params.ChainConfig, Config) {
16+
return BlockContext{}, TxContext{}, nil, &params.ChainConfig{ChainID: big.NewInt(o.chainID)}, Config{}
17+
}
18+
19+
func TestOverrideNewEVMArgs(t *testing.T) {
20+
// The OverrideNewEVMArgs hook accepts and returns all arguments to
21+
// NewEVM(), in order. Here we lock in our assumption of that order. If this
22+
// breaks then the Hooks.OverrideNewEVMArgs() signature MUST be changed to
23+
// match.
24+
var _ func(BlockContext, TxContext, StateDB, *params.ChainConfig, Config) *EVM = NewEVM
25+
26+
const chainID = 13579
27+
libevmHooks = nil
28+
RegisterHooks(chainIDOverrider{chainID: chainID})
29+
30+
got := NewEVM(BlockContext{}, TxContext{}, nil, nil, Config{}).ChainConfig().ChainID
31+
require.Equal(t, big.NewInt(chainID), got)
32+
}

0 commit comments

Comments
 (0)