From 8e8a9585f07034235a9614562b91d7e36b119f58 Mon Sep 17 00:00:00 2001 From: marioevz Date: Thu, 19 Jan 2023 15:27:40 -0600 Subject: [PATCH 1/3] cmd/evm: add blocktest subcommand --- cmd/evm/blockrunner.go | 73 ++++++++++++++++++++++++++++++++++++++++++ cmd/evm/main.go | 1 + 2 files changed, 74 insertions(+) create mode 100644 cmd/evm/blockrunner.go diff --git a/cmd/evm/blockrunner.go b/cmd/evm/blockrunner.go new file mode 100644 index 00000000000..d1392347695 --- /dev/null +++ b/cmd/evm/blockrunner.go @@ -0,0 +1,73 @@ +// Copyright 2023 The go-ethereum Authors +// This file is part of go-ethereum. +// +// go-ethereum is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// go-ethereum is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with go-ethereum. If not, see . + +package main + +import ( + "encoding/json" + "errors" + "os" + + "github.com/ethereum/go-ethereum/core/state" + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/tests" + + "github.com/urfave/cli/v2" +) + +var blockTestCommand = &cli.Command{ + Action: blockTestCmd, + Name: "blocktest", + Usage: "executes the given blockchain tests", + ArgsUsage: "", +} + +// BlocktestResult contains the execution status after running a blockchain test, any +// error that might have occurred and a dump of the final blockchain if requested. +type BlocktestResult struct { + Name string `json:"name"` + Pass bool `json:"pass"` + Fork string `json:"fork"` + Error string `json:"error,omitempty"` + State *state.Dump `json:"state,omitempty"` +} + +func blockTestCmd(ctx *cli.Context) error { + if len(ctx.Args().First()) == 0 { + return errors.New("path-to-test argument required") + } + // Configure the go-ethereum logger + glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.TerminalFormat(false))) + glogger.Verbosity(log.Lvl(ctx.Int(VerbosityFlag.Name))) + log.Root().SetHandler(glogger) + + // Load the test content from the input file + src, err := os.ReadFile(ctx.Args().First()) + if err != nil { + return err + } + var tests map[string]tests.BlockTest + if err = json.Unmarshal(src, &tests); err != nil { + return err + } + for _, test := range tests { + if err := test.Run(false); err != nil { + return err + } + + } + return nil +} diff --git a/cmd/evm/main.go b/cmd/evm/main.go index 5f9e75f48c6..4afb60820f8 100644 --- a/cmd/evm/main.go +++ b/cmd/evm/main.go @@ -217,6 +217,7 @@ func init() { compileCommand, disasmCommand, runCommand, + blockTestCommand, stateTestCommand, stateTransitionCommand, transactionCommand, From 1e2b10911be7ebc9d8a862c241725391250361ac Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Fri, 20 Jan 2023 04:29:43 -0500 Subject: [PATCH 2/3] Update cmd/evm/blockrunner.go Co-authored-by: lightclient <14004106+lightclient@users.noreply.github.com> --- cmd/evm/blockrunner.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/evm/blockrunner.go b/cmd/evm/blockrunner.go index d1392347695..c641ab566ca 100644 --- a/cmd/evm/blockrunner.go +++ b/cmd/evm/blockrunner.go @@ -67,7 +67,6 @@ func blockTestCmd(ctx *cli.Context) error { if err := test.Run(false); err != nil { return err } - } return nil } From dee1b1be7d3ebfb19acb158bc161cee7761f9bfc Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 26 Jan 2023 14:28:27 +0100 Subject: [PATCH 3/3] cmd/evm: simplify blockrunner --- cmd/evm/blockrunner.go | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/cmd/evm/blockrunner.go b/cmd/evm/blockrunner.go index c641ab566ca..ffd76b8fb0c 100644 --- a/cmd/evm/blockrunner.go +++ b/cmd/evm/blockrunner.go @@ -19,12 +19,11 @@ package main import ( "encoding/json" "errors" + "fmt" "os" - "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/tests" - "github.com/urfave/cli/v2" ) @@ -35,16 +34,6 @@ var blockTestCommand = &cli.Command{ ArgsUsage: "", } -// BlocktestResult contains the execution status after running a blockchain test, any -// error that might have occurred and a dump of the final blockchain if requested. -type BlocktestResult struct { - Name string `json:"name"` - Pass bool `json:"pass"` - Fork string `json:"fork"` - Error string `json:"error,omitempty"` - State *state.Dump `json:"state,omitempty"` -} - func blockTestCmd(ctx *cli.Context) error { if len(ctx.Args().First()) == 0 { return errors.New("path-to-test argument required") @@ -63,9 +52,9 @@ func blockTestCmd(ctx *cli.Context) error { if err = json.Unmarshal(src, &tests); err != nil { return err } - for _, test := range tests { + for i, test := range tests { if err := test.Run(false); err != nil { - return err + return fmt.Errorf("test %v: %w", i, err) } } return nil