cmd/evm: Add --single-test option to blocktest

This commit is contained in:
Mario Vega 2023-10-25 23:58:47 +00:00
parent 58ae1df684
commit ba928796db

View file

@ -30,11 +30,20 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
var singleTestFlag = &cli.StringFlag{
Name: "single-test",
Value: "",
Usage: "Run a single test from the json file",
}
var blockTestCommand = &cli.Command{ var blockTestCommand = &cli.Command{
Action: blockTestCmd, Action: blockTestCmd,
Name: "blocktest", Name: "blocktest",
Usage: "executes the given blockchain tests", Usage: "executes the given blockchain tests",
ArgsUsage: "<file>", ArgsUsage: "<file>",
Flags: []cli.Flag{
singleTestFlag,
},
} }
func blockTestCmd(ctx *cli.Context) error { func blockTestCmd(ctx *cli.Context) error {
@ -61,6 +70,17 @@ func blockTestCmd(ctx *cli.Context) error {
if err = json.Unmarshal(src, &tests); err != nil { if err = json.Unmarshal(src, &tests); err != nil {
return err return err
} }
singleTest := ctx.String(singleTestFlag.Name)
if singleTest != "" {
if test, ok := tests[singleTest]; ok {
if err := test.Run(false, rawdb.HashScheme, tracer); err != nil {
return fmt.Errorf("test %v: %w", singleTest, err)
}
} else {
return fmt.Errorf("test %v not found", singleTest)
}
return nil
}
// run them in order // run them in order
var keys []string var keys []string
for key := range tests { for key := range tests {