cmd/evm: restore --bench flag to evm statetest (#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 <fjl@twurst.com>
This commit is contained in:
parent
4af9af419d
commit
c43faa3d9d
|
@ -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,
|
||||
|
|
|
@ -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.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{}
|
||||
|
|
|
@ -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+
|
||||
\}
|
||||
\}
|
||||
\]
|
|
@ -0,0 +1,4 @@
|
|||
EVM gas used: \d+
|
||||
execution time: \d+\.\d+.s
|
||||
allocations: \d+
|
||||
allocated bytes: \d+
|
Loading…
Reference in New Issue