state_test.go 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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. "math/big"
  19. "os"
  20. "path/filepath"
  21. "testing"
  22. "github.com/ethereum/go-ethereum/core/vm"
  23. "github.com/ethereum/go-ethereum/params"
  24. )
  25. func init() {
  26. if os.Getenv("JITVM") == "true" {
  27. vm.ForceJit = true
  28. vm.EnableJit = true
  29. }
  30. }
  31. func BenchmarkStateCall1024(b *testing.B) {
  32. fn := filepath.Join(stateTestDir, "stCallCreateCallCodeTest.json")
  33. if err := BenchVmTest(fn, bconf{"Call1024BalanceTooLow", true, os.Getenv("JITVM") == "true"}, b); err != nil {
  34. b.Error(err)
  35. }
  36. }
  37. func TestStateSystemOperations(t *testing.T) {
  38. params.HomesteadBlock = big.NewInt(1000000)
  39. fn := filepath.Join(stateTestDir, "stSystemOperationsTest.json")
  40. if err := RunStateTest(fn, StateSkipTests); err != nil {
  41. t.Error(err)
  42. }
  43. }
  44. func TestStateExample(t *testing.T) {
  45. params.HomesteadBlock = big.NewInt(1000000)
  46. fn := filepath.Join(stateTestDir, "stExample.json")
  47. if err := RunStateTest(fn, StateSkipTests); err != nil {
  48. t.Error(err)
  49. }
  50. }
  51. func TestStatePreCompiledContracts(t *testing.T) {
  52. params.HomesteadBlock = big.NewInt(1000000)
  53. fn := filepath.Join(stateTestDir, "stPreCompiledContracts.json")
  54. if err := RunStateTest(fn, StateSkipTests); err != nil {
  55. t.Error(err)
  56. }
  57. }
  58. func TestStateRecursiveCreate(t *testing.T) {
  59. params.HomesteadBlock = big.NewInt(1000000)
  60. fn := filepath.Join(stateTestDir, "stRecursiveCreate.json")
  61. if err := RunStateTest(fn, StateSkipTests); err != nil {
  62. t.Error(err)
  63. }
  64. }
  65. func TestStateSpecial(t *testing.T) {
  66. params.HomesteadBlock = big.NewInt(1000000)
  67. fn := filepath.Join(stateTestDir, "stSpecialTest.json")
  68. if err := RunStateTest(fn, StateSkipTests); err != nil {
  69. t.Error(err)
  70. }
  71. }
  72. func TestStateRefund(t *testing.T) {
  73. params.HomesteadBlock = big.NewInt(1000000)
  74. fn := filepath.Join(stateTestDir, "stRefundTest.json")
  75. if err := RunStateTest(fn, StateSkipTests); err != nil {
  76. t.Error(err)
  77. }
  78. }
  79. func TestStateBlockHash(t *testing.T) {
  80. params.HomesteadBlock = big.NewInt(1000000)
  81. fn := filepath.Join(stateTestDir, "stBlockHashTest.json")
  82. if err := RunStateTest(fn, StateSkipTests); err != nil {
  83. t.Error(err)
  84. }
  85. }
  86. func TestStateInitCode(t *testing.T) {
  87. params.HomesteadBlock = big.NewInt(1000000)
  88. fn := filepath.Join(stateTestDir, "stInitCodeTest.json")
  89. if err := RunStateTest(fn, StateSkipTests); err != nil {
  90. t.Error(err)
  91. }
  92. }
  93. func TestStateLog(t *testing.T) {
  94. params.HomesteadBlock = big.NewInt(1000000)
  95. fn := filepath.Join(stateTestDir, "stLogTests.json")
  96. if err := RunStateTest(fn, StateSkipTests); err != nil {
  97. t.Error(err)
  98. }
  99. }
  100. func TestStateTransaction(t *testing.T) {
  101. params.HomesteadBlock = big.NewInt(1000000)
  102. fn := filepath.Join(stateTestDir, "stTransactionTest.json")
  103. if err := RunStateTest(fn, StateSkipTests); err != nil {
  104. t.Error(err)
  105. }
  106. }
  107. func TestStateTransition(t *testing.T) {
  108. params.HomesteadBlock = big.NewInt(1000000)
  109. fn := filepath.Join(stateTestDir, "stTransitionTest.json")
  110. if err := RunStateTest(fn, StateSkipTests); err != nil {
  111. t.Error(err)
  112. }
  113. }
  114. func TestCallCreateCallCode(t *testing.T) {
  115. params.HomesteadBlock = big.NewInt(1000000)
  116. fn := filepath.Join(stateTestDir, "stCallCreateCallCodeTest.json")
  117. if err := RunStateTest(fn, StateSkipTests); err != nil {
  118. t.Error(err)
  119. }
  120. }
  121. func TestCallCodes(t *testing.T) {
  122. params.HomesteadBlock = big.NewInt(1000000)
  123. fn := filepath.Join(stateTestDir, "stCallCodes.json")
  124. if err := RunStateTest(fn, StateSkipTests); err != nil {
  125. t.Error(err)
  126. }
  127. }
  128. func TestDelegateCall(t *testing.T) {
  129. params.HomesteadBlock = big.NewInt(1000000)
  130. fn := filepath.Join(stateTestDir, "stDelegatecallTest.json")
  131. if err := RunStateTest(fn, StateSkipTests); err != nil {
  132. t.Error(err)
  133. }
  134. }
  135. func TestMemory(t *testing.T) {
  136. params.HomesteadBlock = big.NewInt(1000000)
  137. fn := filepath.Join(stateTestDir, "stMemoryTest.json")
  138. if err := RunStateTest(fn, StateSkipTests); err != nil {
  139. t.Error(err)
  140. }
  141. }
  142. func TestMemoryStress(t *testing.T) {
  143. params.HomesteadBlock = big.NewInt(1000000)
  144. if os.Getenv("TEST_VM_COMPLEX") == "" {
  145. t.Skip()
  146. }
  147. fn := filepath.Join(stateTestDir, "stMemoryStressTest.json")
  148. if err := RunStateTest(fn, StateSkipTests); err != nil {
  149. t.Error(err)
  150. }
  151. }
  152. func TestQuadraticComplexity(t *testing.T) {
  153. params.HomesteadBlock = big.NewInt(1000000)
  154. if os.Getenv("TEST_VM_COMPLEX") == "" {
  155. t.Skip()
  156. }
  157. fn := filepath.Join(stateTestDir, "stQuadraticComplexityTest.json")
  158. if err := RunStateTest(fn, StateSkipTests); err != nil {
  159. t.Error(err)
  160. }
  161. }
  162. func TestSolidity(t *testing.T) {
  163. params.HomesteadBlock = big.NewInt(1000000)
  164. fn := filepath.Join(stateTestDir, "stSolidityTest.json")
  165. if err := RunStateTest(fn, StateSkipTests); err != nil {
  166. t.Error(err)
  167. }
  168. }
  169. func TestWallet(t *testing.T) {
  170. params.HomesteadBlock = big.NewInt(1000000)
  171. fn := filepath.Join(stateTestDir, "stWalletTest.json")
  172. if err := RunStateTest(fn, StateSkipTests); err != nil {
  173. t.Error(err)
  174. }
  175. }
  176. func TestStateTestsRandom(t *testing.T) {
  177. params.HomesteadBlock = big.NewInt(1000000)
  178. fns, _ := filepath.Glob("./files/StateTests/RandomTests/*")
  179. for _, fn := range fns {
  180. if err := RunStateTest(fn, StateSkipTests); err != nil {
  181. t.Error(err)
  182. }
  183. }
  184. }
  185. // homestead tests
  186. func TestHomesteadStateSystemOperations(t *testing.T) {
  187. params.HomesteadBlock = big.NewInt(0)
  188. fn := filepath.Join(stateTestDir, "Homestead", "stSystemOperationsTest.json")
  189. if err := RunStateTest(fn, StateSkipTests); err != nil {
  190. t.Error(err)
  191. }
  192. }
  193. func TestHomesteadStatePreCompiledContracts(t *testing.T) {
  194. params.HomesteadBlock = big.NewInt(0)
  195. fn := filepath.Join(stateTestDir, "Homestead", "stPreCompiledContracts.json")
  196. if err := RunStateTest(fn, StateSkipTests); err != nil {
  197. t.Error(err)
  198. }
  199. }
  200. func TestHomesteadStateRecursiveCreate(t *testing.T) {
  201. params.HomesteadBlock = big.NewInt(0)
  202. fn := filepath.Join(stateTestDir, "Homestead", "stRecursiveCreate.json")
  203. if err := RunStateTest(fn, StateSkipTests); err != nil {
  204. t.Error(err)
  205. }
  206. }
  207. func TestHomesteadStateSpecial(t *testing.T) {
  208. params.HomesteadBlock = big.NewInt(0)
  209. fn := filepath.Join(stateTestDir, "Homestead", "stSpecialTest.json")
  210. if err := RunStateTest(fn, StateSkipTests); err != nil {
  211. t.Error(err)
  212. }
  213. }
  214. func TestHomesteadStateRefund(t *testing.T) {
  215. params.HomesteadBlock = big.NewInt(0)
  216. fn := filepath.Join(stateTestDir, "Homestead", "stRefundTest.json")
  217. if err := RunStateTest(fn, StateSkipTests); err != nil {
  218. t.Error(err)
  219. }
  220. }
  221. func TestHomesteadStateInitCode(t *testing.T) {
  222. params.HomesteadBlock = big.NewInt(0)
  223. fn := filepath.Join(stateTestDir, "Homestead", "stInitCodeTest.json")
  224. if err := RunStateTest(fn, StateSkipTests); err != nil {
  225. t.Error(err)
  226. }
  227. }
  228. func TestHomesteadStateLog(t *testing.T) {
  229. params.HomesteadBlock = big.NewInt(0)
  230. fn := filepath.Join(stateTestDir, "Homestead", "stLogTests.json")
  231. if err := RunStateTest(fn, StateSkipTests); err != nil {
  232. t.Error(err)
  233. }
  234. }
  235. func TestHomesteadStateTransaction(t *testing.T) {
  236. params.HomesteadBlock = big.NewInt(0)
  237. fn := filepath.Join(stateTestDir, "Homestead", "stTransactionTest.json")
  238. if err := RunStateTest(fn, StateSkipTests); err != nil {
  239. t.Error(err)
  240. }
  241. }
  242. func TestHomesteadCallCreateCallCode(t *testing.T) {
  243. params.HomesteadBlock = big.NewInt(0)
  244. fn := filepath.Join(stateTestDir, "Homestead", "stCallCreateCallCodeTest.json")
  245. if err := RunStateTest(fn, StateSkipTests); err != nil {
  246. t.Error(err)
  247. }
  248. }
  249. func TestHomesteadCallCodes(t *testing.T) {
  250. params.HomesteadBlock = big.NewInt(0)
  251. fn := filepath.Join(stateTestDir, "Homestead", "stCallCodes.json")
  252. if err := RunStateTest(fn, StateSkipTests); err != nil {
  253. t.Error(err)
  254. }
  255. }
  256. func TestHomesteadMemory(t *testing.T) {
  257. params.HomesteadBlock = big.NewInt(0)
  258. fn := filepath.Join(stateTestDir, "Homestead", "stMemoryTest.json")
  259. if err := RunStateTest(fn, StateSkipTests); err != nil {
  260. t.Error(err)
  261. }
  262. }
  263. func TestHomesteadMemoryStress(t *testing.T) {
  264. params.HomesteadBlock = big.NewInt(0)
  265. if os.Getenv("TEST_VM_COMPLEX") == "" {
  266. t.Skip()
  267. }
  268. fn := filepath.Join(stateTestDir, "Homestead", "stMemoryStressTest.json")
  269. if err := RunStateTest(fn, StateSkipTests); err != nil {
  270. t.Error(err)
  271. }
  272. }
  273. func TestHomesteadQuadraticComplexity(t *testing.T) {
  274. params.HomesteadBlock = big.NewInt(0)
  275. if os.Getenv("TEST_VM_COMPLEX") == "" {
  276. t.Skip()
  277. }
  278. fn := filepath.Join(stateTestDir, "Homestead", "stQuadraticComplexityTest.json")
  279. if err := RunStateTest(fn, StateSkipTests); err != nil {
  280. t.Error(err)
  281. }
  282. }
  283. func TestHomesteadWallet(t *testing.T) {
  284. params.HomesteadBlock = big.NewInt(0)
  285. fn := filepath.Join(stateTestDir, "Homestead", "stWalletTest.json")
  286. if err := RunStateTest(fn, StateSkipTests); err != nil {
  287. t.Error(err)
  288. }
  289. }
  290. func TestHomesteadDelegateCodes(t *testing.T) {
  291. params.HomesteadBlock = big.NewInt(0)
  292. fn := filepath.Join(stateTestDir, "Homestead", "stCallDelegateCodes.json")
  293. if err := RunStateTest(fn, StateSkipTests); err != nil {
  294. t.Error(err)
  295. }
  296. }
  297. func TestHomesteadDelegateCodesCallCode(t *testing.T) {
  298. params.HomesteadBlock = big.NewInt(0)
  299. fn := filepath.Join(stateTestDir, "Homestead", "stCallDelegateCodesCallCode.json")
  300. if err := RunStateTest(fn, StateSkipTests); err != nil {
  301. t.Error(err)
  302. }
  303. }