Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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.MatchString(string(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, string(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+