github.com/electroneum/electroneum-sc@v0.0.0-20230105223411-3bc1d078281e/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/electroneum/electroneum-sc/common" 24 "github.com/electroneum/electroneum-sc/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 ropstenChainConfig = params.ChainConfig{ 41 ChainID: big.NewInt(3), 42 HomesteadBlock: big.NewInt(0), 43 DAOForkBlock: nil, 44 DAOForkSupport: true, 45 EIP150Block: big.NewInt(0), 46 EIP150Hash: common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d"), 47 EIP155Block: big.NewInt(10), 48 EIP158Block: big.NewInt(10), 49 ByzantiumBlock: big.NewInt(1_700_000), 50 ConstantinopleBlock: big.NewInt(4_230_000), 51 PetersburgBlock: big.NewInt(4_939_394), 52 IstanbulBlock: big.NewInt(6_485_846), 53 MuirGlacierBlock: big.NewInt(7_117_117), 54 BerlinBlock: big.NewInt(9_812_189), 55 LondonBlock: big.NewInt(10_499_401), 56 TerminalTotalDifficulty: big.NewInt(43531756765713534), 57 } 58 ) 59 60 func TestDifficulty(t *testing.T) { 61 t.Parallel() 62 63 dt := new(testMatcher) 64 // Not difficulty-tests 65 dt.skipLoad("hexencodetest.*") 66 dt.skipLoad("crypto.*") 67 dt.skipLoad("blockgenesistest\\.json") 68 dt.skipLoad("genesishashestest\\.json") 69 dt.skipLoad("keyaddrtest\\.json") 70 dt.skipLoad("txtest\\.json") 71 72 // files are 2 years old, contains strange values 73 dt.skipLoad("difficultyCustomHomestead\\.json") 74 dt.skipLoad("difficultyMorden\\.json") 75 dt.skipLoad("difficultyOlimpic\\.json") 76 77 dt.config("Ropsten", ropstenChainConfig) 78 dt.config("Morden", ropstenChainConfig) 79 dt.config("Frontier", params.ChainConfig{}) 80 81 dt.config("Homestead", params.ChainConfig{ 82 HomesteadBlock: big.NewInt(0), 83 }) 84 85 dt.config("Byzantium", params.ChainConfig{ 86 ByzantiumBlock: big.NewInt(0), 87 }) 88 89 dt.config("Frontier", ropstenChainConfig) 90 dt.config("MainNetwork", mainnetChainConfig) 91 dt.config("CustomMainNetwork", mainnetChainConfig) 92 dt.config("Constantinople", params.ChainConfig{ 93 ConstantinopleBlock: big.NewInt(0), 94 }) 95 dt.config("EIP2384", params.ChainConfig{ 96 MuirGlacierBlock: big.NewInt(0), 97 }) 98 dt.config("EIP4345", params.ChainConfig{ 99 ArrowGlacierBlock: big.NewInt(0), 100 }) 101 dt.config("difficulty.json", mainnetChainConfig) 102 103 dt.walk(t, difficultyTestDir, func(t *testing.T, name string, test *DifficultyTest) { 104 cfg := dt.findConfig(t) 105 if test.ParentDifficulty.Cmp(params.MinimumDifficulty) < 0 { 106 t.Skip("difficulty below minimum") 107 return 108 } 109 if err := dt.checkFailure(t, test.Run(cfg)); err != nil { 110 t.Error(err) 111 } 112 }) 113 }