diff --git a/lib/inventory.js b/lib/inventory.js index 111000a..ba6b19e 100644 --- a/lib/inventory.js +++ b/lib/inventory.js @@ -59,10 +59,10 @@ Inventory.fromBuffer = function(payload) { return new Inventory(obj); }; -Inventory.fromBufferWriter = function(bw) { +Inventory.fromBufferReader = function(br) { var obj = {}; - obj.type = bw.readUInt32LE(); - obj.hash = bw.read(32); + obj.type = br.readUInt32LE(); + obj.hash = br.read(32); return new Inventory(obj); }; diff --git a/test/inventory.js b/test/inventory.js index ef9add8..e269f13 100644 --- a/test/inventory.js +++ b/test/inventory.js @@ -9,6 +9,7 @@ var P2P = require('../'); var Inventory = P2P.Inventory; var BufferUtils = bitcore.util.buffer; var BufferWriter = bitcore.encoding.BufferWriter; +var BufferReader = bitcore.encoding.BufferReader; describe('Inventory', function() { @@ -93,4 +94,14 @@ describe('Inventory', function() { }); }); + describe('#fromBufferWriter', function() { + it('deserialize from a buffer reader', function() { + var bw = new BufferReader(inventoryBuffer); + var inventory = Inventory.fromBufferReader(bw); + should.exist(inventory); + inventory.type.should.equal(Inventory.TYPE.TX); + inventory.hash.should.deep.equal(hash); + }); + }); + });