add test that exposes bug

This commit is contained in:
Manuel Araoz 2015-04-29 15:31:46 -03:00
parent 25eaae2b45
commit 722eddb894
3 changed files with 16 additions and 3 deletions

View File

@ -118,6 +118,7 @@ Block._fromBufferReader = function _fromBufferReader(br) {
* @returns {Block} - An instance of block
*/
Block.fromBufferReader = function fromBufferReader(br) {
$.checkArgument(br, 'br is required');
var info = Block._fromBufferReader(br);
return new Block(info);
};
@ -127,7 +128,7 @@ Block.fromBufferReader = function fromBufferReader(br) {
* @returns {Block} - An instance of block
*/
Block.fromBuffer = function fromBuffer(buf) {
return Block.fromBufferReader(BufferReader(buf));
return Block.fromBufferReader(new BufferReader(buf));
};
/**

View File

@ -13,9 +13,15 @@ var BufferReader = function BufferReader(buf) {
this.set({
buf: buf
});
} else if (buf) {
} else if (_.isString(buf)) {
this.set({
buf: new Buffer(buf, 'hex'),
});
} else if (_.isObject(buf)) {
var obj = buf;
this.set(obj);
} else {
throw new TypeError('Unrecognized argument for BufferReader');
}
};

File diff suppressed because one or more lines are too long