Skip to content

Commit 8500134

Browse files
bshastryclaude
andcommitted
cmd/evm: address PR feedback on blocktest stdin support
This commit addresses all feedback from @rjl493456442: 1. Result printing location: Removed duplicate report() call from inside test loop. Now uses dedicated traceEndMarker on stderr instead of printing full results mid-execution. 2. Fork assignment: Fork now always assigned regardless of tracer or pass/fail status. Root only assigned when test succeeds, following correct semantics. 3. Log suppression: Removed automatic log suppression. Users can control logging via standard --verbosity and --log.file flags. Only one rare INFO log exists in blocktest path. The traceEndMarker provides clear delimiter for trace parsers (e.g., goevmlab) without duplicating test results. Format: {"testEnd":{"name":"...","pass":true,"fork":"...","root":"..."}} This follows precedent from Nethermind PR #9432. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 838ef5c commit 8500134

File tree

1 file changed

+45
-10
lines changed

1 file changed

+45
-10
lines changed

cmd/evm/blockrunner.go

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/ethereum/go-ethereum/common"
2929
"github.com/ethereum/go-ethereum/core"
3030
"github.com/ethereum/go-ethereum/core/rawdb"
31-
"github.com/ethereum/go-ethereum/log"
3231
"github.com/ethereum/go-ethereum/tests"
3332
"github.com/urfave/cli/v2"
3433
)
@@ -81,6 +80,41 @@ func blockTestCmd(ctx *cli.Context) error {
8180
return nil
8281
}
8382

83+
// traceEndMarker represents the final status of a blocktest when tracing is enabled.
84+
// It is written as the last line of trace output in JSONL format to signal completion.
85+
type traceEndMarker struct {
86+
TestEnd traceEndDetails `json:"testEnd"`
87+
}
88+
89+
type traceEndDetails struct {
90+
Name string `json:"name"`
91+
Pass bool `json:"pass"`
92+
Fork string `json:"fork"`
93+
Root string `json:"root,omitempty"`
94+
Error string `json:"error,omitempty"`
95+
}
96+
97+
// writeTraceEndMarker writes a blocktest end marker to stderr in JSONL format.
98+
// This provides a clear delimiter for trace parsers (e.g., goevmlab) to know when
99+
// the trace output for a specific test is complete, enabling proper batched processing.
100+
func writeTraceEndMarker(name string, pass bool, fork string, root *common.Hash, errMsg string) {
101+
details := traceEndDetails{
102+
Name: name,
103+
Pass: pass,
104+
Fork: fork,
105+
}
106+
if root != nil {
107+
details.Root = root.Hex()
108+
}
109+
if !pass && errMsg != "" {
110+
details.Error = errMsg
111+
}
112+
marker := traceEndMarker{TestEnd: details}
113+
if data, err := json.Marshal(marker); err == nil {
114+
fmt.Fprintf(os.Stderr, "%s\n", data)
115+
}
116+
}
117+
84118
func runBlockTest(ctx *cli.Context, fname string) ([]testResult, error) {
85119
src, err := os.ReadFile(fname)
86120
if err != nil {
@@ -96,11 +130,6 @@ func runBlockTest(ctx *cli.Context, fname string) ([]testResult, error) {
96130
}
97131
tracer := tracerFromFlags(ctx)
98132

99-
// Suppress INFO logs when tracing to avoid polluting stderr
100-
if tracer != nil {
101-
log.SetDefault(log.NewLogger(log.DiscardHandler()))
102-
}
103-
104133
// Pull out keys to sort and ensure tests are run in order.
105134
keys := slices.Sorted(maps.Keys(tests))
106135

@@ -128,12 +157,18 @@ func runBlockTest(ctx *cli.Context, fname string) ([]testResult, error) {
128157
result.Pass, result.Error = false, err.Error()
129158
}
130159

131-
// Write result between transactions when tracing is enabled
132-
if tracer != nil {
133-
result.Fork = test.Network()
160+
// Always assign fork (regardless of pass/fail or tracer)
161+
result.Fork = test.Network()
162+
// Assign root if test succeeded
163+
if result.Pass && finalRoot != nil {
134164
result.Root = finalRoot
135-
report(ctx, []testResult{*result})
136165
}
166+
167+
// When tracing, write end marker to delimit trace output for this test
168+
if tracer != nil {
169+
writeTraceEndMarker(result.Name, result.Pass, result.Fork, finalRoot, result.Error)
170+
}
171+
137172
results = append(results, *result)
138173
}
139174
return results, nil

0 commit comments

Comments
 (0)