cmd/evm: make staterunner always output stateroot to stderr (#29290)

This changes makes it so that when `evm statetest` executes, regardless of whether `--json` is specified or not, the stateroot is printed on `stderr` as a `jsonl` line. This enables speedier execution of testcases in goevmlab, in cases where full execution op-by-op is not required.
pull/29298/head
Martin HS 8 months ago committed by GitHub
parent 0ceac8d00e
commit de08f3d625
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      cmd/evm/staterunner.go

@ -67,7 +67,7 @@ func stateTestCmd(ctx *cli.Context) error {
}
// Load the test content from the input file
if len(ctx.Args().First()) != 0 {
return runStateTest(ctx.Args().First(), cfg, ctx.Bool(MachineFlag.Name), ctx.Bool(DumpFlag.Name))
return runStateTest(ctx.Args().First(), cfg, ctx.Bool(MachineFlag.Name))
}
// Read filenames from stdin and execute back-to-back
scanner := bufio.NewScanner(os.Stdin)
@ -76,7 +76,7 @@ func stateTestCmd(ctx *cli.Context) error {
if len(fname) == 0 {
return nil
}
if err := runStateTest(fname, cfg, ctx.Bool(MachineFlag.Name), ctx.Bool(DumpFlag.Name)); err != nil {
if err := runStateTest(fname, cfg, ctx.Bool(MachineFlag.Name)); err != nil {
return err
}
}
@ -84,7 +84,7 @@ func stateTestCmd(ctx *cli.Context) error {
}
// runStateTest loads the state-test given by fname, and executes the test.
func runStateTest(fname string, cfg vm.Config, jsonOut, dump bool) error {
func runStateTest(fname string, cfg vm.Config, dump bool) error {
src, err := os.ReadFile(fname)
if err != nil {
return err
@ -105,9 +105,7 @@ func runStateTest(fname string, cfg vm.Config, jsonOut, dump bool) error {
if tstate.StateDB != nil {
root = tstate.StateDB.IntermediateRoot(false)
result.Root = &root
if jsonOut {
fmt.Fprintf(os.Stderr, "{\"stateRoot\": \"%#x\"}\n", root)
}
fmt.Fprintf(os.Stderr, "{\"stateRoot\": \"%#x\"}\n", root)
if dump { // Dump any state to aid debugging
cpy, _ := state.New(root, tstate.StateDB.Database(), nil)
dump := cpy.RawDump(nil)

Loading…
Cancel
Save