Added preconditions to addr message.
This commit is contained in:
parent
81047d73bd
commit
36709faaa9
@ -48,7 +48,7 @@ function builder(options) {
|
||||
headers: 'Headers',
|
||||
notfound: 'NotFound',
|
||||
inv: 'Inventory',
|
||||
addr: 'Address',
|
||||
addr: 'Addresses',
|
||||
alert: 'Alert',
|
||||
reject: 'Reject',
|
||||
merkleblock: 'MerkleBlock',
|
||||
|
||||
@ -4,6 +4,8 @@ var Message = require('../message');
|
||||
var inherits = require('util').inherits;
|
||||
var bitcore = require('bitcore');
|
||||
var utils = require('../utils');
|
||||
var $ = bitcore.util.preconditions;
|
||||
var _ = bitcore.deps._;
|
||||
var BufferReader = bitcore.encoding.BufferReader;
|
||||
var BufferWriter = bitcore.encoding.BufferWriter;
|
||||
|
||||
@ -18,6 +20,14 @@ function AddrMessage(arg, options) {
|
||||
Message.call(this, arg, options);
|
||||
this.command = 'addr';
|
||||
this.magicNumber = options.magicNumber;
|
||||
$.checkArgument(
|
||||
_.isUndefined(arg) ||
|
||||
(Array.isArray(arg) &&
|
||||
!_.isUndefined(arg[0].services) &&
|
||||
!_.isUndefined(arg[0].ip) &&
|
||||
!_.isUndefined(arg[0].port)),
|
||||
'First argument is expected to be an array of addrs'
|
||||
);
|
||||
this.addresses = arg;
|
||||
}
|
||||
inherits(AddrMessage, Message);
|
||||
|
||||
@ -10,6 +10,25 @@ describe('Command Messages', function() {
|
||||
|
||||
var messages = new Messages();
|
||||
|
||||
describe('Addr', function() {
|
||||
|
||||
it('should error if arg is not an array of addrs', function() {
|
||||
(function() {
|
||||
var message = messages.Addresses(['not an addr']);
|
||||
}).should.throw('First argument is expected to be an array of addrs');
|
||||
});
|
||||
|
||||
it('should instantiate with an array of addrs', function() {
|
||||
var message = messages.Addresses([{
|
||||
ip: {
|
||||
v4: 'localhost'
|
||||
},
|
||||
services: 1,
|
||||
port: 1234
|
||||
}]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Alert', function() {
|
||||
|
||||
it('should accept a transaction instance as an argument', function() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user