cmd/evm: add stdin support to blocktest command

Enable blocktest to read filenames from stdin when no path argument
is provided, matching the existing statetest behavior. This allows
efficient batch processing of blockchain tests.

Usage:
- Single file: evm blocktest <path>
- Batch mode: find tests/ -name "*.json" | evm blocktest

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Bhargava Shastry 2025-10-02 14:06:49 +02:00
parent fc8c8c1314
commit 2dfae90ccb

View file

@ -17,8 +17,8 @@
package main package main
import ( import (
"bufio"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"maps" "maps"
"os" "os"
@ -34,7 +34,7 @@ import (
var blockTestCommand = &cli.Command{ var blockTestCommand = &cli.Command{
Action: blockTestCmd, Action: blockTestCmd,
Name: "blocktest", Name: "blocktest",
Usage: "Executes the given blockchain tests", Usage: "Executes the given blockchain tests. Filenames can be fed via standard input (batch mode) or as an argument (one-off execution).",
ArgsUsage: "<path>", ArgsUsage: "<path>",
Flags: slices.Concat([]cli.Flag{ Flags: slices.Concat([]cli.Flag{
DumpFlag, DumpFlag,
@ -46,9 +46,9 @@ var blockTestCommand = &cli.Command{
func blockTestCmd(ctx *cli.Context) error { func blockTestCmd(ctx *cli.Context) error {
path := ctx.Args().First() path := ctx.Args().First()
if len(path) == 0 {
return errors.New("path argument required") // If path is provided, run the tests at that path.
} if len(path) != 0 {
var ( var (
collected = collectFiles(path) collected = collectFiles(path)
results []testResult results []testResult
@ -63,6 +63,21 @@ func blockTestCmd(ctx *cli.Context) error {
report(ctx, results) report(ctx, results)
return nil return nil
} }
// Otherwise, read filenames from stdin and execute back-to-back.
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
fname := scanner.Text()
if len(fname) == 0 {
return nil
}
results, err := runBlockTest(ctx, fname)
if err != nil {
return err
}
report(ctx, results)
}
return nil
}
func runBlockTest(ctx *cli.Context, fname string) ([]testResult, error) { func runBlockTest(ctx *cli.Context, fname string) ([]testResult, error) {
src, err := os.ReadFile(fname) src, err := os.ReadFile(fname)