github.com/gnattishness/bazel-go-ethereum@v0.0.0-20190929123618-7022a154f56d/tests/state_test.go (about) 1 // Copyright 2015 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser 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 // The go-ethereum library 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 Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package tests 18 19 import ( 20 "bufio" 21 "bytes" 22 "fmt" 23 "reflect" 24 "testing" 25 26 "github.com/ethereum/go-ethereum/core/vm" 27 ) 28 29 func TestState(t *testing.T) { 30 t.Parallel() 31 32 st := new(testMatcher) 33 // Long tests: 34 st.slow(`^stAttackTest/ContractCreationSpam`) 35 st.slow(`^stBadOpcode/badOpcodes`) 36 st.slow(`^stPreCompiledContracts/modexp`) 37 st.slow(`^stQuadraticComplexityTest/`) 38 st.slow(`^stStaticCall/static_Call50000`) 39 st.slow(`^stStaticCall/static_Return50000`) 40 st.slow(`^stStaticCall/static_Call1MB`) 41 st.slow(`^stSystemOperationsTest/CallRecursiveBomb`) 42 st.slow(`^stTransactionTest/Opcodes_TransactionInit`) 43 // Broken tests: 44 st.skipLoad(`^stTransactionTest/OverflowGasRequire\.json`) // gasLimit > 256 bits 45 st.skipLoad(`^stTransactionTest/zeroSigTransa[^/]*\.json`) // EIP-86 is not supported yet 46 // Expected failures: 47 //st.fails(`^stRevertTest/RevertPrecompiledTouch(_storage)?\.json/Byzantium/0`, "bug in test") 48 //st.fails(`^stRevertTest/RevertPrecompiledTouch(_storage)?\.json/Byzantium/3`, "bug in test") 49 //st.fails(`^stRevertTest/RevertPrecompiledTouch(_storage)?\.json/Constantinople/0`, "bug in test") 50 //st.fails(`^stRevertTest/RevertPrecompiledTouch(_storage)?\.json/Constantinople/3`, "bug in test") 51 //st.fails(`^stRevertTest/RevertPrecompiledTouch(_storage)?\.json/ConstantinopleFix/0`, "bug in test") 52 //st.fails(`^stRevertTest/RevertPrecompiledTouch(_storage)?\.json/ConstantinopleFix/3`, "bug in test") 53 54 st.walk(t, stateTestDir, func(t *testing.T, name string, test *StateTest) { 55 for _, subtest := range test.Subtests() { 56 subtest := subtest 57 key := fmt.Sprintf("%s/%d", subtest.Fork, subtest.Index) 58 name := name + "/" + key 59 t.Run(key, func(t *testing.T) { 60 withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error { 61 _, err := test.Run(subtest, vmconfig) 62 return st.checkFailure(t, name, err) 63 }) 64 }) 65 } 66 }) 67 } 68 69 // Transactions with gasLimit above this value will not get a VM trace on failure. 70 const traceErrorLimit = 400000 71 72 func withTrace(t *testing.T, gasLimit uint64, test func(vm.Config) error) { 73 // Use config from command line arguments. 74 config := vm.Config{EVMInterpreter: *testEVM, EWASMInterpreter: *testEWASM} 75 err := test(config) 76 if err == nil { 77 return 78 } 79 80 // Test failed, re-run with tracing enabled. 81 t.Error(err) 82 if gasLimit > traceErrorLimit { 83 t.Log("gas limit too high for EVM trace") 84 return 85 } 86 buf := new(bytes.Buffer) 87 w := bufio.NewWriter(buf) 88 tracer := vm.NewJSONLogger(&vm.LogConfig{DisableMemory: true}, w) 89 config.Debug, config.Tracer = true, tracer 90 err2 := test(config) 91 if !reflect.DeepEqual(err, err2) { 92 t.Errorf("different error for second run: %v", err2) 93 } 94 w.Flush() 95 if buf.Len() == 0 { 96 t.Log("no EVM operation logs generated") 97 } else { 98 t.Log("EVM operation log:\n" + buf.String()) 99 } 100 //t.Logf("EVM output: 0x%x", tracer.Output()) 101 //t.Logf("EVM error: %v", tracer.Error()) 102 }