From cb333a11ea522b28a46339ea7d05b222ebade181 Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Mon, 20 Jan 2025 12:48:19 -0700 Subject: [PATCH 1/3] Restore --bench flag to evm statetest Restore the --bench flag to `evm statetest`, as well as testing for its function in `evm run` and `evmstatetest` --- cmd/evm/staterunner.go | 1 + cmd/evm/t8n_test.go | 56 ++++++++++++++++++++++++++++ cmd/evm/testdata/evmrun/10.out.1.txt | 15 ++++++++ cmd/evm/testdata/evmrun/10.out.2.txt | 0 cmd/evm/testdata/evmrun/9.out.1.txt | 0 cmd/evm/testdata/evmrun/9.out.2.txt | 4 ++ 6 files changed, 76 insertions(+) create mode 100644 cmd/evm/testdata/evmrun/10.out.1.txt create mode 100644 cmd/evm/testdata/evmrun/10.out.2.txt create mode 100644 cmd/evm/testdata/evmrun/9.out.1.txt create mode 100644 cmd/evm/testdata/evmrun/9.out.2.txt diff --git a/cmd/evm/staterunner.go b/cmd/evm/staterunner.go index 4c2dfeabc630..8f81a953159b 100644 --- a/cmd/evm/staterunner.go +++ b/cmd/evm/staterunner.go @@ -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: "", Flags: slices.Concat([]cli.Flag{ + BenchFlag, DumpFlag, HumanReadableFlag, RunFlag, diff --git a/cmd/evm/t8n_test.go b/cmd/evm/t8n_test.go index 27c6c43164a7..fc829eba499c 100644 --- a/cmd/evm/t8n_test.go +++ b/cmd/evm/t8n_test.go @@ -24,6 +24,7 @@ import ( "os" "path/filepath" "reflect" + "regexp" "strings" "testing" @@ -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{} diff --git a/cmd/evm/testdata/evmrun/10.out.1.txt b/cmd/evm/testdata/evmrun/10.out.1.txt new file mode 100644 index 000000000000..5f94bdd2611d --- /dev/null +++ b/cmd/evm/testdata/evmrun/10.out.1.txt @@ -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+ + \} + \} +\] \ No newline at end of file diff --git a/cmd/evm/testdata/evmrun/10.out.2.txt b/cmd/evm/testdata/evmrun/10.out.2.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/cmd/evm/testdata/evmrun/9.out.1.txt b/cmd/evm/testdata/evmrun/9.out.1.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/cmd/evm/testdata/evmrun/9.out.2.txt b/cmd/evm/testdata/evmrun/9.out.2.txt new file mode 100644 index 000000000000..90def283e018 --- /dev/null +++ b/cmd/evm/testdata/evmrun/9.out.2.txt @@ -0,0 +1,4 @@ +EVM gas used: \d+ +execution time: \d+\.\d+.s +allocations: \d+ +allocated bytes: \d+ From 6915628f82ea88d4f60ceaa815d2b5707919b457 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 21 Jan 2025 13:46:20 +0100 Subject: [PATCH 2/3] Update t8n_test.go --- cmd/evm/t8n_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/evm/t8n_test.go b/cmd/evm/t8n_test.go index fc829eba499c..2141dfa59d86 100644 --- a/cmd/evm/t8n_test.go +++ b/cmd/evm/t8n_test.go @@ -706,7 +706,7 @@ func TestEvmRunRegEx(t *testing.T) { if err != nil { t.Fatalf("test %d: could not compile regular expression: %v", i, err) } - if !re.MatchString(string(have)) { + if !re.Match(have) { t.Fatalf("test %d, output wrong, have \n%v\nwant\n%v\n", i, string(have), re) } } From e673af9acff69ce7bcf377be086348faaa60b396 Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Tue, 21 Jan 2025 11:19:30 -0700 Subject: [PATCH 3/3] fix lint error --- cmd/evm/t8n_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/evm/t8n_test.go b/cmd/evm/t8n_test.go index 2141dfa59d86..78f399856106 100644 --- a/cmd/evm/t8n_test.go +++ b/cmd/evm/t8n_test.go @@ -720,7 +720,7 @@ func TestEvmRunRegEx(t *testing.T) { 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) + t.Fatalf("test %d, output wrong, have \n%v\nwant\n%v\n", i, have, re) } } }