Skip to content

Commit 1df72a8

Browse files
committed
handle_inv tests
1 parent 8c2e118 commit 1df72a8

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

.jshintrc

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"afterEach",
3333
"it",
3434
"inject",
35-
"expect",
3635
"$",
3736
"io",
3837
"app",

lib/PeerSync.js

+6
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ function spec() {
111111

112112
peerman.start();
113113
};
114+
115+
PeerSync.prototype.close = function() {
116+
this.sync.close();
117+
};
118+
119+
114120
return PeerSync;
115121

116122
}

lib/Sync.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ function spec() {
266266
this.rpc = new RpcClient(config.bitcoind);
267267

268268

269-
if (!(opts && opts.skip_db_connection)) {
269+
if (!(opts && opts.skip_db_connection) && !mongoose.connection) {
270270
mongoose.connect(config.db, {server: {auto_reconnect: true}} );
271271
}
272272
this.opts = opts;
@@ -364,8 +364,9 @@ function spec() {
364364
sync();
365365
}, retry_secs * 1000);
366366
}
367-
else
368-
return next(err, that.block_count);
367+
else {
368+
return next(err, that.block_count);
369+
}
369370
});
370371
}
371372

@@ -377,7 +378,6 @@ function spec() {
377378
};
378379

379380
Sync.prototype.close = function() {
380-
console.log("closing connection");
381381
this.db.close();
382382
};
383383
return Sync;

test/lib/PeerSync.js

+26-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
11
'use strict';
2-
var assert = require('assert');
2+
var chai = require('chai'),
3+
expect = chai.expect,
4+
sinon = require('sinon');
5+
36
var PeerSync = require('../../lib/PeerSync.js').class();
4-
describe('Unit testing PeerSync', function() {
5-
var ps;
7+
describe('PeerSync', function() {
8+
var ps, inv_info;
69
beforeEach(function() {
710
ps = new PeerSync();
11+
ps.init();
12+
});
13+
afterEach(function(){
14+
ps.close();
815
});
916
describe('#init()', function() {
1017
it('should return with no errors', function() {
11-
assert.doesNotThrow(function() {
12-
ps.init();
13-
});
18+
var other_ps = new PeerSync();
19+
expect(other_ps.init.bind(other_ps)).not.to.throw(Error);
20+
other_ps.close();
1421
});
1522
});
1623
describe('#handle_inv()', function() {
17-
it('should return with no errors');
18-
it('should call sendGetData');
24+
inv_info = {
25+
message: {invs: []},
26+
conn: {sendGetData: sinon.spy()}
27+
};
28+
it('should return with no errors', function(){
29+
expect(function() {
30+
ps.handle_inv(inv_info);
31+
}).not.to.throw(Error);
32+
});
33+
it('should call sendGetData', function() {
34+
ps.handle_inv(inv_info);
35+
expect(inv_info.conn.calledOnce);
36+
});
1937
});
2038
describe('#handle_tx()', function() {
2139
it('should call storeTxs');

0 commit comments

Comments
 (0)