github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/tests/state_test.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 12:09:50</date> 10 //</624342686119235584> 11 12 // 13 // 14 // 15 // 16 // 17 // 18 // 19 // 20 // 21 // 22 // 23 // 24 // 25 // 26 // 27 28 package tests 29 30 import ( 31 "bytes" 32 "fmt" 33 "reflect" 34 "testing" 35 36 "github.com/ethereum/go-ethereum/core/vm" 37 ) 38 39 func TestState(t *testing.T) { 40 t.Parallel() 41 42 st := new(testMatcher) 43 // 44 st.skipShortMode(`^stQuadraticComplexityTest/`) 45 // 46 st.skipLoad(`^stTransactionTest/OverflowGasRequire\.json`) // 47 st.skipLoad(`^stTransactionTest/zeroSigTransa[^/]*\.json`) // 48 // 49 st.fails(`^stRevertTest/RevertPrecompiledTouch\.json/EIP158`, "bug in test") 50 st.fails(`^stRevertTest/RevertPrecompiledTouch\.json/Byzantium`, "bug in test") 51 52 st.walk(t, stateTestDir, func(t *testing.T, name string, test *StateTest) { 53 for _, subtest := range test.Subtests() { 54 subtest := subtest 55 key := fmt.Sprintf("%s/%d", subtest.Fork, subtest.Index) 56 name := name + "/" + key 57 t.Run(key, func(t *testing.T) { 58 if subtest.Fork == "Constantinople" { 59 t.Skip("constantinople not supported yet") 60 } 61 withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error { 62 _, err := test.Run(subtest, vmconfig) 63 return st.checkFailure(t, name, err) 64 }) 65 }) 66 } 67 }) 68 } 69 70 // 71 const traceErrorLimit = 400000 72 73 func withTrace(t *testing.T, gasLimit uint64, test func(vm.Config) error) { 74 err := test(vm.Config{}) 75 if err == nil { 76 return 77 } 78 t.Error(err) 79 if gasLimit > traceErrorLimit { 80 t.Log("gas limit too high for EVM trace") 81 return 82 } 83 tracer := vm.NewStructLogger(nil) 84 err2 := test(vm.Config{Debug: true, Tracer: tracer}) 85 if !reflect.DeepEqual(err, err2) { 86 t.Errorf("different error for second run: %v", err2) 87 } 88 buf := new(bytes.Buffer) 89 vm.WriteTrace(buf, tracer.StructLogs()) 90 if buf.Len() == 0 { 91 t.Log("no EVM operation logs generated") 92 } else { 93 t.Log("EVM operation log:\n" + buf.String()) 94 } 95 t.Logf("EVM output: 0x%x", tracer.Output()) 96 t.Logf("EVM error: %v", tracer.Error()) 97 } 98