github.com/n1ghtfa1l/go-vnt@v0.6.4-alpha.6/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 "bytes" 21 "fmt" 22 "reflect" 23 "testing" 24 25 "github.com/vntchain/go-vnt/core/vm" 26 "github.com/vntchain/go-vnt/core/wavm" 27 ) 28 29 func TestState(t *testing.T) { 30 t.Parallel() 31 32 st := new(testMatcher) 33 // Long tests: 34 st.skipShortMode(`^stQuadraticComplexityTest/`) 35 // Broken tests: 36 st.skipLoad(`^stTransactionTest/OverflowGasRequire\.json`) // gasLimit > 256 bits 37 st.skipLoad(`^stTransactionTest/zeroSigTransa[^/]*\.json`) // EIP-86 is not supported yet 38 // Expected failures: 39 st.fails(`^stRevertTest/RevertPrecompiledTouch\.json/EIP158`, "bug in test") 40 st.fails(`^stRevertTest/RevertPrecompiledTouch\.json/Byzantium`, "bug in test") 41 42 st.walk(t, stateTestDir, func(t *testing.T, name string, test *StateTest) { 43 for _, subtest := range test.Subtests() { 44 subtest := subtest 45 key := fmt.Sprintf("%s/%d", subtest.Fork, subtest.Index) 46 name := name + "/" + key 47 t.Run(key, func(t *testing.T) { 48 if subtest.Fork == "Constantinople" { 49 t.Skip("constantinople not supported yet") 50 } 51 withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error { 52 _, err := test.Run(subtest, vmconfig) 53 return st.checkFailure(t, name, err) 54 }) 55 }) 56 } 57 }) 58 } 59 60 // Transactions with gasLimit above this value will not get a VM trace on failure. 61 const traceErrorLimit = 400000 62 63 func withTrace(t *testing.T, gasLimit uint64, test func(vm.Config) error) { 64 err := test(vm.Config{}) 65 if err == nil { 66 return 67 } 68 t.Error(err) 69 if gasLimit > traceErrorLimit { 70 t.Log("gas limit too high for VM trace") 71 return 72 } 73 tracer := wavm.NewWasmLogger(nil) 74 err2 := test(vm.Config{Debug: true, Tracer: tracer}) 75 if !reflect.DeepEqual(err, err2) { 76 t.Errorf("different error for second run: %v", err2) 77 } 78 buf := new(bytes.Buffer) 79 wavm.WriteTrace(buf, tracer.StructLogs()) 80 if buf.Len() == 0 { 81 t.Log("no EVM operation logs generated") 82 } else { 83 t.Log("EVM operation log:\n" + buf.String()) 84 } 85 t.Logf("EVM output: 0x%x", tracer.Output()) 86 t.Logf("EVM error: %v", tracer.Error()) 87 }