diff --git a/integration/bitcoind.js b/integration/bitcoind.js index 279141c..93a4562 100644 --- a/integration/bitcoind.js +++ b/integration/bitcoind.js @@ -159,7 +159,7 @@ describe('Integration with ' + network.name + ' bitcoind', function() { }); var from = [blockHash[network.name]]; var stop = stopBlock[network.name]; - it('gets headers', function(cb) { + it.only('gets headers', function(cb) { connect(function(peer) { peer.once('headers', function(message) { (message instanceof Messages.Headers).should.equal(true); diff --git a/lib/messages.js b/lib/messages.js index 90d883c..0ec22e4 100644 --- a/lib/messages.js +++ b/lib/messages.js @@ -169,6 +169,13 @@ Message.prototype.serialize = function(network) { return message.buffer(); }; +/** + * check if parser has no more extra data + */ +Message.prototype._checkFinished = function(parser) { + $.checkState(parser.finished(), 'data still available after parsing ' + this.constructor.name); +}; + module.exports.Message = Message; /** @@ -254,7 +261,7 @@ Version.prototype.fromBuffer = function(payload) { */ this.relay = !!parser.readUInt8(); - $.checkState(parser.finished()); + this._checkFinished(parser); return this; }; @@ -336,7 +343,7 @@ Inventory.prototype.fromBuffer = function(payload) { this.inventory.push(Inventory.forItem(type, hash)); } - $.checkState(parser.finished()); + this._checkFinished(parser); return this; }; @@ -420,7 +427,8 @@ util.inherits(Ping, Message); Ping.prototype.fromBuffer = function(payload) { var parser = new BufferReader(payload); this.nonce = parser.read(8); - $.checkState(parser.finished()); + + this._checkFinished(parser); return this; }; @@ -532,7 +540,7 @@ Addresses.prototype.fromBuffer = function(payload) { this.addresses.push(addr); } - $.checkState(parser.finished()); + this._checkFinished(parser); return this; }; @@ -607,7 +615,7 @@ Alert.prototype.fromBuffer = function(payload) { var parser = new BufferReader(payload); this.payload = parser.readVarLengthBuffer(); this.signature = parser.readVarLengthBuffer(); - $.checkState(parser.finished()); + this._checkFinished(parser); return this; }; @@ -651,7 +659,7 @@ Headers.prototype.fromBuffer = function(payload) { var header = BlockHeaderModel.fromBufferReader(parser); this.headers.push(header); } - $.checkState(parser.finished()); + this._checkFinished(parser); return this; }; @@ -777,7 +785,7 @@ GetBlocks.prototype.fromBuffer = function(payload) { this.starts.push(parser.read(32)); } this.stop = parser.read(32); - $.checkState(parser.finished()); + this._checkFinished(parser); return this; };