Skip to content

Commit 90f15a0

Browse files
marioevzholimanlightclient
authored
cmd/evm: add blocktest subcommand to evm (#26526)
Adds blocktest subcommand to the evm command, which is very similar to statetest, but instead of loading a StateTest static test it loads a BlockchainTest from a json file and runs it. Co-authored-by: Martin Holst Swende <martin@swende.se> Co-authored-by: lightclient <14004106+lightclient@users.noreply.github.com>
1 parent a63875b commit 90f15a0

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

cmd/evm/blockrunner.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2023 The go-ethereum Authors
2+
// This file is part of go-ethereum.
3+
//
4+
// go-ethereum is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// go-ethereum is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package main
18+
19+
import (
20+
"encoding/json"
21+
"errors"
22+
"fmt"
23+
"os"
24+
25+
"github.com/ethereum/go-ethereum/log"
26+
"github.com/ethereum/go-ethereum/tests"
27+
"github.com/urfave/cli/v2"
28+
)
29+
30+
var blockTestCommand = &cli.Command{
31+
Action: blockTestCmd,
32+
Name: "blocktest",
33+
Usage: "executes the given blockchain tests",
34+
ArgsUsage: "<file>",
35+
}
36+
37+
func blockTestCmd(ctx *cli.Context) error {
38+
if len(ctx.Args().First()) == 0 {
39+
return errors.New("path-to-test argument required")
40+
}
41+
// Configure the go-ethereum logger
42+
glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.TerminalFormat(false)))
43+
glogger.Verbosity(log.Lvl(ctx.Int(VerbosityFlag.Name)))
44+
log.Root().SetHandler(glogger)
45+
46+
// Load the test content from the input file
47+
src, err := os.ReadFile(ctx.Args().First())
48+
if err != nil {
49+
return err
50+
}
51+
var tests map[string]tests.BlockTest
52+
if err = json.Unmarshal(src, &tests); err != nil {
53+
return err
54+
}
55+
for i, test := range tests {
56+
if err := test.Run(false); err != nil {
57+
return fmt.Errorf("test %v: %w", i, err)
58+
}
59+
}
60+
return nil
61+
}

cmd/evm/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ func init() {
218218
compileCommand,
219219
disasmCommand,
220220
runCommand,
221+
blockTestCommand,
221222
stateTestCommand,
222223
stateTransitionCommand,
223224
transactionCommand,

0 commit comments

Comments
 (0)