This repository was archived by the owner on Nov 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 160
refactor: Split config package so it doesn't import core, core/vm #734
Merged
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8f1ed91
refactor: Split config package so it doesn't end up importing core, c…
baffddb
Merge branch 'master' into split-config-type
7bc9381
adding UT to forbid certain imports
5efb9ff
Merge branch 'split-config-type' of github.com:ava-labs/coreth into s…
9654dac
add comment
25646ee
Revert "refactor: Split config package so it doesn't end up importing…
a33db3b
apply review suggestions
f156efa
Merge branch 'master' of github.com:ava-labs/coreth into split-config…
2d100c5
Merge branch 'master' into split-config-type
b9b887f
Update plugin/evm/imports_test.go
be34fc4
Update plugin/evm/imports_test.go
bf08ba4
add comment
afb9538
Update plugin/evm/config.go
304e096
Update plugin/evm/config/config.go
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // (c) 2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| package evm | ||
|
|
||
| import ( | ||
| "github.com/ava-labs/coreth/core/txpool/legacypool" | ||
| "github.com/ava-labs/coreth/plugin/evm/config" | ||
| ) | ||
|
|
||
| // defaultTxPoolConfig uses legacypool's DefaultConfig to make a TxPoolConfig | ||
| // that can be passed to config.Config.SetDefaults. | ||
| var defaultTxPoolConfig = config.TxPoolConfig{ | ||
darioush marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| PriceLimit: legacypool.DefaultConfig.PriceLimit, | ||
| PriceBump: legacypool.DefaultConfig.PriceBump, | ||
| AccountSlots: legacypool.DefaultConfig.AccountSlots, | ||
| GlobalSlots: legacypool.DefaultConfig.GlobalSlots, | ||
| AccountQueue: legacypool.DefaultConfig.AccountQueue, | ||
| GlobalQueue: legacypool.DefaultConfig.GlobalQueue, | ||
| Lifetime: legacypool.DefaultConfig.Lifetime, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // (c) 2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
qdm12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| package evm | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "golang.org/x/tools/go/packages" | ||
| ) | ||
|
|
||
| // getDependencies takes a fully qualified package name and returns a map of all | ||
| // its recursive package imports (including itself) in the same format. | ||
| func getDependencies(packageName string) (map[string]struct{}, error) { | ||
| // Configure the load mode to include dependencies | ||
| cfg := &packages.Config{Mode: packages.NeedDeps | packages.NeedImports | packages.NeedName | packages.NeedModule} | ||
| pkgs, err := packages.Load(cfg, packageName) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to load package %s: %v", packageName, err) | ||
darioush marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| if len(pkgs) == 0 || pkgs[0].Errors != nil { | ||
| return nil, fmt.Errorf("failed to load package %s", packageName) | ||
| } | ||
|
|
||
| deps := make(map[string]struct{}) | ||
| var collectDeps func(pkg *packages.Package) | ||
| collectDeps = func(pkg *packages.Package) { | ||
| if _, ok := deps[pkg.PkgPath]; ok { | ||
| return // Avoid re-processing the same dependency | ||
| } | ||
| deps[pkg.PkgPath] = struct{}{} | ||
| for _, dep := range pkg.Imports { | ||
| collectDeps(dep) | ||
| } | ||
| } | ||
|
|
||
| // Start collecting dependencies | ||
| collectDeps(pkgs[0]) | ||
| return deps, nil | ||
| } | ||
|
|
||
| func TestMustNotImport(t *testing.T) { | ||
| repo := "github.com/ava-labs/coreth" | ||
| withRepo := func(pkg string) string { | ||
darioush marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return fmt.Sprintf("%s/%s", repo, pkg) | ||
| } | ||
| mustNotImport := map[string][]string{ | ||
| "plugin/evm/atomic": {"core", "core/vm"}, | ||
| "plugin/evm/client": {"core", "core/vm"}, | ||
| "plugin/evm/config": {"core", "core/vm"}, | ||
| } | ||
|
|
||
| for packageName, forbiddenImports := range mustNotImport { | ||
| imports, err := getDependencies(withRepo(packageName)) | ||
| require.NoError(t, err) | ||
|
|
||
| for _, forbiddenImport := range forbiddenImports { | ||
| fullForbiddenImport := withRepo(forbiddenImport) | ||
| _, found := imports[fullForbiddenImport] | ||
| require.False(t, found, "package %s must not import %s, check output of go list -f '{{ .Deps }}' \"%s\" ", packageName, fullForbiddenImport, withRepo(packageName)) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.