Skip to content

Commit abda6e4

Browse files
shemnonfjl
authored andcommitted
cmd/evm: restore --bench flag to evm statetest (ethereum#31055)
Refactoring of the `evm` command moved where some commands were valid. One command, `--bench`, used to work in `evm statetest`. The pluming is still in place. This PR puts the `--bench` flag in the place the trace flags were moved, and adds tests to validate the bench flag operates in `run` and `statetest` --------- Co-authored-by: Felix Lange <[email protected]>
1 parent f7742bc commit abda6e4

File tree

6 files changed

+76
-0
lines changed

6 files changed

+76
-0
lines changed

cmd/evm/staterunner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ var stateTestCommand = &cli.Command{
5151
Usage: "Executes the given state tests. Filenames can be fed via standard input (batch mode) or as an argument (one-off execution).",
5252
ArgsUsage: "<file>",
5353
Flags: slices.Concat([]cli.Flag{
54+
BenchFlag,
5455
DumpFlag,
5556
HumanReadableFlag,
5657
RunFlag,

cmd/evm/t8n_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"os"
2525
"path/filepath"
2626
"reflect"
27+
"regexp"
2728
"strings"
2829
"testing"
2930

@@ -670,6 +671,61 @@ func TestEvmRun(t *testing.T) {
670671
}
671672
}
672673

674+
func TestEvmRunRegEx(t *testing.T) {
675+
t.Parallel()
676+
tt := cmdtest.NewTestCmd(t, nil)
677+
for i, tc := range []struct {
678+
input []string
679+
wantStdout string
680+
wantStderr string
681+
}{
682+
{ // json tracing
683+
input: []string{"run", "--bench", "6040"},
684+
wantStdout: "./testdata/evmrun/9.out.1.txt",
685+
wantStderr: "./testdata/evmrun/9.out.2.txt",
686+
},
687+
{ // statetest subcommand
688+
input: []string{"statetest", "--bench", "./testdata/statetest.json"},
689+
wantStdout: "./testdata/evmrun/10.out.1.txt",
690+
wantStderr: "./testdata/evmrun/10.out.2.txt",
691+
},
692+
} {
693+
tt.Logf("args: go run ./cmd/evm %v\n", strings.Join(tc.input, " "))
694+
tt.Run("evm-test", tc.input...)
695+
696+
haveStdOut := tt.Output()
697+
tt.WaitExit()
698+
haveStdErr := tt.StderrText()
699+
700+
if have, wantFile := haveStdOut, tc.wantStdout; wantFile != "" {
701+
want, err := os.ReadFile(wantFile)
702+
if err != nil {
703+
t.Fatalf("test %d: could not read expected output: %v", i, err)
704+
}
705+
re, err := regexp.Compile(string(want))
706+
if err != nil {
707+
t.Fatalf("test %d: could not compile regular expression: %v", i, err)
708+
}
709+
if !re.Match(have) {
710+
t.Fatalf("test %d, output wrong, have \n%v\nwant\n%v\n", i, string(have), re)
711+
}
712+
}
713+
if have, wantFile := haveStdErr, tc.wantStderr; wantFile != "" {
714+
want, err := os.ReadFile(wantFile)
715+
if err != nil {
716+
t.Fatalf("test %d: could not read expected output: %v", i, err)
717+
}
718+
re, err := regexp.Compile(string(want))
719+
if err != nil {
720+
t.Fatalf("test %d: could not compile regular expression: %v", i, err)
721+
}
722+
if !re.MatchString(have) {
723+
t.Fatalf("test %d, output wrong, have \n%v\nwant\n%v\n", i, have, re)
724+
}
725+
}
726+
}
727+
}
728+
673729
// cmpJson compares the JSON in two byte slices.
674730
func cmpJson(a, b []byte) (bool, error) {
675731
var j, j2 interface{}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
\[
2+
\{
3+
"name": "00000006-naivefuzz-0",
4+
"pass": false,
5+
"stateRoot": "0xad1024c87b5548e77c937aa50f72b6cb620d278f4dd79bae7f78f71ff75af458",
6+
"fork": "London",
7+
"error": "post state root mismatch: got ad1024c87b5548e77c937aa50f72b6cb620d278f4dd79bae7f78f71ff75af458, want 0000000000000000000000000000000000000000000000000000000000000000",
8+
"benchStats": \{
9+
"time": \d+,
10+
"allocs": \d+,
11+
"bytesAllocated": \d+,
12+
"gasUsed": \d+
13+
\}
14+
\}
15+
\]

cmd/evm/testdata/evmrun/10.out.2.txt

Whitespace-only changes.

cmd/evm/testdata/evmrun/9.out.1.txt

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
EVM gas used: \d+
2+
execution time: \d+\.\d+.s
3+
allocations: \d+
4+
allocated bytes: \d+

0 commit comments

Comments
 (0)