github.com/jimmyx0x/go-ethereum@v1.10.28/tests/difficulty_test.go (about) 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 19 import ( 20 "math/big" 21 "testing" 22 23 "github.com/ethereum/go-ethereum/common" 24 "github.com/ethereum/go-ethereum/params" 25 ) 26 27 var ( 28 mainnetChainConfig = params.ChainConfig{ 29 ChainID: big.NewInt(1), 30 HomesteadBlock: big.NewInt(1150000), 31 DAOForkBlock: big.NewInt(1920000), 32 DAOForkSupport: true, 33 EIP150Block: big.NewInt(2463000), 34 EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"), 35 EIP155Block: big.NewInt(2675000), 36 EIP158Block: big.NewInt(2675000), 37 ByzantiumBlock: big.NewInt(4370000), 38 } 39 ) 40 41 func TestDifficulty(t *testing.T) { 42 t.Parallel() 43 44 dt := new(testMatcher) 45 // Not difficulty-tests 46 dt.skipLoad("hexencodetest.*") 47 dt.skipLoad("crypto.*") 48 dt.skipLoad("blockgenesistest\\.json") 49 dt.skipLoad("genesishashestest\\.json") 50 dt.skipLoad("keyaddrtest\\.json") 51 dt.skipLoad("txtest\\.json") 52 53 // files are 2 years old, contains strange values 54 dt.skipLoad("difficultyCustomHomestead\\.json") 55 56 dt.config("Ropsten", *params.RopstenChainConfig) 57 dt.config("Frontier", params.ChainConfig{}) 58 59 dt.config("Homestead", params.ChainConfig{ 60 HomesteadBlock: big.NewInt(0), 61 }) 62 63 dt.config("Byzantium", params.ChainConfig{ 64 ByzantiumBlock: big.NewInt(0), 65 }) 66 67 dt.config("Frontier", *params.RopstenChainConfig) 68 dt.config("MainNetwork", mainnetChainConfig) 69 dt.config("CustomMainNetwork", mainnetChainConfig) 70 dt.config("Constantinople", params.ChainConfig{ 71 ConstantinopleBlock: big.NewInt(0), 72 }) 73 dt.config("EIP2384", params.ChainConfig{ 74 MuirGlacierBlock: big.NewInt(0), 75 }) 76 dt.config("EIP4345", params.ChainConfig{ 77 ArrowGlacierBlock: big.NewInt(0), 78 }) 79 dt.config("EIP5133", params.ChainConfig{ 80 GrayGlacierBlock: big.NewInt(0), 81 }) 82 dt.config("difficulty.json", mainnetChainConfig) 83 84 dt.walk(t, difficultyTestDir, func(t *testing.T, name string, test *DifficultyTest) { 85 cfg := dt.findConfig(t) 86 if test.ParentDifficulty.Cmp(params.MinimumDifficulty) < 0 { 87 t.Skip("difficulty below minimum") 88 return 89 } 90 if err := dt.checkFailure(t, test.Run(cfg)); err != nil { 91 t.Error(err) 92 } 93 }) 94 }