added default options for all command messages, and added tests
This commit is contained in:
parent
4ecb34e123
commit
a8b8c59069
@ -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;
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -14,7 +14,6 @@ function VerackMessage(options) {
|
||||
if(!options) {
|
||||
options = {};
|
||||
}
|
||||
|
||||
Message.call(this, options);
|
||||
this.magicNumber = magicNumber;
|
||||
this.command = 'verack';
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -51,7 +51,6 @@ describe('Messages Builder', function() {
|
||||
message.toBuffer().should.deep.equal(expectedBuffer);
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -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' +
|
||||
|
||||
Loading…
Reference in New Issue
Block a user