diff --git a/tests/init_test.go b/tests/init_test.go index 053cbd6fcd..d715de02fb 100644 --- a/tests/init_test.go +++ b/tests/init_test.go @@ -18,6 +18,7 @@ package tests import ( "encoding/json" + "flag" "fmt" "io" "io/ioutil" @@ -33,6 +34,17 @@ import ( "github.com/ethereum/go-ethereum/params" ) +// Command line flags to configure the interpreters. +var ( + testEVM = flag.String("vm.evm", "", "EVM configuration") + testEWASM = flag.String("vm.ewasm", "", "EWASM configuration") +) + +func TestMain(m *testing.M) { + flag.Parse() + os.Exit(m.Run()) +} + var ( baseDir = filepath.Join(".", "testdata") blockTestDir = filepath.Join(baseDir, "BlockchainTests") diff --git a/tests/state_test.go b/tests/state_test.go index 0cf124d727..d25b157275 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -19,12 +19,10 @@ package tests import ( "bufio" "bytes" - "flag" "fmt" "reflect" "testing" - "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/core/vm" ) @@ -71,20 +69,15 @@ func TestState(t *testing.T) { // Transactions with gasLimit above this value will not get a VM trace on failure. const traceErrorLimit = 400000 -// The VM config for state tests that accepts --vm.* command line arguments. -var testVMConfig = func() vm.Config { - vmconfig := vm.Config{} - flag.StringVar(&vmconfig.EVMInterpreter, utils.EVMInterpreterFlag.Name, utils.EVMInterpreterFlag.Value, utils.EVMInterpreterFlag.Usage) - flag.StringVar(&vmconfig.EWASMInterpreter, utils.EWASMInterpreterFlag.Name, utils.EWASMInterpreterFlag.Value, utils.EWASMInterpreterFlag.Usage) - flag.Parse() - return vmconfig -}() - func withTrace(t *testing.T, gasLimit uint64, test func(vm.Config) error) { - err := test(testVMConfig) + // Use config from command line arguments. + config := vm.Config{EVMInterpreter: *testEVM, EWASMInterpreter: *testEWASM} + err := test(config) if err == nil { return } + + // Test failed, re-run with tracing enabled. t.Error(err) if gasLimit > traceErrorLimit { t.Log("gas limit too high for EVM trace") @@ -93,7 +86,8 @@ func withTrace(t *testing.T, gasLimit uint64, test func(vm.Config) error) { buf := new(bytes.Buffer) w := bufio.NewWriter(buf) tracer := vm.NewJSONLogger(&vm.LogConfig{DisableMemory: true}, w) - err2 := test(vm.Config{Debug: true, Tracer: tracer}) + config.Debug, config.Tracer = true, tracer + err2 := test(config) if !reflect.DeepEqual(err, err2) { t.Errorf("different error for second run: %v", err2) }