Browse Source

add test that exposes bug

patch-2
Manuel Araoz 10 years ago
parent
commit
722eddb894
  1. 3
      lib/block/block.js
  2. 8
      lib/encoding/bufferreader.js
  3. 8
      test/block.js

3
lib/block/block.js

@ -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));
};
/**

8
lib/encoding/bufferreader.js

@ -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');
}
};

8
test/block.js

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save