Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Commit

Permalink
Change difficulty tests to run local Byzantium-compatible test select…
Browse files Browse the repository at this point in the history
…ion (no Byzantium difficulty tests available yet)
  • Loading branch information
holgerd77 committed Sep 11, 2017
1 parent b84ac26 commit c228724
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 20 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var Block = module.exports = function (data) {
for (var i = 0; i < rawUncleHeaders.length; i++) {
this.uncleHeaders.push(new BlockHeader(rawUncleHeaders[i]))
}

// parse transactions
for (i = 0; i < rawTransactions.length; i++) {
var tx = new Tx(rawTransactions[i])
Expand Down
49 changes: 30 additions & 19 deletions tests/difficulty.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const testing = require('ethereumjs-testing')
// const testing = require('ethereumjs-testing')
const utils = require('ethereumjs-util')
const tape = require('tape')
const Block = require('../')
Expand All @@ -13,32 +13,43 @@ function normalize (data) {
}

tape('[Header]: difficulty tests', t => {
let args = {}
args.file = /^difficultyHomestead/
testing.getTestsFromArgs('BasicTests', (fileName, testName, test) => {
return new Promise((resolve, reject) => {
normalize(test)
function runDifficultyTests (test) {
normalize(test)

var parentBlock = new Block()
parentBlock.header.timestamp = test.parentTimestamp
parentBlock.header.difficulty = test.parentDifficulty
var parentBlock = new Block()
parentBlock.header.timestamp = test.parentTimestamp
parentBlock.header.difficulty = test.parentDifficulty
parentBlock.header.uncleHash = test.parentUncleHash

var block = new Block()
block.header.isHomestead = function () {
return true
}
var block = new Block()
block.header.timestamp = test.currentTimestamp
block.header.difficulty = test.currentDifficulty
block.header.number = test.currentBlockNumber

block.header.timestamp = test.currentTimestamp
block.header.difficulty = test.currentDifficulty
block.header.number = test.currentBlockNumber
var dif = block.header.canonicalDifficulty(parentBlock)
t.equal(dif.toString(), test.currentDifficulty.toString(), 'test canonicalDifficulty')
t.assert(block.header.validateDifficulty(parentBlock), 'test validateDifficulty')
}

var dif = block.header.canonicalDifficulty(parentBlock)
t.equal(dif.toString(), test.currentDifficulty.toString(), 'test canonicalDifficulty')
t.assert(block.header.validateDifficulty(parentBlock), 'test validateDifficulty')
const testData = require('./testdata-difficulty.json')
for (let testName in testData) {
runDifficultyTests(testData[testName])
}
t.end()

// Temporarily run local test selection
// also: implicit testing through ethereumjs-vm tests
// (no Byzantium difficulty tests available yet)
/*
let args = {}
args.file = /^difficultyHomestead/
testing.getTestsFromArgs('BasicTests', (fileName, testName, test) => {
return new Promise((resolve, reject) => {
runDifficultyTests(test)
resolve()
}).catch(err => console.log(err))
}, args).then(() => {
t.end()
})
*/
})
50 changes: 50 additions & 0 deletions tests/testdata-difficulty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"LocalDifficultyTest1_Byzantium" : {
"parentTimestamp" : "0x18d89135f8ebcb78",
"parentDifficulty" : "0x1ef5f85ed5a0067a",
"currentTimestamp" : "0x18d89135f8ebcb78",
"currentBlockNumber" : "0x61a9",
"currentDifficulty" : "0x1ef9d71de17aba7a",
"parentUncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
"bcTotalDifficultyTest_uncleBlockAtBlock3AfterBlock3_Byzantium_GB_B1" : {
"parentTimestamp" : "0x54c98c81",
"parentDifficulty" : "0x020000",
"currentTimestamp" : "0x59976a0f",
"currentBlockNumber" : "0x01",
"currentDifficulty" : "0x020000",
"parentUncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
"bcTotalDifficultyTest_uncleBlockAtBlock3AfterBlock3_Byzantium_B1_B2" : {
"parentTimestamp" : "0x59976a0f",
"parentDifficulty" : "0x020000",
"currentTimestamp" : "0x59976a11",
"currentBlockNumber" : "0x02",
"currentDifficulty" : "0x020040",
"parentUncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
"bcTotalDifficultyTest_uncleBlockAtBlock3AfterBlock3_Byzantium_B2_B3_1" : {
"parentTimestamp" : "0x59976a11",
"parentDifficulty" : "0x020040",
"currentTimestamp" : "0x59976a13",
"currentBlockNumber" : "0x03",
"currentDifficulty" : "0x020080",
"parentUncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
"bcTotalDifficultyTest_uncleBlockAtBlock3AfterBlock3_Byzantium_B2_B3_2" : {
"parentTimestamp" : "0x59976a11",
"parentDifficulty" : "0x020040",
"currentTimestamp" : "0x59976a19",
"currentBlockNumber" : "0x03",
"currentDifficulty" : "0x020080",
"parentUncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
"bcTotalDifficultyTest_uncleBlockAtBlock3AfterBlock3_Byzantium_B3_2_B4" : {
"parentTimestamp" : "0x59976a19",
"parentDifficulty" : "0x020080",
"currentTimestamp" : "0x59976a1e",
"currentBlockNumber" : "0x04",
"currentDifficulty" : "0x020100",
"parentUncleHash": "0xca3e970cbb36b672f8707491c3aaf1dd0971c35f4bd23b26f668fa90eecb12b8"
}
}

0 comments on commit c228724

Please sign in to comment.