check for timestamp out of bounds
This commit is contained in:
parent
7e1d433781
commit
a0be38f074
|
@ -209,9 +209,16 @@ DB.prototype.getBlockHashesByTimestamp = function(high, low, callback) {
|
|||
var self = this;
|
||||
var hashes = [];
|
||||
|
||||
try {
|
||||
var lowKey = this._encodeBlockIndexKey(low);
|
||||
var highKey = this._encodeBlockIndexKey(high);
|
||||
} catch(e) {
|
||||
return callback(e);
|
||||
}
|
||||
|
||||
var stream = this.store.createReadStream({
|
||||
gte: this._encodeBlockIndexKey(low),
|
||||
lte: this._encodeBlockIndexKey(high),
|
||||
gte: lowKey,
|
||||
lte: highKey,
|
||||
reverse: true,
|
||||
valueEncoding: 'binary',
|
||||
keyEncoding: 'binary'
|
||||
|
@ -456,6 +463,7 @@ DB.prototype.runAllBlockHandlers = function(block, add, callback) {
|
|||
};
|
||||
|
||||
DB.prototype._encodeBlockIndexKey = function(timestamp) {
|
||||
$.checkArgument(timestamp >= 0 && timestamp <= 4294967295, 'timestamp out of bounds');
|
||||
var timestampBuffer = new Buffer(4);
|
||||
timestampBuffer.writeUInt32BE(timestamp);
|
||||
return Buffer.concat([DB.PREFIXES.BLOCKS, timestampBuffer]);
|
||||
|
|
|
@ -423,6 +423,20 @@ describe('DB Service', function() {
|
|||
|
||||
readStream.emit('close');
|
||||
});
|
||||
|
||||
it('should give an error if the timestamp is out of range', function(done) {
|
||||
var db = new DB(baseConfig);
|
||||
var readStream = new EventEmitter();
|
||||
db.store = {
|
||||
createReadStream: sinon.stub().returns(readStream)
|
||||
};
|
||||
|
||||
db.getBlockHashesByTimestamp(-1, -5, function(err, hashes) {
|
||||
should.exist(err);
|
||||
err.message.should.equal('Invalid Argument: timestamp out of bounds');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getPrevHash', function() {
|
||||
|
|
Loading…
Reference in New Issue