Browse Source

Transport/Pool: Use sinon for tests.

patch-2
Braydon Fuller 10 years ago
parent
commit
e04cb76854
  1. 9
      lib/transport/pool.js
  2. 1
      package.json
  3. 13
      test/transport/pool.js

9
lib/transport/pool.js

@ -28,15 +28,10 @@ function now(){
* @returns {Pool}
* @constructor
*/
function Pool(network, options) {
function Pool(network) {
var self = this;
if (!options) {
options = {};
}
this.dns = options.dns || dns;
this.network = Networks.get(network) || Networks.defaultNetwork;
this.connectedPeers = [];
this.addrs = [];
@ -246,7 +241,7 @@ Pool.prototype.addAddr = function addAddr(addr) {
*/
Pool.prototype.addAddrsFromSeed = function addAddrsFromSeed(seed, done) {
var self = this;
this.dns.resolve(seed, function(err, ips) {
dns.resolve(seed, function(err, ips) {
if (err) {
self.emit('error', err);
return done();

1
package.json

@ -98,6 +98,7 @@
"gulp-shell": "^0.2.10",
"mocha": "~2.0.1",
"run-sequence": "^1.0.2",
"sinon": "^1.12.2",
"karma": "^0.12.28",
"karma-firefox-launcher": "^0.1.3",
"karma-mocha": "^0.1.9"

13
test/transport/pool.js

@ -10,6 +10,9 @@ if (typeof(window) === 'undefined'){
var should = chai.should();
var expect = chai.expect;
var dns = require('dns');
var sinon = require('sinon');
var bitcore = require('../..');
var Peer = bitcore.transport.Peer;
var Pool = bitcore.transport.Pool;
@ -28,14 +31,14 @@ if (typeof(window) === 'undefined'){
});
it('should discover peers via dns', function() {
// mock dns
var dns = function() {};
dns.resolve = function(seed, callback){
var stub = sinon.stub(dns, 'resolve', function(seed, callback){
callback(null, ['10.10.10.1', '10.10.10.2', '10.10.10.3']);
};
var pool = new Pool(Networks.livenet, {dns: dns});
});
var pool = new Pool(Networks.livenet);
pool.connect();
pool.addrs.length.should.equal(3);
stub.restore();
});
it('should not discover peers via dns', function() {

Loading…
Cancel
Save