github.com/theQRL/go-zond@v0.1.1/cmd/evm/blockrunner.go (about) 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/theQRL/go-zond/core/rawdb" 26 "github.com/theQRL/go-zond/core/vm" 27 "github.com/theQRL/go-zond/zond/tracers/logger" 28 "github.com/theQRL/go-zond/log" 29 "github.com/theQRL/go-zond/tests" 30 "github.com/urfave/cli/v2" 31 ) 32 33 var blockTestCommand = &cli.Command{ 34 Action: blockTestCmd, 35 Name: "blocktest", 36 Usage: "executes the given blockchain tests", 37 ArgsUsage: "<file>", 38 } 39 40 func blockTestCmd(ctx *cli.Context) error { 41 if len(ctx.Args().First()) == 0 { 42 return errors.New("path-to-test argument required") 43 } 44 // Configure the go-ethereum logger 45 glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.TerminalFormat(false))) 46 glogger.Verbosity(log.Lvl(ctx.Int(VerbosityFlag.Name))) 47 log.Root().SetHandler(glogger) 48 var tracer vm.EVMLogger 49 // Configure the EVM logger 50 if ctx.Bool(MachineFlag.Name) { 51 tracer = logger.NewJSONLogger(&logger.Config{ 52 EnableMemory: !ctx.Bool(DisableMemoryFlag.Name), 53 DisableStack: ctx.Bool(DisableStackFlag.Name), 54 DisableStorage: ctx.Bool(DisableStorageFlag.Name), 55 EnableReturnData: !ctx.Bool(DisableReturnDataFlag.Name), 56 }, os.Stderr) 57 } 58 // Load the test content from the input file 59 src, err := os.ReadFile(ctx.Args().First()) 60 if err != nil { 61 return err 62 } 63 var tests map[string]tests.BlockTest 64 if err = json.Unmarshal(src, &tests); err != nil { 65 return err 66 } 67 for i, test := range tests { 68 if err := test.Run(false, rawdb.HashScheme, tracer); err != nil { 69 return fmt.Errorf("test %v: %w", i, err) 70 } 71 } 72 return nil 73 }