difficulty_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. //
  17. package tests
  18. import (
  19. "testing"
  20. "math/big"
  21. "github.com/ethereum/go-ethereum/common"
  22. "github.com/ethereum/go-ethereum/params"
  23. )
  24. var (
  25. mainnetChainConfig = params.ChainConfig{
  26. ChainId: big.NewInt(1),
  27. HomesteadBlock: big.NewInt(1150000),
  28. DAOForkBlock: big.NewInt(1920000),
  29. DAOForkSupport: true,
  30. EIP150Block: big.NewInt(2463000),
  31. EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"),
  32. EIP155Block: big.NewInt(2675000),
  33. EIP158Block: big.NewInt(2675000),
  34. ByzantiumBlock: big.NewInt(4370000),
  35. }
  36. )
  37. func TestDifficulty(t *testing.T) {
  38. t.Parallel()
  39. dt := new(testMatcher)
  40. // Not difficulty-tests
  41. dt.skipLoad("hexencodetest.*")
  42. dt.skipLoad("crypto.*")
  43. dt.skipLoad("blockgenesistest\\.json")
  44. dt.skipLoad("genesishashestest\\.json")
  45. dt.skipLoad("keyaddrtest\\.json")
  46. dt.skipLoad("txtest\\.json")
  47. // files are 2 years old, contains strange values
  48. dt.skipLoad("difficultyCustomHomestead\\.json")
  49. dt.skipLoad("difficultyMorden\\.json")
  50. dt.skipLoad("difficultyOlimpic\\.json")
  51. dt.config("Ropsten", *params.TestnetChainConfig)
  52. dt.config("Morden", *params.TestnetChainConfig)
  53. dt.config("Frontier", params.ChainConfig{})
  54. dt.config("Homestead", params.ChainConfig{
  55. HomesteadBlock: big.NewInt(0),
  56. })
  57. dt.config("Byzantium", params.ChainConfig{
  58. ByzantiumBlock: big.NewInt(0),
  59. })
  60. dt.config("Frontier", *params.TestnetChainConfig)
  61. dt.config("MainNetwork", mainnetChainConfig)
  62. dt.config("CustomMainNetwork", mainnetChainConfig)
  63. dt.config("difficulty.json", mainnetChainConfig)
  64. dt.walk(t, difficultyTestDir, func(t *testing.T, name string, test *DifficultyTest) {
  65. cfg := dt.findConfig(name)
  66. if test.ParentDifficulty.Cmp(params.MinimumDifficulty) < 0 {
  67. t.Skip("difficulty below minimum")
  68. return
  69. }
  70. if err := dt.checkFailure(t, name, test.Run(cfg)); err != nil {
  71. t.Error(err)
  72. }
  73. })
  74. }