github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/tests/difficulty_test.go (about)

     1  // This file is part of the go-sberex library. The go-sberex library is 
     2  // free software: you can redistribute it and/or modify it under the terms 
     3  // of the GNU Lesser General Public License as published by the Free 
     4  // Software Foundation, either version 3 of the License, or (at your option)
     5  // any later version.
     6  //
     7  // The go-sberex library is distributed in the hope that it will be useful, 
     8  // but WITHOUT ANY WARRANTY; without even the implied warranty of
     9  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 
    10  // General Public License <http://www.gnu.org/licenses/> for more details.
    11  
    12  package tests
    13  
    14  import (
    15  	"testing"
    16  
    17  	"math/big"
    18  
    19  	"github.com/Sberex/go-sberex/common"
    20  	"github.com/Sberex/go-sberex/params"
    21  )
    22  
    23  var (
    24  	mainnetChainConfig = params.ChainConfig{
    25  		ChainId:        big.NewInt(1),
    26  		HomesteadBlock: big.NewInt(1150000),
    27  		DAOForkBlock:   big.NewInt(1920000),
    28  		DAOForkSupport: true,
    29  		EIP150Block:    big.NewInt(2463000),
    30  		EIP150Hash:     common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"),
    31  		EIP155Block:    big.NewInt(2675000),
    32  		EIP158Block:    big.NewInt(2675000),
    33  		ByzantiumBlock: big.NewInt(4370000),
    34  	}
    35  )
    36  
    37  func TestDifficulty(t *testing.T) {
    38  	t.Parallel()
    39  
    40  	dt := new(testMatcher)
    41  	// Not difficulty-tests
    42  	dt.skipLoad("hexencodetest.*")
    43  	dt.skipLoad("crypto.*")
    44  	dt.skipLoad("blockgenesistest\\.json")
    45  	dt.skipLoad("genesishashestest\\.json")
    46  	dt.skipLoad("keyaddrtest\\.json")
    47  	dt.skipLoad("txtest\\.json")
    48  
    49  	// files are 2 years old, contains strange values
    50  	dt.skipLoad("difficultyCustomHomestead\\.json")
    51  	dt.skipLoad("difficultyMorden\\.json")
    52  	dt.skipLoad("difficultyOlimpic\\.json")
    53  
    54  	dt.config("Ropsten", *params.TestnetChainConfig)
    55  	dt.config("Morden", *params.TestnetChainConfig)
    56  	dt.config("Frontier", params.ChainConfig{})
    57  
    58  	dt.config("Homestead", params.ChainConfig{
    59  		HomesteadBlock: big.NewInt(0),
    60  	})
    61  
    62  	dt.config("Byzantium", params.ChainConfig{
    63  		ByzantiumBlock: big.NewInt(0),
    64  	})
    65  
    66  	dt.config("Frontier", *params.TestnetChainConfig)
    67  	dt.config("MainNetwork", mainnetChainConfig)
    68  	dt.config("CustomMainNetwork", mainnetChainConfig)
    69  	dt.config("difficulty.json", mainnetChainConfig)
    70  
    71  	dt.walk(t, difficultyTestDir, func(t *testing.T, name string, test *DifficultyTest) {
    72  		cfg := dt.findConfig(name)
    73  		if test.ParentDifficulty.Cmp(params.MinimumDifficulty) < 0 {
    74  			t.Skip("difficulty below minimum")
    75  			return
    76  		}
    77  		if err := dt.checkFailure(t, name, test.Run(cfg)); err != nil {
    78  			t.Error(err)
    79  		}
    80  	})
    81  }