add Block.calculateTarget, use Buffer comparison rather than bigi
This commit is contained in:
parent
26ccb43047
commit
86b51b2d62
4 changed files with 45 additions and 10 deletions
test
|
@ -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 () {
|
||||
|
|
20
test/fixtures/block.json
vendored
20
test/fixtures/block.json
vendored
|
@ -1,4 +1,22 @@
|
|||
|
||||
{
|
||||
"targets": [
|
||||
{
|
||||
"bits": "1d00ffff",
|
||||
"expected": "00000000ffff0000000000000000000000000000000000000000000000000000"
|
||||
},
|
||||
{
|
||||
"bits": "1b80ffff",
|
||||
"expected": "000000000080ffff000000000000000000000000000000000000000000000000"
|
||||
},
|
||||
{
|
||||
"bits": "1b0404cb",
|
||||
"expected": "00000000000404cb000000000000000000000000000000000000000000000000"
|
||||
},
|
||||
{
|
||||
"bits": "1814dd04",
|
||||
"expected": "000000000000000014dd04000000000000000000000000000000000000000000"
|
||||
}
|
||||
],
|
||||
"valid": [
|
||||
{
|
||||
"description": "Headers only",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue