github.com/palisadeinc/bor@v0.0.0-20230615125219-ab7196213d15/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  //go:build integration
    18  // +build integration
    19  
    20  package tests
    21  
    22  import (
    23  	"math/big"
    24  	"testing"
    25  
    26  	"github.com/ethereum/go-ethereum/common"
    27  	"github.com/ethereum/go-ethereum/params"
    28  )
    29  
    30  var (
    31  	mainnetChainConfig = params.ChainConfig{
    32  		ChainID:        big.NewInt(1),
    33  		HomesteadBlock: big.NewInt(1150000),
    34  		DAOForkBlock:   big.NewInt(1920000),
    35  		DAOForkSupport: true,
    36  		EIP150Block:    big.NewInt(2463000),
    37  		EIP150Hash:     common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"),
    38  		EIP155Block:    big.NewInt(2675000),
    39  		EIP158Block:    big.NewInt(2675000),
    40  		ByzantiumBlock: big.NewInt(4370000),
    41  	}
    42  )
    43  
    44  func TestDifficulty(t *testing.T) {
    45  	t.Parallel()
    46  
    47  	dt := new(testMatcher)
    48  	// Not difficulty-tests
    49  	dt.skipLoad("hexencodetest.*")
    50  	dt.skipLoad("crypto.*")
    51  	dt.skipLoad("blockgenesistest\\.json")
    52  	dt.skipLoad("genesishashestest\\.json")
    53  	dt.skipLoad("keyaddrtest\\.json")
    54  	dt.skipLoad("txtest\\.json")
    55  
    56  	// files are 2 years old, contains strange values
    57  	dt.skipLoad("difficultyCustomHomestead\\.json")
    58  	dt.skipLoad("difficultyMorden\\.json")
    59  	dt.skipLoad("difficultyOlimpic\\.json")
    60  
    61  	dt.config("Ropsten", *params.RopstenChainConfig)
    62  	dt.config("Morden", *params.RopstenChainConfig)
    63  	dt.config("Frontier", params.ChainConfig{})
    64  
    65  	dt.config("Homestead", params.ChainConfig{
    66  		HomesteadBlock: big.NewInt(0),
    67  	})
    68  
    69  	dt.config("Byzantium", params.ChainConfig{
    70  		ByzantiumBlock: big.NewInt(0),
    71  	})
    72  
    73  	dt.config("Frontier", *params.RopstenChainConfig)
    74  	dt.config("MainNetwork", mainnetChainConfig)
    75  	dt.config("CustomMainNetwork", mainnetChainConfig)
    76  	dt.config("Constantinople", params.ChainConfig{
    77  		ConstantinopleBlock: big.NewInt(0),
    78  	})
    79  	dt.config("EIP2384", params.ChainConfig{
    80  		MuirGlacierBlock: big.NewInt(0),
    81  	})
    82  	dt.config("EIP4345", params.ChainConfig{
    83  		ArrowGlacierBlock: big.NewInt(0),
    84  	})
    85  	dt.config("difficulty.json", mainnetChainConfig)
    86  
    87  	dt.walk(t, difficultyTestDir, func(t *testing.T, name string, test *DifficultyTest) {
    88  		cfg := dt.findConfig(t)
    89  		if test.ParentDifficulty.Cmp(params.MinimumDifficulty) < 0 {
    90  			t.Skip("difficulty below minimum")
    91  			return
    92  		}
    93  		if err := dt.checkFailure(t, test.Run(cfg)); err != nil {
    94  			t.Errorf("in 'difficulty_test.go', test '%s' failed with error: '%v'", name, err)
    95  		}
    96  	})
    97  }