github.com/Ethersocial/go-esn@v0.3.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/ethersocial/go-esn/common"
    24  	"github.com/ethersocial/go-esn/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  	// Ropsten without the Constantinople bump in bomb delay
    41  	RopstenNoConstantinople = params.ChainConfig{
    42  		ChainID:             big.NewInt(3),
    43  		HomesteadBlock:      big.NewInt(0),
    44  		DAOForkBlock:        nil,
    45  		DAOForkSupport:      true,
    46  		EIP150Block:         big.NewInt(0),
    47  		EIP150Hash:          common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d"),
    48  		EIP155Block:         big.NewInt(10),
    49  		EIP158Block:         big.NewInt(10),
    50  		ByzantiumBlock:      big.NewInt(1700000),
    51  		ConstantinopleBlock: nil,
    52  	}
    53  )
    54  
    55  func TestDifficulty(t *testing.T) {
    56  	t.Parallel()
    57  
    58  	dt := new(testMatcher)
    59  	// Not difficulty-tests
    60  	dt.skipLoad("hexencodetest.*")
    61  	dt.skipLoad("crypto.*")
    62  	dt.skipLoad("blockgenesistest\\.json")
    63  	dt.skipLoad("genesishashestest\\.json")
    64  	dt.skipLoad("keyaddrtest\\.json")
    65  	dt.skipLoad("txtest\\.json")
    66  
    67  	// files are 2 years old, contains strange values
    68  	dt.skipLoad("difficultyCustomHomestead\\.json")
    69  	dt.skipLoad("difficultyMorden\\.json")
    70  	dt.skipLoad("difficultyOlimpic\\.json")
    71  
    72  	dt.config("Ropsten", RopstenNoConstantinople)
    73  	dt.config("Morden", *params.TestnetChainConfig)
    74  	dt.config("Frontier", params.ChainConfig{})
    75  
    76  	dt.config("Homestead", params.ChainConfig{
    77  		HomesteadBlock: big.NewInt(0),
    78  	})
    79  
    80  	dt.config("Byzantium", params.ChainConfig{
    81  		ByzantiumBlock: big.NewInt(0),
    82  	})
    83  
    84  	dt.config("Frontier", *params.TestnetChainConfig)
    85  	dt.config("MainNetwork", mainnetChainConfig)
    86  	dt.config("CustomMainNetwork", mainnetChainConfig)
    87  	dt.config("difficulty.json", mainnetChainConfig)
    88  
    89  	dt.walk(t, difficultyTestDir, func(t *testing.T, name string, test *DifficultyTest) {
    90  		cfg := dt.findConfig(name)
    91  		if test.ParentDifficulty.Cmp(params.MinimumDifficulty) < 0 {
    92  			t.Skip("difficulty below minimum")
    93  			return
    94  		}
    95  		if err := dt.checkFailure(t, name, test.Run(cfg)); err != nil {
    96  			t.Error(err)
    97  		}
    98  	})
    99  }