added default options for all command messages, and added tests

This commit is contained in:
Braydon Fuller 2015-03-13 12:50:55 -04:00
parent 4ecb34e123
commit a8b8c59069
21 changed files with 69 additions and 2 deletions

View File

@ -13,6 +13,9 @@ function AddrMessage(options) {
if (!(this instanceof AddrMessage)) {
return new AddrMessage(options);
}
if(!options) {
options = {};
}
Message.call(this, options);
this.command = 'addr';
this.magicNumber = magicNumber;

View File

@ -13,6 +13,9 @@ function AlertMessage(options) {
if (!(this instanceof AlertMessage)) {
return new AlertMessage(options);
}
if(!options) {
options = {};
}
Message.call(this, options);
this.magicNumber = magicNumber;
this.command = 'alert';

View File

@ -11,6 +11,9 @@ function BlockMessage(options) {
if (!(this instanceof BlockMessage)) {
return new BlockMessage(options);
}
if(!options) {
options = {};
}
Message.call(this, options);
this.command = 'block';
this.magicNumber = magicNumber;

View File

@ -21,6 +21,9 @@ function FilteraddMessage(options) {
if (!(this instanceof FilteraddMessage)) {
return new FilteraddMessage(options);
}
if(!options) {
options = {};
}
Message.call(this, options);
this.magicNumber = magicNumber;
this.command = 'filteradd';

View File

@ -11,6 +11,9 @@ function FilterclearMessage(options) {
if (!(this instanceof FilterclearMessage)) {
return new FilterclearMessage(options);
}
if(!options) {
options = {};
}
Message.call(this, options);
this.magicNumber = magicNumber;
this.command = 'filterclear';

View File

@ -14,6 +14,9 @@ function FilterloadMessage(options) {
if (!(this instanceof FilterloadMessage)) {
return new FilterloadMessage(options);
}
if(!options) {
options = {};
}
Message.call(this, options);
this.magicNumber = magicNumber;
this.command = 'filterload';

View File

@ -23,6 +23,9 @@ function GetblocksMessage(options) {
if (!(this instanceof GetblocksMessage)) {
return new GetblocksMessage(options);
}
if(!options) {
options = {};
}
Message.call(this, options);
this.command = 'getblocks';
this.version = protocolVersion;

View File

@ -15,6 +15,9 @@ function GetdataMessage(options) {
if (!(this instanceof GetdataMessage)) {
return new GetdataMessage(options);
}
if(!options) {
options = {};
}
Message.call(this, options);
this.command = 'getdata';
this.magicNumber = magicNumber;

View File

@ -21,6 +21,9 @@ function GetheadersMessage(options) {
if (!(this instanceof GetheadersMessage)) {
return new GetheadersMessage(options);
}
if(!options) {
options = {};
}
Message.call(this, options);
this.command = 'getheaders';
this.version = protocolVersion;

View File

@ -21,6 +21,9 @@ function HeadersMessage(options) {
if (!(this instanceof HeadersMessage)) {
return new HeadersMessage(options);
}
if(!options) {
options = {};
}
Message.call(this, options);
this.magicNumber = magicNumber;
this.command = 'headers';

View File

@ -15,6 +15,9 @@ function InvMessage(options) {
if (!(this instanceof InvMessage)) {
return new InvMessage(options);
}
if(!options) {
options = {};
}
Message.call(this, options);
this.command = 'inv';
this.magicNumber = magicNumber;

View File

@ -11,6 +11,9 @@ function MempoolMessage(options) {
if (!(this instanceof MempoolMessage)) {
return new MempoolMessage(options);
}
if(!options) {
options = {};
}
Message.call(this, options);
this.magicNumber = magicNumber;
this.command = 'mempool';

View File

@ -20,6 +20,9 @@ function MerkleblockMessage(options) {
if (!(this instanceof MerkleblockMessage)) {
return new MerkleblockMessage(options);
}
if(!options) {
options = {};
}
Message.call(this, options);
this.magicNumber = magicNumber;
this.command = 'merkleblock';

View File

@ -15,6 +15,9 @@ function NotfoundMessage(options) {
if (!(this instanceof NotfoundMessage)) {
return new NotfoundMessage(options);
}
if(!options) {
options = {};
}
Message.call(this, options);
this.command = 'notfound';
this.magicNumber = magicNumber;

View File

@ -12,6 +12,9 @@ function PongMessage(options) {
if (!(this instanceof PongMessage)) {
return new PongMessage(options);
}
if(!options) {
options = {};
}
Message.call(this, options);
this.command = 'pong';
this.magicNumber = magicNumber;

View File

@ -12,6 +12,9 @@ function RejectMessage(options) {
if (!(this instanceof RejectMessage)) {
return new RejectMessage(options);
}
if(!options) {
options = {};
}
Message.call(this, options);
this.magicNumber = magicNumber;
this.command = 'reject';

View File

@ -11,6 +11,9 @@ function TransactionMessage(options) {
if (!(this instanceof TransactionMessage)) {
return new TransactionMessage(options);
}
if(!options) {
options = {};
}
Message.call(this, options);
this.command = 'tx';
this.magicNumber = magicNumber;

View File

@ -14,7 +14,6 @@ function VerackMessage(options) {
if(!options) {
options = {};
}
Message.call(this, options);
this.magicNumber = magicNumber;
this.command = 'verack';

View File

@ -9,6 +9,9 @@ var Hash = bitcore.crypto.Hash;
* `getPayload` method to modify the message payload.
*/
function Message(options) {
if(!options) {
options = {};
}
this.command = options.command;
this.magicNumber = options.magicNumber;
}

View File

@ -51,7 +51,6 @@ describe('Messages Builder', function() {
message.toBuffer().should.deep.equal(expectedBuffer);
done();
});
});
});

View File

@ -33,6 +33,21 @@ describe('Messages', function() {
});
});
describe('@constructor for all command messages', function() {
var messages = new Messages();
Object.keys(messages.builder.commandsMap).forEach(function(command) {
var name = messages.builder.commandsMap[command];
it('message.' + name, function(done) {
should.exist(messages[name]);
messages[name].super_.should.equal(Messages.Message);
var message = messages[name]();
should.exist(message);
message.should.be.instanceof(messages[name]);
done();
});
});
});
describe('#parseBuffer', function() {
it('fails with invalid command', function() {
var invalidCommand = 'f9beb4d96d616c6963696f757300000025000000bd5e830c' +