mocha test passing on console

This commit is contained in:
Matias Alejo Garcia 2014-08-15 09:57:47 -04:00
commit eb9acb958f
7 changed files with 185 additions and 191 deletions

View file

@ -1670,7 +1670,7 @@ Wallet.prototype.indexDiscovery = function(start, change, cosigner, gap, cb) {
Wallet.prototype.disconnect = function() { Wallet.prototype.disconnect = function() {
this.log('## DISCONNECTING'); this.log('## DISCONNECTING');
this.unlock(); this.lock.release();
this.network.disconnect(); this.network.disconnect();
}; };

View file

@ -170,7 +170,7 @@ WalletFactory.prototype._checkNetwork = function(inNetworkName) {
WalletFactory.prototype.open = function(walletId, passphrase) { WalletFactory.prototype.open = function(walletId, passphrase) {
this.storage._setPassphrase(passphrase); this.storage._setPassphrase(passphrase);
var w = this.read(walletId, opts); var w = this.read(walletId);
if (w) if (w)
w.store(); w.store();

View file

@ -141,7 +141,7 @@ Storage.prototype.getWalletIds = function() {
if (split.length == 2) { if (split.length == 2) {
var walletId = split[0]; var walletId = split[0];
if (walletId === 'nameFor' || walletId === 'lock') if (!walletId || walletId === 'nameFor')
continue; continue;
if (typeof uniq[walletId] === 'undefined') { if (typeof uniq[walletId] === 'undefined') {
@ -190,19 +190,6 @@ Storage.prototype.getLastOpened = function() {
return this.getGlobal('lastOpened'); return this.getGlobal('lastOpened');
} }
// Lock related
Storage.prototype.setLock = function(walletId) {
this.setGlobal(this._key(walletId, 'Lock'), this.sessionId());
}
Storage.prototype.getLock = function(walletId) {
return this.getGlobal(this._key(walletId, 'Lock'));
}
Storage.prototype.removeLock = function(walletId) {
this.removeGlobal(this._key(walletId, 'Lock'));
}
//obj contains keys to be set //obj contains keys to be set
Storage.prototype.setFromObj = function(walletId, obj) { Storage.prototype.setFromObj = function(walletId, obj) {
for (var k in obj) { for (var k in obj) {

View file

@ -69,7 +69,11 @@ FakeStorage.prototype.getWalletIds = function() {
var split = ii.split('::'); var split = ii.split('::');
if (split.length == 2) { if (split.length == 2) {
var walletId = split[0]; var walletId = split[0];
if (walletId !== 'nameFor' && typeof uniq[walletId] === 'undefined') {
if (!walletId || walletId === 'nameFor' || walletId ==='lock')
continue;
if (typeof uniq[walletId] === 'undefined') {
walletIds.push(walletId); walletIds.push(walletId);
uniq[walletId] = 1; uniq[walletId] = 1;
} }

View file

@ -1,14 +1,17 @@
'use strict'; 'use strict';
var copay = copay || require('../copay');
var chai = chai || require('chai'); var chai = chai || require('chai');
var should = chai.should(); var should = chai.should();
var LocalEncrypted = copay.StorageLocalEncrypted;
var fakeWallet = 'fake-wallet-id'; var fakeWallet = 'fake-wallet-id';
var timeStamp = Date.now(); var timeStamp = Date.now();
var localMock = require('./mocks/FakeLocalStorage'); var localMock = require('./mocks/FakeLocalStorage');
var is_browser = typeof process == 'undefined' || typeof process.versions === 'undefined';
if (is_browser) {
var copay = require('copay'); //browser
} else {
var copay = require('../copay'); //node
}
var LocalEncrypted = copay.StorageLocalEncrypted;
describe('Storage/LocalEncrypted model', function() { describe('Storage/LocalEncrypted model', function() {
var s = new LocalEncrypted({ var s = new LocalEncrypted({
@ -22,6 +25,8 @@ describe('Storage/LocalEncrypted model', function() {
}); });
should.exist(s2); should.exist(s2);
}); });
});
it('should fail when encrypting without a password', function() { it('should fail when encrypting without a password', function() {
var s2 = new LocalEncrypted({ var s2 = new LocalEncrypted({
localStorage: localMock, localStorage: localMock,
@ -81,6 +86,18 @@ describe('Storage/LocalEncrypted model', function() {
//encrypted.slice(0,6).should.equal("53616c"); //encrypted.slice(0,6).should.equal("53616c");
}); });
}); });
describe('#_decryptObj', function() {
it('should decrypt and Obj', function() {
var storage = new LocalEncrypted({
password: 'password',
localStorage: localMock,
});
storage._decryptObj('{"a":"2"}').should.deep.equal({
a: "2"
});
});
});
describe('#remove', function() { describe('#remove', function() {
it('should remove an item', function() { it('should remove an item', function() {
@ -131,18 +148,20 @@ describe('Storage/LocalEncrypted model', function() {
}); });
}); });
describe('#WalletLock', function() { if (is_browser) {
it('should get/set/remove opened', function() { describe('#getSessionId', function() {
it('should get SessionId', function() {
var s = new LocalEncrypted({ var s = new LocalEncrypted({
localStorage: localMock, localStorage: localMock,
password: 'password' password: 'password'
}); });
s.setLock('walletId'); var sid = s.getSessionId();
s.getLock('walletId').should.equal(true); should.exist(sid);
s.removeLock('walletId'); var sid2 = s.getSessionId();
should.not.exist(s.getLock('walletId')); sid2.should.equal(sid);
}); });
}); });
}
describe('#getWallets', function() { describe('#getWallets', function() {
it('should retreive wallets from storage', function() { it('should retreive wallets from storage', function() {
@ -217,4 +236,3 @@ describe('Storage/LocalEncrypted model', function() {
should.not.exist(s.getGlobal('a')); should.not.exist(s.getGlobal('a'));
}); });
}); });
});

View file

@ -1024,22 +1024,6 @@ describe('Wallet model', function() {
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 not start if locked', function() {
var w = cachedCreateW2();
w.netStart();
w.emit = sinon.spy();
w.netStart();
w.emit.getCall(0).args[0].should.equal('locked');
});
it('should accept ignoreLocked', function() {
var w = cachedCreateW2();
w.netStart();
w.network.start = sinon.spy();
w.ignoreLock=1;
w.netStart();
w.network.start.getCall(0).args[0].privkey.length.should.equal(64);
});
}); });
describe('#forceNetwork in config', function() { describe('#forceNetwork in config', function() {

View file

@ -298,6 +298,7 @@ describe('WalletFactory model', function() {
var w = wf.create({ var w = wf.create({
name: 'test wallet' name: 'test wallet'
}); });
ws = wf.getWallets(); ws = wf.getWallets();
ws.length.should.equal(1); ws.length.should.equal(1);
ws[0].name.should.equal('test wallet'); ws[0].name.should.equal('test wallet');