init.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Copyright 2014 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum 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. // go-ethereum 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 go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  16. package tests
  17. import (
  18. "encoding/json"
  19. "fmt"
  20. "io"
  21. "io/ioutil"
  22. "net/http"
  23. "os"
  24. "path/filepath"
  25. "github.com/ethereum/go-ethereum/core"
  26. )
  27. var (
  28. baseDir = filepath.Join(".", "files")
  29. blockTestDir = filepath.Join(baseDir, "BlockchainTests")
  30. stateTestDir = filepath.Join(baseDir, "StateTests")
  31. transactionTestDir = filepath.Join(baseDir, "TransactionTests")
  32. vmTestDir = filepath.Join(baseDir, "VMTests")
  33. BlockSkipTests = []string{
  34. // Fails in InsertPreState with: computed state root does not
  35. // match genesis block bba25a96 0d8f85c8 Christoph said it will be
  36. // fixed eventually
  37. "SimpleTx3",
  38. // These tests are not valid, as they are out of scope for RLP and
  39. // the consensus protocol.
  40. "BLOCK__RandomByteAtTheEnd",
  41. "TRANSCT__RandomByteAtTheEnd",
  42. "BLOCK__ZeroByteAtTheEnd",
  43. "TRANSCT__ZeroByteAtTheEnd",
  44. }
  45. /* Go does not support transaction (account) nonces above 2^64. This
  46. technically breaks consensus but is regarded as "reasonable
  47. engineering constraint" as accounts cannot easily reach such high
  48. nonce values in practice
  49. */
  50. TransSkipTests = []string{"TransactionWithHihghNonce256"}
  51. StateSkipTests = []string{}
  52. VmSkipTests = []string{}
  53. )
  54. func readJson(reader io.Reader, value interface{}) error {
  55. data, err := ioutil.ReadAll(reader)
  56. if err != nil {
  57. return fmt.Errorf("Error reading JSON file", err.Error())
  58. }
  59. core.DisableBadBlockReporting = true
  60. if err = json.Unmarshal(data, &value); err != nil {
  61. if syntaxerr, ok := err.(*json.SyntaxError); ok {
  62. line := findLine(data, syntaxerr.Offset)
  63. return fmt.Errorf("JSON syntax error at line %v: %v", line, err)
  64. }
  65. return fmt.Errorf("JSON unmarshal error: %v", err)
  66. }
  67. return nil
  68. }
  69. func readJsonHttp(uri string, value interface{}) error {
  70. resp, err := http.Get(uri)
  71. if err != nil {
  72. return err
  73. }
  74. defer resp.Body.Close()
  75. err = readJson(resp.Body, value)
  76. if err != nil {
  77. return err
  78. }
  79. return nil
  80. }
  81. func readJsonFile(fn string, value interface{}) error {
  82. file, err := os.Open(fn)
  83. if err != nil {
  84. return err
  85. }
  86. defer file.Close()
  87. err = readJson(file, value)
  88. if err != nil {
  89. return fmt.Errorf("%s in file %s", err.Error(), fn)
  90. }
  91. return nil
  92. }
  93. // findLine returns the line number for the given offset into data.
  94. func findLine(data []byte, offset int64) (line int) {
  95. line = 1
  96. for i, r := range string(data) {
  97. if int64(i) >= offset {
  98. return
  99. }
  100. if r == '\n' {
  101. line++
  102. }
  103. }
  104. return
  105. }