added test for inventory fromBufferReader
This commit is contained in:
parent
7e29af4542
commit
d63c1171db
@ -59,10 +59,10 @@ Inventory.fromBuffer = function(payload) {
|
|||||||
return new Inventory(obj);
|
return new Inventory(obj);
|
||||||
};
|
};
|
||||||
|
|
||||||
Inventory.fromBufferWriter = function(bw) {
|
Inventory.fromBufferReader = function(br) {
|
||||||
var obj = {};
|
var obj = {};
|
||||||
obj.type = bw.readUInt32LE();
|
obj.type = br.readUInt32LE();
|
||||||
obj.hash = bw.read(32);
|
obj.hash = br.read(32);
|
||||||
return new Inventory(obj);
|
return new Inventory(obj);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,7 @@ var P2P = require('../');
|
|||||||
var Inventory = P2P.Inventory;
|
var Inventory = P2P.Inventory;
|
||||||
var BufferUtils = bitcore.util.buffer;
|
var BufferUtils = bitcore.util.buffer;
|
||||||
var BufferWriter = bitcore.encoding.BufferWriter;
|
var BufferWriter = bitcore.encoding.BufferWriter;
|
||||||
|
var BufferReader = bitcore.encoding.BufferReader;
|
||||||
|
|
||||||
describe('Inventory', function() {
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user