state_test.go 3.1 KB

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