add tests

This commit is contained in:
Patrick Nagurny 2015-09-03 16:38:23 -04:00
parent da6b6e3622
commit 900f715a49
3 changed files with 12 additions and 19 deletions

View File

@ -436,19 +436,6 @@ DB.prototype.getHashes = function getHashes(tipHash, callback) {
// Stop at the genesis block
self.cache.chainHashes[tipHash] = hashes;
// Only store 2 chains of hashes in memory
var sorted = Object.keys(self.cache.chainHashes).sort(function(a, b) {
return self.cache.chainHashes[a].length < self.cache.chainHashes[b].length;
});
for(var i = 0; i < sorted.length; i++) {
if(i > 2) {
log.debug('Removing chainHashes ' + sorted[i] + ' ' + (self.cache.chainHashes[sorted[i]].length));
delete self.cache.chainHashes[sorted[i]];
} else {
log.debug('Keeping chainHashes ' + sorted[i] + ' ' + (self.cache.chainHashes[sorted[i]].length));
}
}
callback(null, hashes);
} else if(self.cache.chainHashes[hash]) {
hashes.shift();

View File

@ -75,7 +75,7 @@ describe('#create', function() {
var config = JSON.parse(fs.readFileSync(configPath));
config.name.should.equal('My Node 1');
config.services.should.deep.equal(['address']);
config.services.should.deep.equal(['bitcoind', 'db', 'address', 'web']);
config.datadir.should.equal('./data');
config.network.should.equal('livenet');

View File

@ -39,15 +39,20 @@ describe('WebService', function() {
on: sinon.spy(),
services: {
one: {
setupRoutes: sinon.spy()
setupRoutes: sinon.spy(),
getRoutePrefix: sinon.stub().returns('one')
},
two: {
setupRoutes: sinon.spy()
setupRoutes: sinon.spy(),
getRoutePrefix: sinon.stub().returns('two')
}
}
};
var web = new WebService({node: node});
web.app = {
use: sinon.spy()
};
web.setupAllRoutes();
node.services.one.setupRoutes.callCount.should.equal(1);
@ -104,7 +109,8 @@ describe('WebService', function() {
Module1.prototype.getPublishEvents = function() {
return [
{
name: 'event1'
name: 'event1',
extraEvents: ['event2']
}
];
};
@ -149,13 +155,13 @@ describe('WebService', function() {
});
it('publish events from bus should be emitted from socket', function(done) {
socket.once('event1', function(param1, param2) {
socket.once('event2', function(param1, param2) {
param1.should.equal('param1');
param2.should.equal('param2');
done();
});
socket.connected = true;
bus.emit('event1', 'param1', 'param2');
bus.emit('event2', 'param1', 'param2');
});
it('on disconnect should close bus', function(done) {