Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/evm: restore --bench flag to evm statetest #31055

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/evm/staterunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var stateTestCommand = &cli.Command{
Usage: "Executes the given state tests. Filenames can be fed via standard input (batch mode) or as an argument (one-off execution).",
ArgsUsage: "<file>",
Flags: slices.Concat([]cli.Flag{
BenchFlag,
DumpFlag,
HumanReadableFlag,
RunFlag,
Expand Down
56 changes: 56 additions & 0 deletions cmd/evm/t8n_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os"
"path/filepath"
"reflect"
"regexp"
"strings"
"testing"

Expand Down Expand Up @@ -670,6 +671,61 @@ func TestEvmRun(t *testing.T) {
}
}

func TestEvmRunRegEx(t *testing.T) {
t.Parallel()
tt := cmdtest.NewTestCmd(t, nil)
for i, tc := range []struct {
input []string
wantStdout string
wantStderr string
}{
{ // json tracing
input: []string{"run", "--bench", "6040"},
wantStdout: "./testdata/evmrun/9.out.1.txt",
wantStderr: "./testdata/evmrun/9.out.2.txt",
},
{ // statetest subcommand
input: []string{"statetest", "--bench", "./testdata/statetest.json"},
wantStdout: "./testdata/evmrun/10.out.1.txt",
wantStderr: "./testdata/evmrun/10.out.2.txt",
},
} {
tt.Logf("args: go run ./cmd/evm %v\n", strings.Join(tc.input, " "))
tt.Run("evm-test", tc.input...)

haveStdOut := tt.Output()
tt.WaitExit()
haveStdErr := tt.StderrText()

if have, wantFile := haveStdOut, tc.wantStdout; wantFile != "" {
want, err := os.ReadFile(wantFile)
if err != nil {
t.Fatalf("test %d: could not read expected output: %v", i, err)
}
re, err := regexp.Compile(string(want))
if err != nil {
t.Fatalf("test %d: could not compile regular expression: %v", i, err)
}
if !re.Match(have) {
t.Fatalf("test %d, output wrong, have \n%v\nwant\n%v\n", i, string(have), re)
}
}
if have, wantFile := haveStdErr, tc.wantStderr; wantFile != "" {
want, err := os.ReadFile(wantFile)
if err != nil {
t.Fatalf("test %d: could not read expected output: %v", i, err)
}
re, err := regexp.Compile(string(want))
if err != nil {
t.Fatalf("test %d: could not compile regular expression: %v", i, err)
}
if !re.MatchString(have) {
t.Fatalf("test %d, output wrong, have \n%v\nwant\n%v\n", i, have, re)
}
}
}
}

// cmpJson compares the JSON in two byte slices.
func cmpJson(a, b []byte) (bool, error) {
var j, j2 interface{}
Expand Down
15 changes: 15 additions & 0 deletions cmd/evm/testdata/evmrun/10.out.1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
\[
\{
"name": "00000006-naivefuzz-0",
"pass": false,
"stateRoot": "0xad1024c87b5548e77c937aa50f72b6cb620d278f4dd79bae7f78f71ff75af458",
"fork": "London",
"error": "post state root mismatch: got ad1024c87b5548e77c937aa50f72b6cb620d278f4dd79bae7f78f71ff75af458, want 0000000000000000000000000000000000000000000000000000000000000000",
"benchStats": \{
"time": \d+,
"allocs": \d+,
"bytesAllocated": \d+,
"gasUsed": \d+
\}
\}
\]
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions cmd/evm/testdata/evmrun/9.out.2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
EVM gas used: \d+
execution time: \d+\.\d+.s
allocations: \d+
allocated bytes: \d+