Transport/Pool: Use sinon for tests.
This commit is contained in:
parent
1a1d63321a
commit
e04cb76854
|
@ -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();
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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…
Reference in New Issue