forked from cerc-io/plugeth
e9f78db79d
* cmd/evm: improve flags handling This fixes some issues with flags in cmd/evm. The supported flags did not actually show up in help output because they weren't categorized. I'm also adding the VM-related flags to the run command here so they can be given after the subcommand name. So it can be run like this now: ./evm run --code 6001 --debug * cmd/evm: enable all forks by default in run command The default genesis was just empty with no forks at all, which is annoying because contracts will be relying on opcodes introduced in a fork. So this changes the default to have all forks enabled. * core/asm: fix some issues in the assembler This fixes minor bugs in the old assembler: - It is now possible to have comments on the same line as an instruction. - Errors for invalid numbers in the jump instruction are reported better - Line numbers in errors were off by one
70 lines
2.0 KiB
Go
70 lines
2.0 KiB
Go
// 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 <http://www.gnu.org/licenses/>.
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
|
"github.com/ethereum/go-ethereum/core/vm"
|
|
"github.com/ethereum/go-ethereum/eth/tracers/logger"
|
|
"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: "<file>",
|
|
}
|
|
|
|
func blockTestCmd(ctx *cli.Context) error {
|
|
if len(ctx.Args().First()) == 0 {
|
|
return errors.New("path-to-test argument required")
|
|
}
|
|
|
|
var tracer vm.EVMLogger
|
|
// Configure the EVM logger
|
|
if ctx.Bool(MachineFlag.Name) {
|
|
tracer = logger.NewJSONLogger(&logger.Config{
|
|
EnableMemory: !ctx.Bool(DisableMemoryFlag.Name),
|
|
DisableStack: ctx.Bool(DisableStackFlag.Name),
|
|
DisableStorage: ctx.Bool(DisableStorageFlag.Name),
|
|
EnableReturnData: !ctx.Bool(DisableReturnDataFlag.Name),
|
|
}, os.Stderr)
|
|
}
|
|
// 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 i, test := range tests {
|
|
if err := test.Run(false, rawdb.HashScheme, tracer); err != nil {
|
|
return fmt.Errorf("test %v: %w", i, err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|