github.com/intfoundation/intchain@v0.0.0-20220727031208-4316ad31ca73/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  	"testing"
    21  
    22  	"math/big"
    23  
    24  	"github.com/intfoundation/intchain/common"
    25  	"github.com/intfoundation/intchain/params"
    26  )
    27  
    28  var (
    29  	mainnetChainConfig = params.ChainConfig{
    30  		ChainId:        big.NewInt(1),
    31  		HomesteadBlock: big.NewInt(1150000),
    32  		EIP150Block:    big.NewInt(2463000),
    33  		EIP150Hash:     common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"),
    34  		EIP155Block:    big.NewInt(2675000),
    35  		EIP158Block:    big.NewInt(2675000),
    36  		ByzantiumBlock: big.NewInt(4370000),
    37  	}
    38  )
    39  
    40  func TestDifficulty(t *testing.T) {
    41  	t.Parallel()
    42  
    43  	dt := new(testMatcher)
    44  	// Not difficulty-tests
    45  	dt.skipLoad("hexencodetest.*")
    46  	dt.skipLoad("crypto.*")
    47  	dt.skipLoad("blockgenesistest\\.json")
    48  	dt.skipLoad("genesishashestest\\.json")
    49  	dt.skipLoad("keyaddrtest\\.json")
    50  	dt.skipLoad("txtest\\.json")
    51  
    52  	// files are 2 years old, contains strange values
    53  	dt.skipLoad("difficultyCustomHomestead\\.json")
    54  	dt.skipLoad("difficultyMorden\\.json")
    55  	dt.skipLoad("difficultyOlimpic\\.json")
    56  
    57  	dt.config("Ropsten", *params.TestnetChainConfig)
    58  	dt.config("Morden", *params.TestnetChainConfig)
    59  	dt.config("Frontier", params.ChainConfig{})
    60  
    61  	dt.config("Homestead", params.ChainConfig{
    62  		HomesteadBlock: big.NewInt(0),
    63  	})
    64  
    65  	dt.config("Byzantium", params.ChainConfig{
    66  		ByzantiumBlock: big.NewInt(0),
    67  	})
    68  
    69  	dt.config("Frontier", *params.TestnetChainConfig)
    70  	dt.config("MainNetwork", mainnetChainConfig)
    71  	dt.config("CustomMainNetwork", mainnetChainConfig)
    72  	dt.config("difficulty.json", mainnetChainConfig)
    73  	dt.config("Constantinople", params.ChainConfig{
    74  		ConstantinopleBlock: big.NewInt(0),
    75  	})
    76  	dt.config("Petersburg", params.ChainConfig{
    77  		PetersburgBlock: big.NewInt(0),
    78  	})
    79  	dt.config("Istanbul", params.ChainConfig{
    80  		IstanbulBlock: big.NewInt(0),
    81  	})
    82  	dt.walk(t, difficultyTestDir, func(t *testing.T, name string, test *DifficultyTest) {
    83  		cfg := dt.findConfig(name)
    84  		if test.ParentDifficulty.Cmp(params.MinimumDifficulty) < 0 {
    85  			t.Skip("difficulty below minimum")
    86  			return
    87  		}
    88  		if err := dt.checkFailure(t, name, test.Run(cfg)); err != nil {
    89  			t.Error(err)
    90  		}
    91  	})
    92  }