Added preconditions to the Headers message.
This commit is contained in:
parent
24ffd3f5f6
commit
f21e2439be
@ -6,6 +6,7 @@ var bitcore = require('bitcore');
|
|||||||
var utils = require('../utils');
|
var utils = require('../utils');
|
||||||
var BufferReader = bitcore.encoding.BufferReader;
|
var BufferReader = bitcore.encoding.BufferReader;
|
||||||
var BufferWriter = bitcore.encoding.BufferWriter;
|
var BufferWriter = bitcore.encoding.BufferWriter;
|
||||||
|
var _ = bitcore.deps._;
|
||||||
var $ = bitcore.util.preconditions;
|
var $ = bitcore.util.preconditions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,6 +25,10 @@ function HeadersMessage(arg, options) {
|
|||||||
this.BlockHeader = options.BlockHeader;
|
this.BlockHeader = options.BlockHeader;
|
||||||
this.magicNumber = options.magicNumber;
|
this.magicNumber = options.magicNumber;
|
||||||
this.command = 'headers';
|
this.command = 'headers';
|
||||||
|
$.checkArgument(
|
||||||
|
_.isUndefined(arg) || (Array.isArray(arg) && arg[0] instanceof this.BlockHeader),
|
||||||
|
'First argument is expected to be an array of BlockHeader instances'
|
||||||
|
);
|
||||||
this.headers = arg;
|
this.headers = arg;
|
||||||
}
|
}
|
||||||
inherits(HeadersMessage, Message);
|
inherits(HeadersMessage, Message);
|
||||||
|
|||||||
@ -10,6 +10,19 @@ describe('Command Messages', function() {
|
|||||||
|
|
||||||
var messages = new Messages();
|
var messages = new Messages();
|
||||||
|
|
||||||
|
describe('Alert', function() {
|
||||||
|
|
||||||
|
it('should accept a transaction instance as an argument', function() {
|
||||||
|
var message = messages.Alert({
|
||||||
|
payload: new Buffer('abcdef', 'hex'),
|
||||||
|
signature: new Buffer('123456', 'hex')
|
||||||
|
});
|
||||||
|
message.payload.should.deep.equal(new Buffer('abcdef', 'hex'));
|
||||||
|
message.signature.should.deep.equal(new Buffer('123456', 'hex'));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('Transaction', function() {
|
describe('Transaction', function() {
|
||||||
|
|
||||||
it('should accept a transaction instance as an argument', function() {
|
it('should accept a transaction instance as an argument', function() {
|
||||||
@ -123,6 +136,24 @@ describe('Command Messages', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Headers', function() {
|
||||||
|
it('should error if arg is not an array', function() {
|
||||||
|
(function() {
|
||||||
|
var message = messages.Headers({});
|
||||||
|
}).should.throw('First argument is expected to be an array');
|
||||||
|
});
|
||||||
|
it('should error if arg is an empty array', function() {
|
||||||
|
(function() {
|
||||||
|
var message = messages.Headers([]);
|
||||||
|
}).should.throw('First argument is expected to be an array');
|
||||||
|
});
|
||||||
|
it('should error if arg is not an array of BlockHeaders', function() {
|
||||||
|
(function() {
|
||||||
|
var message = messages.Headers([Number(0)]);
|
||||||
|
}).should.throw('First argument is expected to be an array');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('MerkleBlock', function() {
|
describe('MerkleBlock', function() {
|
||||||
|
|
||||||
it('should return null buffer for payload', function() {
|
it('should return null buffer for payload', function() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user