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