Skip to content

Commit

Permalink
Fix bug in Request.getPayload()
Browse files Browse the repository at this point in the history
Apparently, node v0.12 buffer.writeUInt8 is more lenient than v0.10
  • Loading branch information
smh committed Dec 15, 2015
1 parent 6a88aaa commit 0ea205d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/messages/commands/reject.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ RejectMessage.prototype.getPayload = function() {
var bw = new BufferWriter();
bw.writeVarintNum(this.message.length);
bw.write(new Buffer(this.message, 'utf-8'));
bw.writeUInt8(this.cccode);
bw.writeUInt8(this.ccode);
bw.writeVarintNum(this.reason.length);
bw.write(new Buffer(this.reason, 'utf-8'));
bw.write(this.data);
Expand Down
20 changes: 20 additions & 0 deletions test/messages/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,26 @@ describe('Command Messages', function() {
expect(message.reason).to.be.undefined;
expect(message.data).to.be.undefined;
});
it('should write payload correctly', function() {
var message = messages.Reject({
message: 'tx',
ccode: 0x01,
reason: 'transaction is malformed',
data: new Buffer('12345678901234567890123456789012', 'hex')
});
var payload = message.getPayload();
message = messages.Reject();
message.setPayload(payload);
message.message.should.equal('tx');
message.ccode.should.equal(0x01);
message.reason.should.equal('transaction is malformed');
message.data.toString('hex').should.equal('12345678901234567890123456789012');
//var message = messages.Reject();
//expect(message.message).to.be.undefined;
//expect(message.ccode).to.be.undefined;
//expect(message.reason).to.be.undefined;
//expect(message.data).to.be.undefined;
});
});

describe('Version', function() {
Expand Down

0 comments on commit 0ea205d

Please sign in to comment.