github.com/muku314115/go-ethereum@v1.9.7/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/common"
    24  	"github.com/ethereum/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  
    41  func TestDifficulty(t *testing.T) {
    42  	t.Parallel()
    43  
    44  	dt := new(testMatcher)
    45  	// Not difficulty-tests
    46  	dt.skipLoad("hexencodetest.*")
    47  	dt.skipLoad("crypto.*")
    48  	dt.skipLoad("blockgenesistest\\.json")
    49  	dt.skipLoad("genesishashestest\\.json")
    50  	dt.skipLoad("keyaddrtest\\.json")
    51  	dt.skipLoad("txtest\\.json")
    52  
    53  	// files are 2 years old, contains strange values
    54  	dt.skipLoad("difficultyCustomHomestead\\.json")
    55  	dt.skipLoad("difficultyMorden\\.json")
    56  	dt.skipLoad("difficultyOlimpic\\.json")
    57  
    58  	dt.config("Ropsten", *params.TestnetChainConfig)
    59  	dt.config("Morden", *params.TestnetChainConfig)
    60  	dt.config("Frontier", params.ChainConfig{})
    61  
    62  	dt.config("Homestead", params.ChainConfig{
    63  		HomesteadBlock: big.NewInt(0),
    64  	})
    65  
    66  	dt.config("Byzantium", params.ChainConfig{
    67  		ByzantiumBlock: big.NewInt(0),
    68  	})
    69  
    70  	dt.config("Frontier", *params.TestnetChainConfig)
    71  	dt.config("MainNetwork", mainnetChainConfig)
    72  	dt.config("CustomMainNetwork", mainnetChainConfig)
    73  	dt.config("Constantinople", params.ChainConfig{
    74  		ConstantinopleBlock: big.NewInt(0),
    75  	})
    76  	dt.config("difficulty.json", mainnetChainConfig)
    77  
    78  	dt.walk(t, difficultyTestDir, func(t *testing.T, name string, test *DifficultyTest) {
    79  		cfg := dt.findConfig(name)
    80  		if test.ParentDifficulty.Cmp(params.MinimumDifficulty) < 0 {
    81  			t.Skip("difficulty below minimum")
    82  			return
    83  		}
    84  		if err := dt.checkFailure(t, name, test.Run(cfg)); err != nil {
    85  			t.Error(err)
    86  		}
    87  	})
    88  }