github.com/codingfuture/orig-energi3@v0.8.4/tests/difficulty_test.go (about)

     1  // Copyright 2018 The Energi Core Authors
     2  // Copyright 2017 The go-ethereum Authors
     3  // This file is part of the Energi Core library.
     4  //
     5  // The Energi Core library is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Lesser General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // The Energi Core library is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  // GNU Lesser General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Lesser General Public License
    16  // along with the Energi Core library. If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package tests
    19  
    20  import (
    21  	"math/big"
    22  	"os"
    23  	"testing"
    24  
    25  	"github.com/ethereum/go-ethereum/common"
    26  	"github.com/ethereum/go-ethereum/params"
    27  )
    28  
    29  var (
    30  	mainnetChainConfig = params.ChainConfig{
    31  		ChainID:        big.NewInt(1),
    32  		HomesteadBlock: big.NewInt(1150000),
    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  	if val, ok := os.LookupEnv("SKIP_KNOWN_FAIL"); ok && val == "1" {
    43  		t.Skip("unit test is broken: conditional test skipping activated")
    44  	}
    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.TestnetChainConfig)
    62  	dt.config("Morden", *params.TestnetChainConfig)
    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.TestnetChainConfig)
    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("difficulty.json", mainnetChainConfig)
    80  
    81  	dt.walk(t, difficultyTestDir, func(t *testing.T, name string, test *DifficultyTest) {
    82  		cfg := dt.findConfig(name)
    83  		if test.ParentDifficulty.Cmp(params.MinimumDifficulty) < 0 {
    84  			t.Skip("difficulty below minimum")
    85  			return
    86  		}
    87  		if err := dt.checkFailure(t, name, test.Run(cfg)); err != nil {
    88  			t.Error(err)
    89  		}
    90  	})
    91  }