From 81047d73bde8f3e6846403827eb8658c5b7cfbce Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Wed, 1 Apr 2015 11:59:17 -0400 Subject: [PATCH] Added preconditions to filteradd message. --- lib/messages/commands/filteradd.js | 5 +++++ test/messages/commands/index.js | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/messages/commands/filteradd.js b/lib/messages/commands/filteradd.js index 1bb9951..4237924 100644 --- a/lib/messages/commands/filteradd.js +++ b/lib/messages/commands/filteradd.js @@ -8,6 +8,7 @@ var BufferUtil = bitcore.util.buffer; var BufferWriter = bitcore.encoding.BufferWriter; var BufferReader = bitcore.encoding.BufferReader; var $ = bitcore.util.preconditions; +var _ = bitcore.deps._; /** * Request peer to add data to a bloom filter already set by 'filterload' @@ -21,6 +22,10 @@ function FilteraddMessage(arg, options) { Message.call(this, arg, options); this.magicNumber = options.magicNumber; this.command = 'filteradd'; + $.checkArgument( + _.isUndefined(arg) || BufferUtil.isBuffer(arg), + 'First argument is expected to be a Buffer or undefined' + ); this.data = arg || BufferUtil.EMPTY_BUFFER; } inherits(FilteraddMessage, Message); diff --git a/test/messages/commands/index.js b/test/messages/commands/index.js index 98edd79..ce0eefd 100644 --- a/test/messages/commands/index.js +++ b/test/messages/commands/index.js @@ -102,6 +102,16 @@ describe('Command Messages', function() { }); + describe('FilterAdd', function() { + + it('should error if arg is not a buffer', function() { + (function() { + var message = messages.FilterAdd('not a buffer'); + }).should.throw('First argument is expected to be a Buffer or undefined'); + }); + + }); + describe('FilterLoad', function() { it('should return a null payload', function() {