@@ -13,14 +13,6 @@ function normalize (data) {
13
13
}
14
14
15
15
tape ( '[Header]: difficulty tests' , t => {
16
- t . test ( 'should test error cases' , function ( st ) {
17
- var parentBlock = new Block ( null , { 'chain' : 'mainnet' , 'hardfork' : 'spuriousDragon' } )
18
- var block = new Block ( null , { 'chain' : 'mainnet' , 'hardfork' : 'spuriousDragon' } )
19
-
20
- t . throws ( function ( ) { block . header . canonicalDifficulty ( parentBlock ) } , / D i f f i c u l t y v a l i d a t i o n o n l y s u p p o r t e d o n b l o c k s > = b y z a n t i u m $ / , 'should throw on block with spuriousDragon HF initialization' )
21
- st . end ( )
22
- } )
23
-
24
16
function runDifficultyTests ( test , parentBlock , block , msg ) {
25
17
normalize ( test )
26
18
@@ -29,42 +21,51 @@ tape('[Header]: difficulty tests', t => {
29
21
t . assert ( block . header . validateDifficulty ( parentBlock ) , `test validateDifficulty (${ msg } )` )
30
22
}
31
23
32
- const testData = require ( './testdata-difficulty.json' )
33
- for ( let testName in testData ) {
34
- let test = testData [ testName ]
35
- let parentBlock = new Block ( null , { 'chain' : 'mainnet' , 'hardfork' : 'byzantium' } )
36
- parentBlock . header . timestamp = test . parentTimestamp
37
- parentBlock . header . difficulty = test . parentDifficulty
38
- parentBlock . header . uncleHash = test . parentUncles
24
+ const hardforkTestData = {
25
+ 'chainstart' : require ( './difficultyFrontier.json' ) ,
26
+ 'homestead' : require ( './difficultyHomestead.json' ) ,
27
+ 'byzantium' : require ( './difficultyByzantium.json' )
28
+ }
29
+ for ( let hardfork in hardforkTestData ) {
30
+ const testData = hardforkTestData [ hardfork ]
31
+ for ( let testName in testData ) {
32
+ let test = testData [ testName ]
33
+ let parentBlock = new Block ( null , { 'chain' : 'mainnet' , 'hardfork' : hardfork } )
34
+ parentBlock . header . timestamp = test . parentTimestamp
35
+ parentBlock . header . difficulty = test . parentDifficulty
36
+ parentBlock . header . uncleHash = test . parentUncles
39
37
40
- let block = new Block ( null , { 'chain' : 'mainnet' , 'hardfork' : 'byzantium' } )
41
- block . header . timestamp = test . currentTimestamp
42
- block . header . difficulty = test . currentDifficulty
43
- block . header . number = test . currentBlockNumber
38
+ let block = new Block ( null , { 'chain' : 'mainnet' , 'hardfork' : hardfork } )
39
+ block . header . timestamp = test . currentTimestamp
40
+ block . header . difficulty = test . currentDifficulty
41
+ block . header . number = test . currentBlockNumber
44
42
45
- runDifficultyTests ( test , parentBlock , block , 'fork determination by hardfork param' )
43
+ runDifficultyTests ( test , parentBlock , block , 'fork determination by hardfork param' )
44
+ }
46
45
}
47
46
48
- for ( let testName in testData ) {
49
- let test = testData [ testName ]
50
- const BYZANTIUM_BLOCK = 4370000
51
- let parentBlock = new Block ( )
52
- parentBlock . header . timestamp = test . parentTimestamp
53
- parentBlock . header . difficulty = test . parentDifficulty
54
- parentBlock . header . uncleHash = test . parentUncles
55
- parentBlock . header . number = utils . intToBuffer ( BYZANTIUM_BLOCK - 1 )
47
+ const chainTestData = {
48
+ 'mainnet' : require ( './difficultyMainNetwork.json' ) ,
49
+ 'ropsten' : require ( './difficultyRopsten.json' )
50
+ }
51
+ for ( let chain in chainTestData ) {
52
+ const testData = chainTestData [ chain ]
53
+ for ( let testName in testData ) {
54
+ let test = testData [ testName ]
55
+ let parentBlock = new Block ( null , { 'chain' : chain } )
56
+ parentBlock . header . timestamp = test . parentTimestamp
57
+ parentBlock . header . difficulty = test . parentDifficulty
58
+ parentBlock . header . uncleHash = test . parentUncles
56
59
57
- let block = new Block ( )
58
- block . header . timestamp = test . currentTimestamp
59
- block . header . difficulty = test . currentDifficulty
60
- block . header . number = test . currentBlockNumber
60
+ let block = new Block ( null , { 'chain' : chain } )
61
+ block . header . timestamp = test . currentTimestamp
62
+ block . header . difficulty = test . currentDifficulty
63
+ block . header . number = test . currentBlockNumber
61
64
62
- if ( utils . bufferToInt ( block . header . number ) >= BYZANTIUM_BLOCK ) {
63
65
runDifficultyTests ( test , parentBlock , block , 'fork determination by block number' )
64
- } else {
65
- t . throws ( function ( ) { block . header . canonicalDifficulty ( parentBlock ) } , / D i f f i c u l t y v a l i d a t i o n o n l y s u p p o r t e d o n b l o c k s > = b y z a n t i u m $ / , 'should throw on block < byzantium' )
66
66
}
67
67
}
68
+
68
69
t . end ( )
69
70
70
71
// Temporarily run local test selection
0 commit comments