Add tests

This commit is contained in:
Yemel Jardi 2014-12-10 17:43:56 -03:00
parent 2d4b26a6a1
commit 228e7e214a
2 changed files with 390 additions and 5 deletions

View File

@ -48,6 +48,9 @@ var parseMessage = function(network, dataBuffer) {
return;
}
console.log(command, 'FULL MESSAGE', dataBuffer.slice(0, messageLength).toString('hex'));
console.log(command, 'PAYLOAD MESSAGE', payload.toString('hex'));
dataBuffer.skip(messageLength);
return Message.buildMessage(command, payload);
};
@ -165,7 +168,7 @@ Version.prototype.fromBuffer = function(payload) {
this.addr_me = parser.read(26);
this.addr_you = parser.read(26);
this.nonce = parser.read(8);
this.subversion = parser.readVarintBuf();
this.subversion = parser.readVarintBuf().toString();
this.start_height = parser.readUInt32LE();
return this;
@ -217,8 +220,8 @@ Inventory.prototype.getPayload = function() {
put.varint(this.inventory.length);
this.inventory.forEach(function(value) {
value instanceof Block ? put.word32le(2) : put.word32le(1);
put.put(value.getHash());
put.word32le(value.type);
put.put(value.hash);
});
return put.buffer();
@ -272,7 +275,7 @@ function Pong(nonce) {
}
util.inherits(Pong, Ping);
module.exports.Pong = Pong;
module.exports.Pong = Message.COMMANDS['pong'] = Pong;
/**
* Addr Message
@ -358,8 +361,10 @@ module.exports.Reject = Message.COMMANDS['reject'] = Reject;
* Alert Message
*
*/
function Alert() {
function Alert(payload, signature) {
this.command = 'alert';
this.payload = payload || new Buffer(32);
this.signature = signature || new Buffer(32);
}
util.inherits(Alert, Message);

380
test/transport/messages.js Normal file

File diff suppressed because one or more lines are too long