Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
21b5aea
test: add import compliance tests
JonathanOppenheimer Nov 21, 2025
7e33965
test: tweak violation wording
JonathanOppenheimer Nov 21, 2025
404acd5
test: add violation to show failure example
JonathanOppenheimer Nov 21, 2025
dec282e
test: remove violation
JonathanOppenheimer Nov 21, 2025
234a039
test: only enforce on vms/evm directory
JonathanOppenheimer Nov 21, 2025
9a39d6b
test: clarify boundaries
JonathanOppenheimer Nov 22, 2025
5017e1e
test: rename test
JonathanOppenheimer Nov 22, 2025
e490151
test: clarify comments
JonathanOppenheimer Nov 22, 2025
f411817
chore: lint
JonathanOppenheimer Nov 22, 2025
84fbb35
test: add license violation test
JonathanOppenheimer Nov 22, 2025
498915c
test: inline once used type
JonathanOppenheimer Nov 22, 2025
f4fbfac
tests: rename libevm test
JonathanOppenheimer Nov 22, 2025
69e8354
chore: fix typo
JonathanOppenheimer Nov 22, 2025
be5228a
test: remove licensing test (excessive)
JonathanOppenheimer Nov 24, 2025
d607b78
Merge branch 'master' into JonathanOppenheimer/import-testing
JonathanOppenheimer Nov 24, 2025
99ed2ce
test: check both evm code locations
JonathanOppenheimer Nov 24, 2025
e9cc48b
test: move import tests to evm directory
JonathanOppenheimer Nov 24, 2025
cbcd663
test: reconsider boundary tests
JonathanOppenheimer Nov 24, 2025
f482da4
Update vms/evm/imports_test.go
JonathanOppenheimer Dec 1, 2025
c4b31fc
test: use Arran's rewritten test
JonathanOppenheimer Dec 1, 2025
7d513d4
fix: add .go
JonathanOppenheimer Dec 1, 2025
40e5904
Merge branch 'master' into JonathanOppenheimer/import-testing
JonathanOppenheimer Dec 1, 2025
b6541d1
chore: lint
JonathanOppenheimer Dec 1, 2025
70f33bc
chore: move comment
JonathanOppenheimer Dec 1, 2025
57f083c
docs: document functions
JonathanOppenheimer Dec 1, 2025
63a88d9
Update vms/evm/imports_test.go
JonathanOppenheimer Dec 2, 2025
249e7cd
Update vms/evm/imports_test.go
JonathanOppenheimer Dec 2, 2025
fee0356
Update vms/evm/imports_test.go
JonathanOppenheimer Dec 2, 2025
d24963b
test: use absolute file paths
JonathanOppenheimer Dec 2, 2025
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
4 changes: 3 additions & 1 deletion graft/scripts/libevm-allowed-packages.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Allowed libevm packages that can be imported in the graft directory.
# Allowed libevm packages can be imported by EVM code
# Lines with a "!" prefix are forbidden.
# Lines without a "!" prefix are allowed (exceptions to the forbidden patterns).

Expand Down Expand Up @@ -29,6 +29,7 @@
"github.com/ava-labs/libevm/eth/tracers/logger"
"github.com/ava-labs/libevm/eth/tracers/native"
"github.com/ava-labs/libevm/ethdb"
"github.com/ava-labs/libevm/ethdb/dbtest"
"github.com/ava-labs/libevm/ethdb/leveldb"
"github.com/ava-labs/libevm/ethdb/memorydb"
"github.com/ava-labs/libevm/ethdb/pebble"
Expand All @@ -39,6 +40,7 @@
"github.com/ava-labs/libevm/libevm/stateconf"
"github.com/ava-labs/libevm/log"
"github.com/ava-labs/libevm/metrics"
"github.com/ava-labs/libevm/params"
"github.com/ava-labs/libevm/rlp"
"github.com/ava-labs/libevm/trie"
"github.com/ava-labs/libevm/trie/testutil"
Expand Down
29 changes: 23 additions & 6 deletions tests/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestEnforceGraftImportBoundaries(t *testing.T) {
require.Fail(t, formatImportViolations(foundImports, header))
}

// TestEnforceLibevmImportsAllowlist ensures that all libevm imports in the graft directory
// TestEnforceLibevmImportsAllowlist ensures that all libevm imports by EVM code
// are explicitly allowed via the libevm-allowed-packages.txt file.
func TestEnforceLibevmImportsAllowlist(t *testing.T) {
_, allowedPackages, err := loadPatternFile("../graft/scripts/libevm-allowed-packages.txt")
Expand All @@ -84,9 +84,9 @@ func TestEnforceLibevmImportsAllowlist(t *testing.T) {
allowedSet.Add(pkg)
}

// Find all libevm imports in source files, excluding underscore and "eth*" named imports
// Find all libevm imports in graft and vms/evm, excluding underscore and "eth*" named imports
libevmRegex := regexp.MustCompile(`^github\.com/ava-labs/libevm/`)
foundImports, err := findImportsMatchingPattern("../graft", libevmRegex, func(path string, _ string, imp *ast.ImportSpec) bool {
filterFunc := func(path string, _ string, imp *ast.ImportSpec) bool {
// Skip generated files and test-specific files
filename := filepath.Base(path)
if strings.HasPrefix(filename, "gen_") ||
Expand All @@ -97,8 +97,25 @@ func TestEnforceLibevmImportsAllowlist(t *testing.T) {

// Skip underscore and "eth*" named imports
return imp.Name != nil && (imp.Name.Name == "_" || strings.HasPrefix(imp.Name.Name, "eth"))
})
require.NoError(t, err, "Failed to find libevm imports")
}

// TODO(jonathanoppenheimer): remove when graft is removed
foundImports, err := findImportsMatchingPattern("../graft", libevmRegex, filterFunc)
require.NoError(t, err, "Failed to find libevm imports in graft")

evmImports, err := findImportsMatchingPattern("../vms/evm", libevmRegex, filterFunc)
require.NoError(t, err, "Failed to find libevm imports in vms/evm")

// merge libevm imports from graft and vms/evm
for importPath, files := range evmImports {
if existingFiles, exists := foundImports[importPath]; exists {
for file := range files {
existingFiles.Add(file)
}
} else {
foundImports[importPath] = files
}
}

violations := make(map[string]set.Set[string])
for importPath, files := range foundImports {
Expand All @@ -111,7 +128,7 @@ func TestEnforceLibevmImportsAllowlist(t *testing.T) {
return // no violations found
}

header := "Files inside the graft directory must not import forbidden libevm packages!\n" +
header := "EVM files must not import forbidden libevm packages!\n" +
"If a package is safe to import, add it to graft/scripts/libevm-allowed-packages.txt.\n\n"
require.Fail(t, formatImportViolations(violations, header))
}
Expand Down
Loading