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