added tests for pool _addConnectedPeer
This commit is contained in:
parent
3b53593288
commit
97f39db081
52
test/pool.js
52
test/pool.js
@ -336,6 +336,33 @@ describe('Pool', function() {
|
|||||||
pool.connect();
|
pool.connect();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#_addConnectedPeer', function() {
|
||||||
|
|
||||||
|
it('should add a peer', function() {
|
||||||
|
/* jshint sub: true */
|
||||||
|
var pool = new Pool({network: Networks.livenet, maxSize: 1});
|
||||||
|
pool._addPeerEventHandlers = sinon.stub();
|
||||||
|
pool._addConnectedPeer({
|
||||||
|
on: sinon.stub()
|
||||||
|
}, {hash: 'hash'});
|
||||||
|
should.exist(pool._connectedPeers['hash']);
|
||||||
|
pool._addPeerEventHandlers.calledOnce.should.equal(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not already added peer', function() {
|
||||||
|
/* jshint sub: true */
|
||||||
|
var pool = new Pool({network: Networks.livenet, maxSize: 1});
|
||||||
|
pool._addPeerEventHandlers = sinon.stub();
|
||||||
|
pool._connectedPeers['hash'] = {};
|
||||||
|
pool._addConnectedPeer({
|
||||||
|
on: sinon.stub()
|
||||||
|
}, {hash: 'hash'});
|
||||||
|
should.exist(pool._connectedPeers['hash']);
|
||||||
|
pool._addPeerEventHandlers.calledOnce.should.equal(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('#listen', function() {
|
describe('#listen', function() {
|
||||||
|
|
||||||
it('create a server', function(done) {
|
it('create a server', function(done) {
|
||||||
@ -376,6 +403,31 @@ describe('Pool', function() {
|
|||||||
pool.listen();
|
pool.listen();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle an ipv4 connection', function(done) {
|
||||||
|
var ipv4 = '127.0.0.1';
|
||||||
|
sinon.stub(net, 'createServer', function(callback) {
|
||||||
|
callback({
|
||||||
|
remoteAddress: ipv4
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
listen: sinon.stub()
|
||||||
|
};
|
||||||
|
});
|
||||||
|
sinon.stub(net, 'isIPv6', function() {
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
var pool = new Pool({network: Networks.livenet, maxSize: 1});
|
||||||
|
pool._addAddr = function(addr) {
|
||||||
|
should.exist(addr.ip.v4);
|
||||||
|
addr.ip.v4.should.equal(ipv4);
|
||||||
|
net.isIPv6.restore();
|
||||||
|
net.createServer.restore();
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
pool._addConnectedPeer = sinon.stub();
|
||||||
|
pool.listen();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user