github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/tests/difficulty_test.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 19:16:45</date>
    10  //</624450121966292992>
    11  
    12  
    13  package tests
    14  
    15  import (
    16  	"math/big"
    17  	"testing"
    18  
    19  	"github.com/ethereum/go-ethereum/common"
    20  	"github.com/ethereum/go-ethereum/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  //不是难度测试
    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  //文件有2年的历史,包含奇怪的值
    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("Constantinople", params.ChainConfig{
    70  		ConstantinopleBlock: big.NewInt(0),
    71  	})
    72  	dt.config("difficulty.json", mainnetChainConfig)
    73  
    74  	dt.walk(t, difficultyTestDir, func(t *testing.T, name string, test *DifficultyTest) {
    75  		cfg := dt.findConfig(name)
    76  		if test.ParentDifficulty.Cmp(params.MinimumDifficulty) < 0 {
    77  			t.Skip("difficulty below minimum")
    78  			return
    79  		}
    80  		if err := dt.checkFailure(t, name, test.Run(cfg)); err != nil {
    81  			t.Error(err)
    82  		}
    83  	})
    84  }
    85