github.com/ethereum/go-ethereum@v1.16.1/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  	}
    55  )
    56  
    57  func TestDifficulty(t *testing.T) {
    58  	t.Parallel()
    59  
    60  	dt := new(testMatcher)
    61  	// Not difficulty-tests
    62  	dt.skipLoad("hexencodetest.*")
    63  	dt.skipLoad("crypto.*")
    64  	dt.skipLoad("blockgenesistest\\.json")
    65  	dt.skipLoad("genesishashestest\\.json")
    66  	dt.skipLoad("keyaddrtest\\.json")
    67  	dt.skipLoad("txtest\\.json")
    68  
    69  	// files are 2 years old, contains strange values
    70  	dt.skipLoad("difficultyCustomHomestead\\.json")
    71  
    72  	dt.config("Ropsten", ropstenChainConfig)
    73  	dt.config("Frontier", params.ChainConfig{})
    74  
    75  	dt.config("Homestead", params.ChainConfig{
    76  		HomesteadBlock: big.NewInt(0),
    77  	})
    78  
    79  	dt.config("Byzantium", params.ChainConfig{
    80  		ByzantiumBlock: big.NewInt(0),
    81  	})
    82  
    83  	dt.config("Frontier", ropstenChainConfig)
    84  	dt.config("MainNetwork", mainnetChainConfig)
    85  	dt.config("CustomMainNetwork", mainnetChainConfig)
    86  	dt.config("Constantinople", params.ChainConfig{
    87  		ConstantinopleBlock: big.NewInt(0),
    88  	})
    89  	dt.config("EIP2384", params.ChainConfig{
    90  		MuirGlacierBlock: big.NewInt(0),
    91  	})
    92  	dt.config("EIP4345", params.ChainConfig{
    93  		ArrowGlacierBlock: big.NewInt(0),
    94  	})
    95  	dt.config("EIP5133", params.ChainConfig{
    96  		GrayGlacierBlock: big.NewInt(0),
    97  	})
    98  	dt.config("difficulty.json", mainnetChainConfig)
    99  
   100  	dt.walk(t, difficultyTestDir, func(t *testing.T, name string, test *DifficultyTest) {
   101  		cfg := dt.findConfig(t)
   102  		if test.ParentDifficulty.Cmp(params.MinimumDifficulty) < 0 {
   103  			t.Skip("difficulty below minimum")
   104  			return
   105  		}
   106  		if err := dt.checkFailure(t, test.Run(cfg)); err != nil {
   107  			t.Error(err)
   108  		}
   109  	})
   110  }