From d63c1171db70ce8f885d5cd1d51ae95b06c90620 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Thu, 12 Mar 2015 00:37:15 -0400 Subject: [PATCH] added test for inventory fromBufferReader --- lib/inventory.js | 6 +++--- test/inventory.js | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) 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); + }); + }); + });