add new tests for new reconnect feature

This commit is contained in:
Manuel Araoz 2014-06-03 13:07:31 -03:00
commit 86016de19d
2 changed files with 98 additions and 56 deletions

View file

@ -7,8 +7,14 @@ function Network(opts) {
Network.parent=EventEmitter;
Network.prototype.start = function(openCallback, opts) {
Network.prototype.start = function(opts, cb) {
// start! :D
this.peer = {
options: {
token: "asd"
}
};
if (cb) cb();
};
Network.prototype.send = function(peerIds, data, cb) {
@ -24,4 +30,16 @@ Network.prototype.disconnect = function(cb) {
// disconect :c
};
Network.prototype.lockIncommingConnections = function() {
};
Network.prototype.getPeer = function() {
};
Network.prototype.connectToCopayers = function(cps) {
};
Network.prototype.isOnline = function() {
return true;
};
module.exports = require('soop')(Network);

View file

@ -2,6 +2,7 @@
var chai = chai || require('chai');
var should = chai.should();
var sinon = require('sinon');
var copay = copay || require('../copay');
var Wallet = require('../js/models/core/Wallet');
var Storage = require('./mocks/FakeStorage');
@ -29,14 +30,19 @@ describe('Wallet model', function() {
};
it('should fail to create an instance', function() {
(function(){new Wallet(config)}).should.throw();
(function() {
new Wallet(config)
}).should.
throw ();
});
var createW = function(netKey) {
var c = JSON.parse(JSON.stringify(config));
if (netKey) c.netKey = netKey;
c.privateKey = new copay.PrivateKey({ networkName: c.networkName });
c.privateKey = new copay.PrivateKey({
networkName: c.networkName
});
c.publicKeyRing = new copay.PublicKeyRing({
networkName: c.networkName,
@ -83,16 +89,14 @@ describe('Wallet model', function() {
w.publicKeyRing.isComplete().should.equal(true);
});
var unspentTest = [
{
var unspentTest = [{
"address": "dummy",
"scriptPubKey": "dummy",
"txid": "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1",
"vout": 1,
"amount": 10,
"confirmations": 7
}
];
}];
var createW2 = function(privateKeys) {
var netKey = 'T0FbU2JLby0=';
@ -148,7 +152,9 @@ describe('Wallet model', function() {
for (var i = 0; i < l.length; i++)
w.addressIsOwn(l[i]).should.equal(true);
w.addressIsOwn(l[0], {excludeMain:true}).should.equal(false);
w.addressIsOwn(l[0], {
excludeMain: true
}).should.equal(false);
w.addressIsOwn('mmHqhvTVbxgJTnePa7cfweSRjBCy9bQQXJ').should.equal(false);
w.addressIsOwn('mgtUfP9sTJ6vPLoBxZLPEccGpcjNVryaCX').should.equal(false);
@ -212,8 +218,26 @@ describe('Wallet model', function() {
});
it('decodeSecret check', function() {
(function(){Wallet.decodeSecret('4fp61K187CsYmjoRQC5iAdC5eGmbCRsAAXfwEwetSQgHvZs27eWKaLaNHRoKM');}).should.not.throw();
(function(){Wallet.decodeSecret('4fp61K187CsYmjoRQC5iAdC5eGmbCRsAAXfwEwetSQgHvZs27eWKaLaNHRoK');}).should.throw();
(function(){Wallet.decodeSecret('12345');}).should.throw();
(function() {
Wallet.decodeSecret('4fp61K187CsYmjoRQC5iAdC5eGmbCRsAAXfwEwetSQgHvZs27eWKaLaNHRoKM');
}).should.not.
throw ();
(function() {
Wallet.decodeSecret('4fp61K187CsYmjoRQC5iAdC5eGmbCRsAAXfwEwetSQgHvZs27eWKaLaNHRoK');
}).should.
throw ();
(function() {
Wallet.decodeSecret('12345');
}).should.
throw ();
});
it('call reconnect after interval', function(done) {
var w = createW2();
var spy = sinon.spy(w, 'scheduleConnect');
w.netStart();
setTimeout(function() {
sinon.assert.callCount(spy, 10);
done();
}, 1000);
});
});