From 1321a4252544c6451ed1867f6d2714f0fd6b30a9 Mon Sep 17 00:00:00 2001 From: Martin HS Date: Wed, 18 Dec 2024 00:18:36 +0100 Subject: [PATCH] cmd/evm: make evm statetest accept non-json files (#30927) This fixes a regression introduced recently. Without this fix, it's not possible to use statetests without `.json` suffix. This is problematic for goevmlab `minimizer`, which appends the suffix `.min` during processing. --- cmd/evm/blockrunner.go | 2 +- cmd/evm/main.go | 11 ++++++++--- cmd/evm/staterunner.go | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/evm/blockrunner.go b/cmd/evm/blockrunner.go index 2cb0531e281e..9a04807b3366 100644 --- a/cmd/evm/blockrunner.go +++ b/cmd/evm/blockrunner.go @@ -50,7 +50,7 @@ func blockTestCmd(ctx *cli.Context) error { return errors.New("path argument required") } var ( - collected = collectJSONFiles(path) + collected = collectFiles(path) results []testResult ) for _, fname := range collected { diff --git a/cmd/evm/main.go b/cmd/evm/main.go index 0e6f6fa5be0a..2079425416d7 100644 --- a/cmd/evm/main.go +++ b/cmd/evm/main.go @@ -262,10 +262,15 @@ func tracerFromFlags(ctx *cli.Context) *tracing.Hooks { } } -// collectJSONFiles walks the given path and accumulates all files with json -// extension. -func collectJSONFiles(path string) []string { +// collectFiles walks the given path. If the path is a directory, it will +// return a list of all accumulates all files with json extension. +// Otherwise (if path points to a file), it will return the path. +func collectFiles(path string) []string { var out []string + if info, err := os.Stat(path); err == nil && !info.IsDir() { + // User explicitly pointed out a file, ignore extension. + return []string{path} + } err := filepath.Walk(path, func(path string, info fs.FileInfo, err error) error { if err != nil { return err diff --git a/cmd/evm/staterunner.go b/cmd/evm/staterunner.go index 323b7d60abc8..4c2dfeabc630 100644 --- a/cmd/evm/staterunner.go +++ b/cmd/evm/staterunner.go @@ -63,7 +63,7 @@ func stateTestCmd(ctx *cli.Context) error { // If path is provided, run the tests at that path. if len(path) != 0 { var ( - collected = collectJSONFiles(path) + collected = collectFiles(path) results []testResult ) for _, fname := range collected {