Tests to arrow functions, use strict asserts, travis uses docker instead of regtest server
This commit is contained in:
parent
16823e9013
commit
dc1ef5958b
24 changed files with 505 additions and 498 deletions
test
|
@ -4,29 +4,29 @@ const Block = require('..').Block
|
|||
|
||||
const fixtures = require('./fixtures/block')
|
||||
|
||||
describe('Block', function () {
|
||||
describe('version', function () {
|
||||
it('should be interpreted as an int32le', function () {
|
||||
describe('Block', () => {
|
||||
describe('version', () => {
|
||||
it('should be interpreted as an int32le', () => {
|
||||
const blockHex = 'ffffffff0000000000000000000000000000000000000000000000000000000000000000414141414141414141414141414141414141414141414141414141414141414101000000020000000300000000'
|
||||
const block = Block.fromHex(blockHex)
|
||||
assert.equal(-1, block.version)
|
||||
assert.equal(1, block.timestamp)
|
||||
assert.strictEqual(-1, block.version)
|
||||
assert.strictEqual(1, block.timestamp)
|
||||
})
|
||||
})
|
||||
|
||||
describe('calculateTarget', function () {
|
||||
fixtures.targets.forEach(function (f) {
|
||||
it('returns ' + f.expected + ' for 0x' + f.bits, function () {
|
||||
describe('calculateTarget', () => {
|
||||
fixtures.targets.forEach(f => {
|
||||
it('returns ' + f.expected + ' for 0x' + f.bits, () => {
|
||||
const bits = parseInt(f.bits, 16)
|
||||
|
||||
assert.equal(Block.calculateTarget(bits).toString('hex'), f.expected)
|
||||
assert.strictEqual(Block.calculateTarget(bits).toString('hex'), f.expected)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('fromBuffer/fromHex', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('imports ' + f.description, function () {
|
||||
describe('fromBuffer/fromHex', () => {
|
||||
fixtures.valid.forEach(f => {
|
||||
it('imports ' + f.description, () => {
|
||||
const block = Block.fromHex(f.hex)
|
||||
|
||||
assert.strictEqual(block.version, f.version)
|
||||
|
@ -42,54 +42,54 @@ describe('Block', function () {
|
|||
})
|
||||
})
|
||||
|
||||
fixtures.invalid.forEach(function (f) {
|
||||
it('throws on ' + f.exception, function () {
|
||||
assert.throws(function () {
|
||||
fixtures.invalid.forEach(f => {
|
||||
it('throws on ' + f.exception, () => {
|
||||
assert.throws(() => {
|
||||
Block.fromHex(f.hex)
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('toBuffer/toHex', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
describe('toBuffer/toHex', () => {
|
||||
fixtures.valid.forEach(f => {
|
||||
let block
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(() => {
|
||||
block = Block.fromHex(f.hex)
|
||||
})
|
||||
|
||||
it('exports ' + f.description, function () {
|
||||
it('exports ' + f.description, () => {
|
||||
assert.strictEqual(block.toHex(true), f.hex.slice(0, 160))
|
||||
assert.strictEqual(block.toHex(), f.hex)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('getHash/getId', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
describe('getHash/getId', () => {
|
||||
fixtures.valid.forEach(f => {
|
||||
let block
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(() => {
|
||||
block = Block.fromHex(f.hex)
|
||||
})
|
||||
|
||||
it('returns ' + f.id + ' for ' + f.description, function () {
|
||||
it('returns ' + f.id + ' for ' + f.description, () => {
|
||||
assert.strictEqual(block.getHash().toString('hex'), f.hash)
|
||||
assert.strictEqual(block.getId(), f.id)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('getUTCDate', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
describe('getUTCDate', () => {
|
||||
fixtures.valid.forEach(f => {
|
||||
let block
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(() => {
|
||||
block = Block.fromHex(f.hex)
|
||||
})
|
||||
|
||||
it('returns UTC date of ' + f.id, function () {
|
||||
it('returns UTC date of ' + f.id, () => {
|
||||
const utcDate = block.getUTCDate().getTime()
|
||||
|
||||
assert.strictEqual(utcDate, f.timestamp * 1e3)
|
||||
|
@ -97,59 +97,59 @@ describe('Block', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('calculateMerkleRoot', function () {
|
||||
it('should throw on zero-length transaction array', function () {
|
||||
assert.throws(function () {
|
||||
describe('calculateMerkleRoot', () => {
|
||||
it('should throw on zero-length transaction array', () => {
|
||||
assert.throws(() => {
|
||||
Block.calculateMerkleRoot([])
|
||||
}, /Cannot compute merkle root for zero transactions/)
|
||||
})
|
||||
|
||||
fixtures.valid.forEach(function (f) {
|
||||
fixtures.valid.forEach(f => {
|
||||
if (f.hex.length === 160) return
|
||||
|
||||
let block
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(() => {
|
||||
block = Block.fromHex(f.hex)
|
||||
})
|
||||
|
||||
it('returns ' + f.merkleRoot + ' for ' + f.id, function () {
|
||||
it('returns ' + f.merkleRoot + ' for ' + f.id, () => {
|
||||
assert.strictEqual(Block.calculateMerkleRoot(block.transactions).toString('hex'), f.merkleRoot)
|
||||
})
|
||||
|
||||
if (f.witnessCommit) {
|
||||
it('returns witness commit ' + f.witnessCommit + ' for ' + f.id, function () {
|
||||
it('returns witness commit ' + f.witnessCommit + ' for ' + f.id, () => {
|
||||
assert.strictEqual(Block.calculateMerkleRoot(block.transactions, true).toString('hex'), f.witnessCommit)
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('checkTxRoots', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
describe('checkTxRoots', () => {
|
||||
fixtures.valid.forEach(f => {
|
||||
if (f.hex.length === 160) return
|
||||
|
||||
let block
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(() => {
|
||||
block = Block.fromHex(f.hex)
|
||||
})
|
||||
|
||||
it('returns ' + f.valid + ' for ' + f.id, function () {
|
||||
it('returns ' + f.valid + ' for ' + f.id, () => {
|
||||
assert.strictEqual(block.checkTxRoots(), true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('checkProofOfWork', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
describe('checkProofOfWork', () => {
|
||||
fixtures.valid.forEach(f => {
|
||||
let block
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(() => {
|
||||
block = Block.fromHex(f.hex)
|
||||
})
|
||||
|
||||
it('returns ' + f.valid + ' for ' + f.id, function () {
|
||||
it('returns ' + f.valid + ' for ' + f.id, () => {
|
||||
assert.strictEqual(block.checkProofOfWork(), f.valid)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue