github.com/SmartMeshFoundation/Spectrum@v0.0.0-20220621030607-452a266fee1e/tests/difficulty_test.go (about) 1 // Copyright 2017 The Spectrum Authors 2 // This file is part of the Spectrum library. 3 // 4 // The Spectrum 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 Spectrum 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 Spectrum library. If not, see <http://www.gnu.org/licenses/>. 16 // 17 18 package tests 19 20 import ( 21 "testing" 22 23 "math/big" 24 25 "github.com/SmartMeshFoundation/Spectrum/common" 26 "github.com/SmartMeshFoundation/Spectrum/params" 27 ) 28 29 var ( 30 mainnetChainConfig = params.ChainConfig{ 31 ChainId: big.NewInt(1), 32 HomesteadBlock: big.NewInt(1150000), 33 DAOForkBlock: big.NewInt(1920000), 34 DAOForkSupport: true, 35 EIP150Block: big.NewInt(2463000), 36 EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"), 37 EIP155Block: big.NewInt(2675000), 38 EIP158Block: big.NewInt(2675000), 39 ByzantiumBlock: big.NewInt(4370000), 40 } 41 ) 42 43 func TestDifficulty(t *testing.T) { 44 t.Parallel() 45 46 dt := new(testMatcher) 47 // Not difficulty-tests 48 dt.skipLoad("hexencodetest.*") 49 dt.skipLoad("crypto.*") 50 dt.skipLoad("blockgenesistest\\.json") 51 dt.skipLoad("genesishashestest\\.json") 52 dt.skipLoad("keyaddrtest\\.json") 53 dt.skipLoad("txtest\\.json") 54 55 // files are 2 years old, contains strange values 56 dt.skipLoad("difficultyCustomHomestead\\.json") 57 dt.skipLoad("difficultyMorden\\.json") 58 dt.skipLoad("difficultyOlimpic\\.json") 59 60 dt.config("Ropsten", *params.TestnetChainConfig) 61 dt.config("Morden", *params.TestnetChainConfig) 62 dt.config("Frontier", params.ChainConfig{}) 63 64 dt.config("Homestead", params.ChainConfig{ 65 HomesteadBlock: big.NewInt(0), 66 }) 67 68 dt.config("Byzantium", params.ChainConfig{ 69 ByzantiumBlock: big.NewInt(0), 70 }) 71 72 dt.config("Frontier", *params.TestnetChainConfig) 73 dt.config("MainNetwork", mainnetChainConfig) 74 dt.config("CustomMainNetwork", mainnetChainConfig) 75 dt.config("difficulty.json", mainnetChainConfig) 76 77 dt.walk(t, difficultyTestDir, func(t *testing.T, name string, test *DifficultyTest) { 78 cfg := dt.findConfig(name) 79 if test.ParentDifficulty.Cmp(params.MinimumDifficulty) < 0 { 80 t.Skip("difficulty below minimum") 81 return 82 } 83 if err := dt.checkFailure(t, name, test.Run(cfg)); err != nil { 84 t.Error(err) 85 } 86 }) 87 }