Skip to content

Commit 24d7e57

Browse files
authored
sync: coreth PR #1305: feat!: explicit libevm calls to Register{Extras,Hooks}() (#1773)
1 parent d5cf1b6 commit 24d7e57

File tree

28 files changed

+565
-335
lines changed

28 files changed

+565
-335
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
- name: Setup Contracts
9898
run: ./scripts/run_task.sh setup-contracts
9999
- name: Run Warp E2E Tests
100-
uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@36baa0509d61679085d35bffa590d63732b0a7bd
100+
uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@84e9aebcfbc04602865f4c0a3e8b46a27409a3f5
101101
with:
102102
run: ./scripts/run_task.sh test-e2e-warp-ci
103103
artifact_prefix: warp
@@ -122,7 +122,7 @@ jobs:
122122
with:
123123
go-version-file: "go.mod"
124124
- name: Run E2E Load Tests
125-
uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@36baa0509d61679085d35bffa590d63732b0a7bd
125+
uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@84e9aebcfbc04602865f4c0a3e8b46a27409a3f5
126126
with:
127127
run: ./scripts/run_task.sh test-e2e-load-ci
128128
artifact_prefix: load

accounts/abi/bind/bind_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,16 @@ import (
3737
"testing"
3838

3939
"github.com/ava-labs/libevm/common"
40+
"github.com/ava-labs/subnet-evm/params"
41+
"github.com/ava-labs/subnet-evm/plugin/evm/customtypes"
4042
)
4143

44+
func TestMain(m *testing.M) {
45+
customtypes.Register()
46+
params.RegisterExtras()
47+
os.Exit(m.Run())
48+
}
49+
4250
var bindTests = []struct {
4351
name string
4452
contract string
@@ -2156,10 +2164,21 @@ func golangBindings(t *testing.T, overload bool) {
21562164
21572165
import (
21582166
"testing"
2167+
2168+
"github.com/ava-labs/subnet-evm/params"
2169+
"github.com/ava-labs/subnet-evm/plugin/evm/customtypes"
2170+
libevmparams "github.com/ava-labs/libevm/params"
2171+
libevmtypes "github.com/ava-labs/libevm/core/types"
2172+
21592173
%s
21602174
)
21612175
21622176
func Test%s(t *testing.T) {
2177+
customtypes.Register()
2178+
t.Cleanup(libevmtypes.TestOnlyClearRegisteredExtras)
2179+
params.RegisterExtras()
2180+
t.Cleanup(libevmparams.TestOnlyClearRegisteredExtras)
2181+
21632182
%s
21642183
}
21652184
`, tt.imports, tt.name, tt.tester)

core/evm.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ import (
4646
"github.com/holiman/uint256"
4747
)
4848

49-
func init() {
49+
// RegisterExtras registers hooks with libevm to achieve Avalanche behaviour of
50+
// the EVM. It MUST NOT be called more than once and therefore is only allowed
51+
// to be used in tests and `package main`, to avoid polluting other packages
52+
// that transitively depend on this one but don't need registration.
53+
func RegisterExtras() {
54+
// Although the registration function refers to just Hooks (not Extras) this
55+
// will be changed in the future to standardise across libevm, hence the
56+
// name of the function we're in.
5057
vm.RegisterHooks(hooks{})
5158
}
5259

core/main_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ import (
77
"testing"
88

99
"go.uber.org/goleak"
10+
11+
"github.com/ava-labs/subnet-evm/params"
12+
"github.com/ava-labs/subnet-evm/plugin/evm/customtypes"
1013
)
1114

1215
// TestMain uses goleak to verify tests in this package do not leak unexpected
1316
// goroutines.
1417
func TestMain(m *testing.M) {
18+
RegisterExtras()
19+
20+
customtypes.Register()
21+
params.RegisterExtras()
22+
1523
opts := []goleak.Option{
1624
// No good way to shut down these goroutines:
1725
goleak.IgnoreTopFunction("github.com/ava-labs/subnet-evm/core/state/snapshot.(*diskLayer).generate"),

core/txpool/blobpool/blobpool_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ var (
7575
var testChainConfig *params.ChainConfig
7676

7777
func init() {
78+
params.RegisterExtras()
79+
7880
testChainConfig = new(params.ChainConfig)
7981
*testChainConfig = params.Copy(params.TestChainConfig)
8082
params.GetExtra(testChainConfig).FeeConfig.MinBaseFee = new(big.Int).SetUint64(1)

core/txpool/legacypool/legacypool_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ import (
5454
"github.com/holiman/uint256"
5555
)
5656

57+
func TestMain(m *testing.M) {
58+
params.RegisterExtras()
59+
os.Exit(m.Run())
60+
}
61+
5762
var (
5863
// testTxPoolConfig is a transaction pool configuration without stateful disk
5964
// sideeffects used during testing.

core/vm/runtime/runtime_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ import (
5252
"github.com/holiman/uint256"
5353
)
5454

55+
func TestMain(m *testing.M) {
56+
params.RegisterExtras()
57+
os.Exit(m.Run())
58+
}
59+
5560
func TestDefaults(t *testing.T) {
5661
cfg := new(Config)
5762
setDefaults(cfg)

eth/filters/filter_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"context"
3232
"encoding/json"
3333
"math/big"
34+
"os"
3435
"strings"
3536
"testing"
3637
"time"
@@ -46,10 +47,17 @@ import (
4647
"github.com/ava-labs/subnet-evm/core"
4748
"github.com/ava-labs/subnet-evm/params"
4849
"github.com/ava-labs/subnet-evm/plugin/evm/customrawdb"
50+
"github.com/ava-labs/subnet-evm/plugin/evm/customtypes"
4951
"github.com/ava-labs/subnet-evm/rpc"
5052
"github.com/stretchr/testify/require"
5153
)
5254

55+
func TestMain(m *testing.M) {
56+
customtypes.Register()
57+
params.RegisterExtras()
58+
os.Exit(m.Run())
59+
}
60+
5361
func makeReceipt(addr common.Address) *types.Receipt {
5462
receipt := types.NewReceipt(nil, false, 0)
5563
receipt.Logs = []*types.Log{

eth/gasprice/gasprice_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ package gasprice
3030
import (
3131
"context"
3232
"math/big"
33+
"os"
3334
"testing"
3435
"time"
3536

@@ -46,13 +47,21 @@ import (
4647
"github.com/ava-labs/subnet-evm/params"
4748
"github.com/ava-labs/subnet-evm/params/extras"
4849
"github.com/ava-labs/subnet-evm/plugin/evm/customheader"
50+
"github.com/ava-labs/subnet-evm/plugin/evm/customtypes"
4951
"github.com/ava-labs/subnet-evm/plugin/evm/upgrade/legacy"
5052
"github.com/ava-labs/subnet-evm/precompile/contracts/feemanager"
5153
"github.com/ava-labs/subnet-evm/rpc"
5254
"github.com/ava-labs/subnet-evm/utils"
5355
"github.com/stretchr/testify/require"
5456
)
5557

58+
func TestMain(m *testing.M) {
59+
core.RegisterExtras()
60+
customtypes.Register()
61+
params.RegisterExtras()
62+
os.Exit(m.Run())
63+
}
64+
5665
var (
5766
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
5867
addr = crypto.PubkeyToAddress(key.PublicKey)

eth/tracers/api_extra_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"encoding/json"
99
"fmt"
1010
"math/big"
11+
"os"
1112
"reflect"
1213
"sync/atomic"
1314
"testing"
@@ -25,12 +26,19 @@ import (
2526
"github.com/ava-labs/subnet-evm/params"
2627
"github.com/ava-labs/subnet-evm/params/extras"
2728
"github.com/ava-labs/subnet-evm/plugin/evm/customrawdb"
29+
"github.com/ava-labs/subnet-evm/plugin/evm/customtypes"
2830
"github.com/ava-labs/subnet-evm/precompile/contracts/txallowlist"
2931
"github.com/ava-labs/subnet-evm/rpc"
3032

3133
ethparams "github.com/ava-labs/libevm/params"
3234
)
3335

36+
func TestMain(m *testing.M) {
37+
customtypes.Register()
38+
params.RegisterExtras()
39+
os.Exit(m.Run())
40+
}
41+
3442
var schemes = []string{rawdb.HashScheme, customrawdb.FirewoodScheme}
3543

3644
func TestTraceBlockPrecompileActivation(t *testing.T) {

0 commit comments

Comments
 (0)