2017-09-05 12:24:26 +03:00
|
|
|
// Copyright 2017 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/core/state"
|
|
|
|
"github.com/ethereum/go-ethereum/core/vm"
|
2021-11-25 15:17:09 +03:00
|
|
|
"github.com/ethereum/go-ethereum/eth/tracers/logger"
|
2017-09-05 12:24:26 +03:00
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
|
|
"github.com/ethereum/go-ethereum/tests"
|
|
|
|
|
2020-11-25 23:00:23 +03:00
|
|
|
"gopkg.in/urfave/cli.v1"
|
2017-09-05 12:24:26 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var stateTestCommand = cli.Command{
|
|
|
|
Action: stateTestCmd,
|
|
|
|
Name: "statetest",
|
|
|
|
Usage: "executes the given state tests",
|
|
|
|
ArgsUsage: "<file>",
|
|
|
|
}
|
|
|
|
|
2018-05-09 10:38:03 +03:00
|
|
|
// StatetestResult contains the execution status after running a state test, any
|
|
|
|
// error that might have occurred and a dump of the final state if requested.
|
2017-09-05 12:24:26 +03:00
|
|
|
type StatetestResult 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 stateTestCmd(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.GlobalInt(VerbosityFlag.Name)))
|
|
|
|
log.Root().SetHandler(glogger)
|
|
|
|
|
|
|
|
// Configure the EVM logger
|
2021-11-25 15:17:09 +03:00
|
|
|
config := &logger.Config{
|
2021-09-13 19:59:52 +03:00
|
|
|
EnableMemory: !ctx.GlobalBool(DisableMemoryFlag.Name),
|
|
|
|
DisableStack: ctx.GlobalBool(DisableStackFlag.Name),
|
|
|
|
DisableStorage: ctx.GlobalBool(DisableStorageFlag.Name),
|
|
|
|
EnableReturnData: !ctx.GlobalBool(DisableReturnDataFlag.Name),
|
2017-09-05 12:24:26 +03:00
|
|
|
}
|
|
|
|
var (
|
2021-11-05 13:48:21 +03:00
|
|
|
tracer vm.EVMLogger
|
2021-11-25 15:17:09 +03:00
|
|
|
debugger *logger.StructLogger
|
2017-09-05 12:24:26 +03:00
|
|
|
)
|
|
|
|
switch {
|
|
|
|
case ctx.GlobalBool(MachineFlag.Name):
|
2021-11-25 15:17:09 +03:00
|
|
|
tracer = logger.NewJSONLogger(config, os.Stderr)
|
2017-09-05 12:24:26 +03:00
|
|
|
|
|
|
|
case ctx.GlobalBool(DebugFlag.Name):
|
2021-11-25 15:17:09 +03:00
|
|
|
debugger = logger.NewStructLogger(config)
|
2017-09-05 12:24:26 +03:00
|
|
|
tracer = debugger
|
|
|
|
|
|
|
|
default:
|
2021-11-25 15:17:09 +03:00
|
|
|
debugger = logger.NewStructLogger(config)
|
2017-09-05 12:24:26 +03:00
|
|
|
}
|
|
|
|
// Load the test content from the input file
|
|
|
|
src, err := ioutil.ReadFile(ctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var tests map[string]tests.StateTest
|
|
|
|
if err = json.Unmarshal(src, &tests); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Iterate over all the tests, run them and aggregate the results
|
|
|
|
cfg := vm.Config{
|
|
|
|
Tracer: tracer,
|
|
|
|
Debug: ctx.GlobalBool(DebugFlag.Name) || ctx.GlobalBool(MachineFlag.Name),
|
|
|
|
}
|
|
|
|
results := make([]StatetestResult, 0, len(tests))
|
|
|
|
for key, test := range tests {
|
|
|
|
for _, st := range test.Subtests() {
|
|
|
|
// Run the test and aggregate the result
|
|
|
|
result := &StatetestResult{Name: key, Fork: st.Fork, Pass: true}
|
cmd/geth, eth, core: snapshot dump + unify with trie dump (#22795)
* cmd/geth, eth, core: snapshot dump + unify with trie dump
* cmd/evm: dump API fixes
* cmd/geth, core, eth: fix some remaining errors
* cmd/evm: dump - add limit, support address startkey, address review concerns
* cmd, core/state, eth: minor polishes, fix snap dump crash, unify format
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2021-05-12 11:05:39 +03:00
|
|
|
_, s, err := test.Run(st, cfg, false)
|
2018-10-04 11:22:41 +03:00
|
|
|
// print state root for evmlab tracing
|
cmd/geth, eth, core: snapshot dump + unify with trie dump (#22795)
* cmd/geth, eth, core: snapshot dump + unify with trie dump
* cmd/evm: dump API fixes
* cmd/geth, core, eth: fix some remaining errors
* cmd/evm: dump - add limit, support address startkey, address review concerns
* cmd, core/state, eth: minor polishes, fix snap dump crash, unify format
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2021-05-12 11:05:39 +03:00
|
|
|
if ctx.GlobalBool(MachineFlag.Name) && s != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "{\"stateRoot\": \"%x\"}\n", s.IntermediateRoot(false))
|
2018-10-04 11:22:41 +03:00
|
|
|
}
|
2017-10-20 13:22:06 +03:00
|
|
|
if err != nil {
|
2017-09-05 12:24:26 +03:00
|
|
|
// Test failed, mark as so and dump any state to aid debugging
|
|
|
|
result.Pass, result.Error = false, err.Error()
|
cmd/geth, eth, core: snapshot dump + unify with trie dump (#22795)
* cmd/geth, eth, core: snapshot dump + unify with trie dump
* cmd/evm: dump API fixes
* cmd/geth, core, eth: fix some remaining errors
* cmd/evm: dump - add limit, support address startkey, address review concerns
* cmd, core/state, eth: minor polishes, fix snap dump crash, unify format
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2021-05-12 11:05:39 +03:00
|
|
|
if ctx.GlobalBool(DumpFlag.Name) && s != nil {
|
|
|
|
dump := s.RawDump(nil)
|
2017-09-05 12:24:26 +03:00
|
|
|
result.State = &dump
|
|
|
|
}
|
|
|
|
}
|
2017-10-20 13:22:06 +03:00
|
|
|
|
2017-09-05 12:24:26 +03:00
|
|
|
results = append(results, *result)
|
|
|
|
|
|
|
|
// Print any structured logs collected
|
|
|
|
if ctx.GlobalBool(DebugFlag.Name) {
|
|
|
|
if debugger != nil {
|
2018-08-01 19:09:08 +03:00
|
|
|
fmt.Fprintln(os.Stderr, "#### TRACE ####")
|
2021-11-25 15:17:09 +03:00
|
|
|
logger.WriteTrace(os.Stderr, debugger.StructLogs())
|
2017-09-05 12:24:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out, _ := json.MarshalIndent(results, "", " ")
|
2018-08-01 19:09:08 +03:00
|
|
|
fmt.Println(string(out))
|
2017-09-05 12:24:26 +03:00
|
|
|
return nil
|
|
|
|
}
|