github.com/ethereumproject/go-ethereum@v5.5.2+incompatible/tests/state_test.go (about) 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 17 package tests 18 19 import ( 20 "math/big" 21 "os" 22 "path/filepath" 23 "testing" 24 ) 25 26 func BenchmarkStateCall1024(b *testing.B) { 27 fn := filepath.Join(stateTestDir, "stCallCreateCallCodeTest.json") 28 if err := BenchVmTest(fn, bconf{"Call1024BalanceTooLow", true, os.Getenv("JITVM") == "true"}, b); err != nil { 29 b.Error(err) 30 } 31 } 32 33 func TestStateSystemOperations(t *testing.T) { 34 ruleSet := RuleSet{ 35 HomesteadBlock: big.NewInt(1000000), 36 } 37 38 fn := filepath.Join(stateTestDir, "stSystemOperationsTest.json") 39 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 40 t.Error(err) 41 } 42 } 43 44 func TestStateExample(t *testing.T) { 45 ruleSet := RuleSet{ 46 HomesteadBlock: big.NewInt(1000000), 47 } 48 49 fn := filepath.Join(stateTestDir, "stExample.json") 50 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 51 t.Error(err) 52 } 53 } 54 55 func TestStatePreCompiledContracts(t *testing.T) { 56 ruleSet := RuleSet{ 57 HomesteadBlock: big.NewInt(1000000), 58 } 59 60 fn := filepath.Join(stateTestDir, "stPreCompiledContracts.json") 61 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 62 t.Error(err) 63 } 64 } 65 66 func TestStateRecursiveCreate(t *testing.T) { 67 ruleSet := RuleSet{ 68 HomesteadBlock: big.NewInt(1000000), 69 } 70 71 fn := filepath.Join(stateTestDir, "stRecursiveCreate.json") 72 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 73 t.Error(err) 74 } 75 } 76 77 func TestStateSpecial(t *testing.T) { 78 ruleSet := RuleSet{ 79 HomesteadBlock: big.NewInt(1000000), 80 } 81 82 fn := filepath.Join(stateTestDir, "stSpecialTest.json") 83 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 84 t.Error(err) 85 } 86 } 87 88 func TestStateRefund(t *testing.T) { 89 ruleSet := RuleSet{ 90 HomesteadBlock: big.NewInt(1000000), 91 } 92 93 fn := filepath.Join(stateTestDir, "stRefundTest.json") 94 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 95 t.Error(err) 96 } 97 } 98 99 func TestStateBlockHash(t *testing.T) { 100 ruleSet := RuleSet{ 101 HomesteadBlock: big.NewInt(1000000), 102 } 103 104 fn := filepath.Join(stateTestDir, "stBlockHashTest.json") 105 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 106 t.Error(err) 107 } 108 } 109 110 func TestStateInitCode(t *testing.T) { 111 ruleSet := RuleSet{ 112 HomesteadBlock: big.NewInt(1000000), 113 } 114 115 fn := filepath.Join(stateTestDir, "stInitCodeTest.json") 116 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 117 t.Error(err) 118 } 119 } 120 121 func TestStateLog(t *testing.T) { 122 ruleSet := RuleSet{ 123 HomesteadBlock: big.NewInt(1000000), 124 } 125 126 fn := filepath.Join(stateTestDir, "stLogTests.json") 127 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 128 t.Error(err) 129 } 130 } 131 132 func TestStateTransaction(t *testing.T) { 133 ruleSet := RuleSet{ 134 HomesteadBlock: big.NewInt(1000000), 135 } 136 137 fn := filepath.Join(stateTestDir, "stTransactionTest.json") 138 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 139 t.Error(err) 140 } 141 } 142 143 func TestStateTransition(t *testing.T) { 144 ruleSet := RuleSet{ 145 HomesteadBlock: big.NewInt(1000000), 146 } 147 148 fn := filepath.Join(stateTestDir, "stTransitionTest.json") 149 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 150 t.Error(err) 151 } 152 } 153 154 func TestCallCreateCallCode(t *testing.T) { 155 ruleSet := RuleSet{ 156 HomesteadBlock: big.NewInt(1000000), 157 } 158 159 fn := filepath.Join(stateTestDir, "stCallCreateCallCodeTest.json") 160 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 161 t.Error(err) 162 } 163 } 164 165 func TestCallCodes(t *testing.T) { 166 ruleSet := RuleSet{ 167 HomesteadBlock: big.NewInt(1000000), 168 } 169 170 fn := filepath.Join(stateTestDir, "stCallCodes.json") 171 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 172 t.Error(err) 173 } 174 } 175 176 func TestDelegateCall(t *testing.T) { 177 ruleSet := RuleSet{ 178 HomesteadBlock: big.NewInt(1000000), 179 } 180 181 fn := filepath.Join(stateTestDir, "stDelegatecallTest.json") 182 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 183 t.Error(err) 184 } 185 } 186 187 func TestMemory(t *testing.T) { 188 ruleSet := RuleSet{ 189 HomesteadBlock: big.NewInt(1000000), 190 } 191 192 fn := filepath.Join(stateTestDir, "stMemoryTest.json") 193 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 194 t.Error(err) 195 } 196 } 197 198 func TestMemoryStress(t *testing.T) { 199 ruleSet := RuleSet{ 200 HomesteadBlock: big.NewInt(1000000), 201 } 202 203 if os.Getenv("TEST_VM_COMPLEX") == "" { 204 t.Skip() 205 } 206 fn := filepath.Join(stateTestDir, "stMemoryStressTest.json") 207 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 208 t.Error(err) 209 } 210 } 211 212 func TestQuadraticComplexity(t *testing.T) { 213 ruleSet := RuleSet{ 214 HomesteadBlock: big.NewInt(1000000), 215 } 216 217 if os.Getenv("TEST_VM_COMPLEX") == "" { 218 t.Skip() 219 } 220 fn := filepath.Join(stateTestDir, "stQuadraticComplexityTest.json") 221 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 222 t.Error(err) 223 } 224 } 225 226 func TestSolidity(t *testing.T) { 227 ruleSet := RuleSet{ 228 HomesteadBlock: big.NewInt(1000000), 229 } 230 231 fn := filepath.Join(stateTestDir, "stSolidityTest.json") 232 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 233 t.Error(err) 234 } 235 } 236 237 func TestWallet(t *testing.T) { 238 ruleSet := RuleSet{ 239 HomesteadBlock: big.NewInt(1000000), 240 } 241 242 fn := filepath.Join(stateTestDir, "stWalletTest.json") 243 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 244 t.Error(err) 245 } 246 } 247 248 func TestStateTestsRandom(t *testing.T) { 249 ruleSet := RuleSet{ 250 HomesteadBlock: big.NewInt(1000000), 251 } 252 253 fns, _ := filepath.Glob("./files/StateTests/RandomTests/*") 254 for _, fn := range fns { 255 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 256 t.Error(err) 257 } 258 } 259 } 260 261 // homestead tests 262 func TestHomesteadStateSystemOperations(t *testing.T) { 263 ruleSet := RuleSet{ 264 HomesteadBlock: new(big.Int), 265 } 266 267 fn := filepath.Join(stateTestDir, "Homestead", "stSystemOperationsTest.json") 268 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 269 t.Error(err) 270 } 271 } 272 273 func TestHomesteadStatePreCompiledContracts(t *testing.T) { 274 ruleSet := RuleSet{ 275 HomesteadBlock: new(big.Int), 276 } 277 278 fn := filepath.Join(stateTestDir, "Homestead", "stPreCompiledContracts.json") 279 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 280 t.Error(err) 281 } 282 } 283 284 func TestHomesteadStateRecursiveCreate(t *testing.T) { 285 ruleSet := RuleSet{ 286 HomesteadBlock: new(big.Int), 287 } 288 289 fn := filepath.Join(stateTestDir, "Homestead", "stSpecialTest.json") 290 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 291 t.Error(err) 292 } 293 } 294 295 func TestHomesteadStateRefund(t *testing.T) { 296 ruleSet := RuleSet{ 297 HomesteadBlock: new(big.Int), 298 } 299 300 fn := filepath.Join(stateTestDir, "Homestead", "stRefundTest.json") 301 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 302 t.Error(err) 303 } 304 } 305 306 func TestHomesteadStateInitCode(t *testing.T) { 307 ruleSet := RuleSet{ 308 HomesteadBlock: new(big.Int), 309 } 310 311 fn := filepath.Join(stateTestDir, "Homestead", "stInitCodeTest.json") 312 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 313 t.Error(err) 314 } 315 } 316 317 func TestHomesteadStateLog(t *testing.T) { 318 ruleSet := RuleSet{ 319 HomesteadBlock: new(big.Int), 320 } 321 322 fn := filepath.Join(stateTestDir, "Homestead", "stLogTests.json") 323 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 324 t.Error(err) 325 } 326 } 327 328 func TestHomesteadStateTransaction(t *testing.T) { 329 ruleSet := RuleSet{ 330 HomesteadBlock: new(big.Int), 331 } 332 333 fn := filepath.Join(stateTestDir, "Homestead", "stTransactionTest.json") 334 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 335 t.Error(err) 336 } 337 } 338 339 func TestHomesteadCallCreateCallCode(t *testing.T) { 340 ruleSet := RuleSet{ 341 HomesteadBlock: new(big.Int), 342 } 343 344 fn := filepath.Join(stateTestDir, "Homestead", "stCallCreateCallCodeTest.json") 345 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 346 t.Error(err) 347 } 348 } 349 350 func TestHomesteadCallCodes(t *testing.T) { 351 ruleSet := RuleSet{ 352 HomesteadBlock: new(big.Int), 353 } 354 355 fn := filepath.Join(stateTestDir, "Homestead", "stCallCodes.json") 356 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 357 t.Error(err) 358 } 359 } 360 361 func TestHomesteadMemory(t *testing.T) { 362 ruleSet := RuleSet{ 363 HomesteadBlock: new(big.Int), 364 } 365 366 fn := filepath.Join(stateTestDir, "Homestead", "stMemoryTest.json") 367 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 368 t.Error(err) 369 } 370 } 371 372 func TestHomesteadMemoryStress(t *testing.T) { 373 ruleSet := RuleSet{ 374 HomesteadBlock: new(big.Int), 375 } 376 377 if os.Getenv("TEST_VM_COMPLEX") == "" { 378 t.Skip() 379 } 380 fn := filepath.Join(stateTestDir, "Homestead", "stMemoryStressTest.json") 381 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 382 t.Error(err) 383 } 384 } 385 386 func TestHomesteadQuadraticComplexity(t *testing.T) { 387 ruleSet := RuleSet{ 388 HomesteadBlock: new(big.Int), 389 } 390 391 if os.Getenv("TEST_VM_COMPLEX") == "" { 392 t.Skip() 393 } 394 fn := filepath.Join(stateTestDir, "Homestead", "stQuadraticComplexityTest.json") 395 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 396 t.Error(err) 397 } 398 } 399 400 func TestHomesteadWallet(t *testing.T) { 401 ruleSet := RuleSet{ 402 HomesteadBlock: new(big.Int), 403 } 404 405 fn := filepath.Join(stateTestDir, "Homestead", "stWalletTest.json") 406 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 407 t.Error(err) 408 } 409 } 410 411 func TestHomesteadDelegateCodes(t *testing.T) { 412 ruleSet := RuleSet{ 413 HomesteadBlock: new(big.Int), 414 } 415 416 fn := filepath.Join(stateTestDir, "Homestead", "stCallDelegateCodes.json") 417 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 418 t.Error(err) 419 } 420 } 421 422 func TestHomesteadDelegateCodesCallCode(t *testing.T) { 423 ruleSet := RuleSet{ 424 HomesteadBlock: new(big.Int), 425 } 426 427 fn := filepath.Join(stateTestDir, "Homestead", "stCallDelegateCodesCallCode.json") 428 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 429 t.Error(err) 430 } 431 } 432 433 // EIP150 tests 434 func TestEIP150Specific(t *testing.T) { 435 ruleSet := RuleSet{ 436 HomesteadBlock: new(big.Int), 437 HomesteadGasRepriceBlock: big.NewInt(2457000), 438 } 439 440 fn := filepath.Join(stateTestDir, "EIP150", "stEIPSpecificTest.json") 441 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 442 t.Error(err) 443 } 444 } 445 446 func TestEIP150SingleCodeGasPrice(t *testing.T) { 447 ruleSet := RuleSet{ 448 HomesteadBlock: new(big.Int), 449 HomesteadGasRepriceBlock: big.NewInt(2457000), 450 } 451 452 fn := filepath.Join(stateTestDir, "EIP150", "stEIPSingleCodeGasPrices.json") 453 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 454 t.Error(err) 455 } 456 } 457 458 func TestEIP150MemExpandingCalls(t *testing.T) { 459 ruleSet := RuleSet{ 460 HomesteadBlock: new(big.Int), 461 HomesteadGasRepriceBlock: big.NewInt(2457000), 462 } 463 464 fn := filepath.Join(stateTestDir, "EIP150", "stMemExpandingEIPCalls.json") 465 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 466 t.Error(err) 467 } 468 } 469 470 func TestEIP150HomesteadStateSystemOperations(t *testing.T) { 471 ruleSet := RuleSet{ 472 HomesteadBlock: new(big.Int), 473 HomesteadGasRepriceBlock: big.NewInt(2457000), 474 } 475 476 fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stSystemOperationsTest.json") 477 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 478 t.Error(err) 479 } 480 } 481 482 func TestEIP150HomesteadStatePreCompiledContracts(t *testing.T) { 483 ruleSet := RuleSet{ 484 HomesteadBlock: new(big.Int), 485 HomesteadGasRepriceBlock: big.NewInt(1457000), 486 DiehardBlock: big.NewInt(2457000), 487 } 488 489 fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stPreCompiledContracts.json") 490 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 491 t.Error(err) 492 } 493 } 494 495 func TestEIP150HomesteadStateRecursiveCreate(t *testing.T) { 496 ruleSet := RuleSet{ 497 HomesteadBlock: new(big.Int), 498 HomesteadGasRepriceBlock: big.NewInt(2457000), 499 } 500 501 fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stSpecialTest.json") 502 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 503 t.Error(err) 504 } 505 } 506 507 func TestEIP150HomesteadStateRefund(t *testing.T) { 508 ruleSet := RuleSet{ 509 HomesteadBlock: new(big.Int), 510 HomesteadGasRepriceBlock: big.NewInt(1457000), 511 DiehardBlock: big.NewInt(2457000), 512 } 513 514 fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stRefundTest.json") 515 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 516 t.Error(err) 517 } 518 } 519 520 func TestEIP150HomesteadStateInitCode(t *testing.T) { 521 ruleSet := RuleSet{ 522 HomesteadBlock: new(big.Int), 523 HomesteadGasRepriceBlock: big.NewInt(2457000), 524 } 525 526 fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stInitCodeTest.json") 527 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 528 t.Error(err) 529 } 530 } 531 532 func TestEIP150HomesteadStateLog(t *testing.T) { 533 ruleSet := RuleSet{ 534 HomesteadBlock: new(big.Int), 535 HomesteadGasRepriceBlock: big.NewInt(2457000), 536 } 537 538 fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stLogTests.json") 539 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 540 t.Error(err) 541 } 542 } 543 544 func TestEIP150HomesteadStateTransaction(t *testing.T) { 545 ruleSet := RuleSet{ 546 HomesteadBlock: new(big.Int), 547 HomesteadGasRepriceBlock: big.NewInt(2457000), 548 } 549 550 fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stTransactionTest.json") 551 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 552 t.Error(err) 553 } 554 } 555 556 func TestEIP150HomesteadCallCreateCallCode(t *testing.T) { 557 ruleSet := RuleSet{ 558 HomesteadBlock: new(big.Int), 559 HomesteadGasRepriceBlock: big.NewInt(2457000), 560 } 561 562 fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stCallCreateCallCodeTest.json") 563 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 564 t.Error(err) 565 } 566 } 567 568 func TestEIP150HomesteadCallCodes(t *testing.T) { 569 ruleSet := RuleSet{ 570 HomesteadBlock: new(big.Int), 571 HomesteadGasRepriceBlock: big.NewInt(2457000), 572 } 573 574 fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stCallCodes.json") 575 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 576 t.Error(err) 577 } 578 } 579 580 func TestEIP150HomesteadMemory(t *testing.T) { 581 ruleSet := RuleSet{ 582 HomesteadBlock: new(big.Int), 583 HomesteadGasRepriceBlock: big.NewInt(2457000), 584 } 585 586 fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stMemoryTest.json") 587 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 588 t.Error(err) 589 } 590 } 591 592 func TestEIP150HomesteadMemoryStress(t *testing.T) { 593 ruleSet := RuleSet{ 594 HomesteadBlock: new(big.Int), 595 HomesteadGasRepriceBlock: big.NewInt(2457000), 596 } 597 598 if os.Getenv("TEST_VM_COMPLEX") == "" { 599 t.Skip() 600 } 601 fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stMemoryStressTest.json") 602 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 603 t.Error(err) 604 } 605 } 606 607 func TestEIP150HomesteadQuadraticComplexity(t *testing.T) { 608 ruleSet := RuleSet{ 609 HomesteadBlock: new(big.Int), 610 HomesteadGasRepriceBlock: big.NewInt(2457000), 611 } 612 613 if os.Getenv("TEST_VM_COMPLEX") == "" { 614 t.Skip() 615 } 616 fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stQuadraticComplexityTest.json") 617 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 618 t.Error(err) 619 } 620 } 621 622 func TestEIP150HomesteadWallet(t *testing.T) { 623 ruleSet := RuleSet{ 624 HomesteadBlock: new(big.Int), 625 HomesteadGasRepriceBlock: big.NewInt(1457000), 626 DiehardBlock: big.NewInt(2457000), 627 } 628 629 fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stWalletTest.json") 630 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 631 t.Error(err) 632 } 633 } 634 635 func TestEIP150HomesteadDelegateCodes(t *testing.T) { 636 ruleSet := RuleSet{ 637 HomesteadBlock: new(big.Int), 638 HomesteadGasRepriceBlock: big.NewInt(2457000), 639 } 640 641 fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stCallDelegateCodes.json") 642 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 643 t.Error(err) 644 } 645 } 646 647 func TestEIP150HomesteadDelegateCodesCallCode(t *testing.T) { 648 ruleSet := RuleSet{ 649 HomesteadBlock: new(big.Int), 650 HomesteadGasRepriceBlock: big.NewInt(2457000), 651 } 652 653 fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stCallDelegateCodesCallCode.json") 654 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 655 t.Error(err) 656 } 657 } 658 659 func TestEIP150HomesteadBounds(t *testing.T) { 660 ruleSet := RuleSet{ 661 HomesteadBlock: new(big.Int), 662 HomesteadGasRepriceBlock: big.NewInt(2457000), 663 } 664 665 fn := filepath.Join(stateTestDir, "EIP150", "Homestead", "stBoundsTest.json") 666 if err := RunStateTest(ruleSet, fn, StateSkipTests); err != nil { 667 t.Error(err) 668 } 669 }