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 Aug 31, 2017
1 parent b84ac26 commit 6b0e7fc
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 19 deletions.
49 changes: 30 additions & 19 deletions tests/difficulty.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,43 @@ function normalize (data) {
}

tape('[Header]: difficulty tests', t => {
function runDifficultyTests(test) {
normalize(test)

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.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')
}

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) => {
normalize(test)

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

var block = new Block()
block.header.isHomestead = function () {
return true
}

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')

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 6b0e7fc

Please sign in to comment.