mirror of https://github.com/BTCPrivate/copay.git
Fixes: tests. Added karma and mocha tests.
This commit is contained in:
parent
801e746d11
commit
8ad1fa7b02
|
@ -75,14 +75,16 @@ angular.module('copayApp.controllers').controller('SidebarController',
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.checkIfWarning = function() {
|
$scope.checkIfWarning = function() {
|
||||||
if (!$rootScope.wallet.isLocked) {
|
if ($rootScope.wallet && !$rootScope.wallet.isLocked) {
|
||||||
controllerUtils.redirIfLogged();
|
controllerUtils.redirIfLogged();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.ignoreLocked = function() {
|
$scope.ignoreLocked = function() {
|
||||||
|
if ($rootScope.wallet) {
|
||||||
$rootScope.wallet.isLocked = false;
|
$rootScope.wallet.isLocked = false;
|
||||||
controllerUtils.redirIfLogged();
|
controllerUtils.redirIfLogged();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -43,6 +43,7 @@ function Wallet(opts) {
|
||||||
|
|
||||||
this.id = opts.id || Wallet.getRandomId();
|
this.id = opts.id || Wallet.getRandomId();
|
||||||
this.name = opts.name;
|
this.name = opts.name;
|
||||||
|
this.isLocked = false;
|
||||||
|
|
||||||
this.verbose = opts.verbose;
|
this.verbose = opts.verbose;
|
||||||
this.publicKeyRing.walletId = this.id;
|
this.publicKeyRing.walletId = this.id;
|
||||||
|
@ -431,7 +432,6 @@ Wallet.prototype.netStart = function(callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var net = this.network;
|
var net = this.network;
|
||||||
|
|
||||||
this._checkLocked();
|
|
||||||
|
|
||||||
net.removeAllListeners();
|
net.removeAllListeners();
|
||||||
net.on('connect', self._handleConnect.bind(self));
|
net.on('connect', self._handleConnect.bind(self));
|
||||||
|
@ -464,6 +464,7 @@ Wallet.prototype.netStart = function(callback) {
|
||||||
self.scheduleConnect();
|
self.scheduleConnect();
|
||||||
self.emit('txProposalsUpdated');
|
self.emit('txProposalsUpdated');
|
||||||
}, 10);
|
}, 10);
|
||||||
|
self._checkLocked();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1017,6 +1018,9 @@ Wallet.prototype.indexDiscovery = function(start, change, cosigner, gap, cb) {
|
||||||
|
|
||||||
Wallet.prototype.disconnect = function() {
|
Wallet.prototype.disconnect = function() {
|
||||||
this.log('## DISCONNECTING');
|
this.log('## DISCONNECTING');
|
||||||
|
if (!this.isLocked) {
|
||||||
|
this.closeIfOpen();
|
||||||
|
}
|
||||||
this.network.disconnect();
|
this.network.disconnect();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,6 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
|
|
||||||
root.logout = function() {
|
root.logout = function() {
|
||||||
if (!$rootScope.wallet.isLocked) {
|
|
||||||
$rootScope.wallet.closeIfOpen();
|
|
||||||
}
|
|
||||||
Socket.removeAllListeners();
|
Socket.removeAllListeners();
|
||||||
|
|
||||||
$rootScope.wallet = null;
|
$rootScope.wallet = null;
|
||||||
|
|
|
@ -27,6 +27,18 @@ FakeStorage.prototype.getLastOpened = function() {
|
||||||
return this.storage['lastOpened'];
|
return this.storage['lastOpened'];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
FakeStorage.prototype.setIsOpen = function(id) {
|
||||||
|
this.storage[id + '::isOpen'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
FakeStorage.prototype.getIsOpen = function(id) {
|
||||||
|
return this.storage[id + '::isOpen'];
|
||||||
|
}
|
||||||
|
|
||||||
|
FakeStorage.prototype.removeIsOpen = function(id) {
|
||||||
|
delete this[id + '::isOpen'];
|
||||||
|
}
|
||||||
|
|
||||||
FakeStorage.prototype.removeGlobal = function(id) {
|
FakeStorage.prototype.removeGlobal = function(id) {
|
||||||
delete this.storage[id];
|
delete this.storage[id];
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,6 +4,7 @@ var FakeWallet = function() {
|
||||||
this.safeBalance = 1000;
|
this.safeBalance = 1000;
|
||||||
this.totalCopayers = 2;
|
this.totalCopayers = 2;
|
||||||
this.requiredCopayers = 2;
|
this.requiredCopayers = 2;
|
||||||
|
this.isLocked = false;
|
||||||
this.balanceByAddr = {
|
this.balanceByAddr = {
|
||||||
'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC': 1000
|
'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC': 1000
|
||||||
};
|
};
|
||||||
|
|
|
@ -1022,6 +1022,14 @@ describe('Wallet model', function() {
|
||||||
w.netStart();
|
w.netStart();
|
||||||
w.network.start.getCall(0).args[0].privkey.length.should.equal(64);
|
w.network.start.getCall(0).args[0].privkey.length.should.equal(64);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should check if wallet is already opened', function() {
|
||||||
|
var w = createW();
|
||||||
|
w._checkLocked();
|
||||||
|
w.isLocked.should.equal(false);
|
||||||
|
w._checkLocked();
|
||||||
|
w.isLocked.should.equal(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#forceNetwork in config', function() {
|
describe('#forceNetwork in config', function() {
|
||||||
|
|
|
@ -288,8 +288,10 @@ describe("Unit: Controllers", function() {
|
||||||
describe("Unit: Sidebar Controller", function() {
|
describe("Unit: Sidebar Controller", function() {
|
||||||
var rootScope;
|
var rootScope;
|
||||||
beforeEach(inject(function($controller, $rootScope) {
|
beforeEach(inject(function($controller, $rootScope) {
|
||||||
rootScope = $rootScope;
|
|
||||||
scope = $rootScope.$new();
|
scope = $rootScope.$new();
|
||||||
|
rootScope = $rootScope;
|
||||||
|
rootScope.wallet = new FakeWallet(config);
|
||||||
|
|
||||||
headerCtrl = $controller('SidebarController', {
|
headerCtrl = $controller('SidebarController', {
|
||||||
$scope: scope,
|
$scope: scope,
|
||||||
});
|
});
|
||||||
|
@ -301,6 +303,11 @@ describe("Unit: Controllers", function() {
|
||||||
expect(array.length).equal(n);
|
expect(array.length).equal(n);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should ignore if wallet is locked', function() {
|
||||||
|
scope.ignoreLocked();
|
||||||
|
expect(rootScope.wallet.isLocked).equal(false);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Send Controller', function() {
|
describe('Send Controller', function() {
|
||||||
|
|
Loading…
Reference in New Issue