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