github.com/neatio-net/neatio@v1.7.3-0.20231114194659-f4d7a2226baa/tests/state_test.go (about) 1 package tests 2 3 import ( 4 "bytes" 5 "fmt" 6 "reflect" 7 "testing" 8 9 "github.com/neatio-net/neatio/chain/core/vm" 10 ) 11 12 func TestState(t *testing.T) { 13 t.Parallel() 14 15 st := new(testMatcher) 16 17 st.skipShortMode(`^stQuadraticComplexityTest/`) 18 19 st.skipLoad(`^stTransactionTest/OverflowGasRequire\.json`) 20 st.skipLoad(`^stTransactionTest/zeroSigTransa[^/]*\.json`) 21 22 st.fails(`^stRevertTest/RevertPrecompiledTouch\.json/EIP158`, "bug in test") 23 st.fails(`^stRevertTest/RevertPrefoundEmptyOOG\.json/EIP158`, "bug in test") 24 st.fails(`^stRevertTest/RevertPrecompiledTouch\.json/Byzantium`, "bug in test") 25 st.fails(`^stRevertTest/RevertPrefoundEmptyOOG\.json/Byzantium`, "bug in test") 26 st.fails(`^stRandom2/randomStatetest64[45]\.json/(EIP150|Frontier|Homestead)/.*`, "known bug #15119") 27 st.fails(`^stCreateTest/TransactionCollisionToEmpty\.json/EIP158/2`, "known bug ") 28 st.fails(`^stCreateTest/TransactionCollisionToEmpty\.json/EIP158/3`, "known bug ") 29 st.fails(`^stCreateTest/TransactionCollisionToEmpty\.json/Byzantium/2`, "known bug ") 30 st.fails(`^stCreateTest/TransactionCollisionToEmpty\.json/Byzantium/3`, "known bug ") 31 32 st.walk(t, stateTestDir, func(t *testing.T, name string, test *StateTest) { 33 for _, subtest := range test.Subtests() { 34 subtest := subtest 35 key := fmt.Sprintf("%s/%d", subtest.Fork, subtest.Index) 36 name := name + "/" + key 37 t.Run(key, func(t *testing.T) { 38 if subtest.Fork == "Constantinople" { 39 t.Skip("constantinople not supported yet") 40 } 41 withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error { 42 _, err := test.Run(subtest, vmconfig) 43 return st.checkFailure(t, name, err) 44 }) 45 }) 46 } 47 }) 48 } 49 50 const traceErrorLimit = 400000 51 52 func withTrace(t *testing.T, gasLimit uint64, test func(vm.Config) error) { 53 err := test(vm.Config{}) 54 if err == nil { 55 return 56 } 57 t.Error(err) 58 if gasLimit > traceErrorLimit { 59 t.Log("gas limit too high for EVM trace") 60 return 61 } 62 tracer := vm.NewStructLogger(nil) 63 err2 := test(vm.Config{Debug: true, Tracer: tracer}) 64 if !reflect.DeepEqual(err, err2) { 65 t.Errorf("different error for second run: %v", err2) 66 } 67 buf := new(bytes.Buffer) 68 vm.WriteTrace(buf, tracer.StructLogs()) 69 if buf.Len() == 0 { 70 t.Log("no EVM operation logs generated") 71 } else { 72 t.Log("EVM operation log:\n" + buf.String()) 73 } 74 t.Logf("EVM output: 0x%x", tracer.Output()) 75 t.Logf("EVM error: %v", tracer.Error()) 76 }