state_test.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. 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(`^stRevertTest/RevertPrecompiledTouch\.json/EIP158`, "bug in test")
  34. st.fails(`^stRevertTest/RevertPrefoundEmptyOOG\.json/EIP158`, "bug in test")
  35. st.fails(`^stRevertTest/RevertPrecompiledTouch\.json/Byzantium`, "bug in test")
  36. st.fails(`^stRevertTest/RevertPrefoundEmptyOOG\.json/Byzantium`, "bug in test")
  37. st.fails(`^stRandom2/randomStatetest64[45]\.json/(EIP150|Frontier|Homestead)/.*`, "known bug #15119")
  38. st.fails(`^stCreateTest/TransactionCollisionToEmpty\.json/EIP158/2`, "known bug ")
  39. st.fails(`^stCreateTest/TransactionCollisionToEmpty\.json/EIP158/3`, "known bug ")
  40. st.fails(`^stCreateTest/TransactionCollisionToEmpty\.json/Byzantium/2`, "known bug ")
  41. st.fails(`^stCreateTest/TransactionCollisionToEmpty\.json/Byzantium/3`, "known bug ")
  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. // Transactions with gasLimit above this value will not get a VM trace on failure.
  60. const traceErrorLimit = 400000
  61. func withTrace(t *testing.T, gasLimit uint64, test func(vm.Config) error) {
  62. err := test(vm.Config{})
  63. if err == nil {
  64. return
  65. }
  66. t.Error(err)
  67. if gasLimit > traceErrorLimit {
  68. t.Log("gas limit too high for EVM trace")
  69. return
  70. }
  71. tracer := vm.NewStructLogger(nil)
  72. err2 := test(vm.Config{Debug: true, Tracer: tracer})
  73. if !reflect.DeepEqual(err, err2) {
  74. t.Errorf("different error for second run: %v", err2)
  75. }
  76. buf := new(bytes.Buffer)
  77. vm.WriteTrace(buf, tracer.StructLogs())
  78. if buf.Len() == 0 {
  79. t.Log("no EVM operation logs generated")
  80. } else {
  81. t.Log("EVM operation log:\n" + buf.String())
  82. }
  83. t.Logf("EVM output: 0x%x", tracer.Output())
  84. t.Logf("EVM error: %v", tracer.Error())
  85. }