difficulty_test.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. "math/big"
  19. "testing"
  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.RopstenChainConfig)
  51. dt.config("Morden", *params.RopstenChainConfig)
  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.RopstenChainConfig)
  60. dt.config("MainNetwork", mainnetChainConfig)
  61. dt.config("CustomMainNetwork", mainnetChainConfig)
  62. dt.config("Constantinople", params.ChainConfig{
  63. ConstantinopleBlock: big.NewInt(0),
  64. })
  65. dt.config("EIP2384", params.ChainConfig{
  66. MuirGlacierBlock: big.NewInt(0),
  67. })
  68. dt.config("difficulty.json", mainnetChainConfig)
  69. dt.walk(t, difficultyTestDir, func(t *testing.T, name string, test *DifficultyTest) {
  70. cfg := dt.findConfig(name)
  71. if test.ParentDifficulty.Cmp(params.MinimumDifficulty) < 0 {
  72. t.Skip("difficulty below minimum")
  73. return
  74. }
  75. if err := dt.checkFailure(t, name, test.Run(cfg)); err != nil {
  76. t.Error(err)
  77. }
  78. })
  79. }