Merge pull request #323 from tuxcanfly/test-headers

Primitives tests - headers
This commit is contained in:
Christopher Jeffrey (JJ) 2017-10-18 13:17:46 -07:00 committed by GitHub
commit 1a3c5e8a22
3 changed files with 58 additions and 0 deletions

BIN
test/data/block1.raw Normal file

Binary file not shown.

BIN
test/data/headers1.raw Normal file

Binary file not shown.

58
test/headers-test.js Normal file
View File

@ -0,0 +1,58 @@
/* eslint-env mocha */
/* eslint prefer-arrow-callback: "off" */
'use strict';
const Headers = require('../lib/primitives/headers');
const assert = require('./util/assert');
const common = require('./util/common');
const block1 = common.readBlock('block1');
const headers1 = common.readFile('headers1.raw');
describe('Headers', function() {
it('should match headers size', () => {
const headers = new Headers();
assert.strictEqual(headers.getSize(), 81);
});
it('should match block1 headers from block', () => {
const [blockOne] = block1.getBlock();
const headers = Headers.fromBlock(blockOne);
assert.strictEqual(headers.time, 1231469665);
assert.strictEqual(headers.bits, 486604799);
assert.strictEqual(headers.nonce, 2573394689);
assert.strictEqual(headers.version, 1);
assert.strictEqual(headers.prevBlock,
'6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000');
assert.strictEqual(headers.merkleRoot,
'982051fd1e4ba744bbbe680e1fee14677ba1a3c3540bf7b1cdb606e857233e0e');
assert.strictEqual(headers.rhash(),
'00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048');
assert(headers.verifyBody());
assert(headers.verifyPOW());
});
it('should match block1 headers from raw', () => {
const headers = Headers.fromRaw(headers1);
assert.strictEqual(headers.time, 1231469665);
assert.strictEqual(headers.bits, 486604799);
assert.strictEqual(headers.nonce, 2573394689);
assert.strictEqual(headers.version, 1);
assert.strictEqual(headers.prevBlock,
'6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000');
assert.strictEqual(headers.merkleRoot,
'982051fd1e4ba744bbbe680e1fee14677ba1a3c3540bf7b1cdb606e857233e0e');
assert.strictEqual(headers.rhash(),
'00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048');
assert(headers.verifyBody());
assert(headers.verifyPOW());
});
});