1 | const testing = require('ethereumjs-testing')
|
2 | const ethUtil = require('ethereumjs-util')
|
3 | const basicTests = testing.tests.basicTests
|
4 | const tape = require('tape')
|
5 | const Block = require('../')
|
6 | const BN = ethUtil.BN
|
7 |
|
8 | function addHomesteadFlag (tests) {
|
9 | Object.keys(tests).map(function (q) {
|
10 | tests[q].homestead = true
|
11 | })
|
12 | return tests
|
13 | }
|
14 |
|
15 | function normilize (data) {
|
16 | Object.keys(data).map(function (i) {
|
17 | if (i !== 'homestead') {
|
18 | data[i] = ethUtil.isHexPrefixed(data[i]) ? new BN(ethUtil.toBuffer(data[i])) : new BN(data[i])
|
19 | }
|
20 | })
|
21 | }
|
22 |
|
23 | testing.runTests(function (data, st, cb) {
|
24 | normilize(data)
|
25 | var parentBlock = new Block()
|
26 | parentBlock.header.timestamp = data.parentTimestamp
|
27 | parentBlock.header.difficulty = data.parentDifficulty
|
28 |
|
29 | var block = new Block()
|
30 | if (data.homestead) {
|
31 | block.header.isHomestead = function () {
|
32 | return true
|
33 | }
|
34 | } else {
|
35 | block.header.isHomestead = function () {
|
36 | return false
|
37 | }
|
38 | }
|
39 | block.header.timestamp = data.currentTimestamp
|
40 | block.header.difficulty = data.currentDifficulty
|
41 | block.header.number = data.currentBlockNumber
|
42 |
|
43 | var dif = block.header.canonicalDifficulty(parentBlock)
|
44 | st.equal(dif.toString(), data.currentDifficulty.toString())
|
45 | cb()
|
46 | }, {
|
47 | difficulty: basicTests.difficulty,
|
48 | difficultyHomestead: addHomesteadFlag(basicTests.difficultyHomestead)
|
49 | }, tape)
|