Skip to content

Commit

Permalink
handle_inv tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maraoz committed Jan 16, 2014
1 parent 8c2e118 commit 1df72a8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
1 change: 0 additions & 1 deletion .jshintrc
Expand Up @@ -32,7 +32,6 @@
"afterEach",
"it",
"inject",
"expect",
"$",
"io",
"app",
Expand Down
6 changes: 6 additions & 0 deletions lib/PeerSync.js
Expand Up @@ -111,6 +111,12 @@ function spec() {

peerman.start();
};

PeerSync.prototype.close = function() {
this.sync.close();
};


return PeerSync;

}
Expand Down
8 changes: 4 additions & 4 deletions lib/Sync.js
Expand Up @@ -266,7 +266,7 @@ function spec() {
this.rpc = new RpcClient(config.bitcoind);


if (!(opts && opts.skip_db_connection)) {
if (!(opts && opts.skip_db_connection) && !mongoose.connection) {
mongoose.connect(config.db, {server: {auto_reconnect: true}} );
}
this.opts = opts;
Expand Down Expand Up @@ -364,8 +364,9 @@ function spec() {
sync();
}, retry_secs * 1000);
}
else
return next(err, that.block_count);
else {
return next(err, that.block_count);
}
});
}

Expand All @@ -377,7 +378,6 @@ function spec() {
};

Sync.prototype.close = function() {
console.log("closing connection");
this.db.close();
};
return Sync;
Expand Down
34 changes: 26 additions & 8 deletions test/lib/PeerSync.js
@@ -1,21 +1,39 @@
'use strict';
var assert = require('assert');
var chai = require('chai'),
expect = chai.expect,
sinon = require('sinon');

var PeerSync = require('../../lib/PeerSync.js').class();
describe('Unit testing PeerSync', function() {
var ps;
describe('PeerSync', function() {
var ps, inv_info;
beforeEach(function() {
ps = new PeerSync();
ps.init();
});
afterEach(function(){
ps.close();
});
describe('#init()', function() {
it('should return with no errors', function() {
assert.doesNotThrow(function() {
ps.init();
});
var other_ps = new PeerSync();
expect(other_ps.init.bind(other_ps)).not.to.throw(Error);
other_ps.close();
});
});
describe('#handle_inv()', function() {
it('should return with no errors');
it('should call sendGetData');
inv_info = {
message: {invs: []},
conn: {sendGetData: sinon.spy()}
};
it('should return with no errors', function(){
expect(function() {
ps.handle_inv(inv_info);
}).not.to.throw(Error);
});
it('should call sendGetData', function() {
ps.handle_inv(inv_info);
expect(inv_info.conn.calledOnce);
});
});
describe('#handle_tx()', function() {
it('should call storeTxs');
Expand Down

0 comments on commit 1df72a8

Please sign in to comment.