Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions tests/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,25 @@ import (
"github.com/ava-labs/avalanchego/utils/packages"
)

// TestMustNotImport tests that we do not import certain packages (like coreth's customtypes package) that would configure libevm globals.
// Libevm panics if a package tries to register a custom type or extra after the globals have been configured (re-registration).
// E2E test packages are used both from Subnet-EVM and Coreth.
// Registering the libevm globals here in these packages does not necessarily break avalanchego e2e testing, but Subnet-EVM (or Coreth) E2E testing.
// So any illegal use here will only be a problem once Subnet-EVM or Coreth bumps the avalanchego version, breaking the release cycles of
// AvalancheGo and other repositories.
// Transitory imports are also checked with packages.GetDependencies.
func TestMustNotImport(t *testing.T) {
require := require.New(t)

// These packages configure libevm globally by registering custom types and extras.
illegalPaths := []string{
"github.com/ava-labs/coreth/params",
"github.com/ava-labs/coreth/plugin/evm/customtypes",
}
mustNotImport := map[string][]string{
// Importing these packages configures libevm globally. This must not be
// done to support both coreth and subnet-evm.
"tests/...": {
"github.com/ava-labs/coreth/params",
"github.com/ava-labs/coreth/plugin/evm/customtypes",
},
"tests/": illegalPaths,
"tests/antithesis/": illegalPaths,
"tests/fixture/...": illegalPaths,
}
for packageName, forbiddenImports := range mustNotImport {
packagePath := path.Join("github.com/ava-labs/avalanchego", packageName)
Expand Down