|
|
@ -1,12 +1,21 @@ |
|
|
|
/* global describe, it, beforeEach */ |
|
|
|
|
|
|
|
var assert = require('assert') |
|
|
|
|
|
|
|
var Block = require('../src/block') |
|
|
|
|
|
|
|
var fixtures = require('./fixtures/block') |
|
|
|
|
|
|
|
describe('Block', function () { |
|
|
|
describe('calculateTarget', function () { |
|
|
|
fixtures.targets.forEach(function (f) { |
|
|
|
it('returns ' + f.expected + ' for 0x' + f.bits, function () { |
|
|
|
var bits = parseInt(f.bits, 16) |
|
|
|
|
|
|
|
assert.equal(Block.calculateTarget(bits).toString('hex'), f.expected) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
describe('fromBuffer/fromHex', function () { |
|
|
|
fixtures.valid.forEach(function (f) { |
|
|
|
it('imports the block: ' + f.description + ' correctly', function () { |
|
|
@ -52,7 +61,7 @@ describe('Block', function () { |
|
|
|
block = Block.fromHex(f.hex) |
|
|
|
}) |
|
|
|
|
|
|
|
it('calculates ' + f.hash + ' for the block: ' + f.description, function () { |
|
|
|
it('returns ' + f.hash + ' for the block: ' + f.description, function () { |
|
|
|
assert.strictEqual(block.getHash().toString('hex'), f.hash) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -66,7 +75,7 @@ describe('Block', function () { |
|
|
|
block = Block.fromHex(f.hex) |
|
|
|
}) |
|
|
|
|
|
|
|
it('calculates ' + f.id + ' for the block: ' + f.description, function () { |
|
|
|
it('returns ' + f.id + ' for the block: ' + f.description, function () { |
|
|
|
assert.strictEqual(block.getId(), f.id) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -87,4 +96,18 @@ describe('Block', function () { |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
describe('checkProofOfWork', function () { |
|
|
|
fixtures.valid.forEach(function (f) { |
|
|
|
var block |
|
|
|
|
|
|
|
beforeEach(function () { |
|
|
|
block = Block.fromHex(f.hex) |
|
|
|
}) |
|
|
|
|
|
|
|
it('returns ' + f.valid + ' for ' + f.id, function () { |
|
|
|
assert.strictEqual(block.checkProofOfWork(), f.valid) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|