mocha test passing on console
This commit is contained in:
parent
bcb61810d5
commit
eb9acb958f
7 changed files with 185 additions and 191 deletions
|
|
@ -1670,7 +1670,7 @@ Wallet.prototype.indexDiscovery = function(start, change, cosigner, gap, cb) {
|
|||
|
||||
Wallet.prototype.disconnect = function() {
|
||||
this.log('## DISCONNECTING');
|
||||
this.unlock();
|
||||
this.lock.release();
|
||||
this.network.disconnect();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ WalletFactory.prototype._checkNetwork = function(inNetworkName) {
|
|||
|
||||
WalletFactory.prototype.open = function(walletId, passphrase) {
|
||||
this.storage._setPassphrase(passphrase);
|
||||
var w = this.read(walletId, opts);
|
||||
var w = this.read(walletId);
|
||||
if (w)
|
||||
w.store();
|
||||
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ Storage.prototype.getWalletIds = function() {
|
|||
if (split.length == 2) {
|
||||
var walletId = split[0];
|
||||
|
||||
if (walletId === 'nameFor' || walletId === 'lock')
|
||||
if (!walletId || walletId === 'nameFor')
|
||||
continue;
|
||||
|
||||
if (typeof uniq[walletId] === 'undefined') {
|
||||
|
|
@ -190,19 +190,6 @@ Storage.prototype.getLastOpened = function() {
|
|||
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
|
||||
Storage.prototype.setFromObj = function(walletId, obj) {
|
||||
for (var k in obj) {
|
||||
|
|
|
|||
|
|
@ -69,7 +69,11 @@ FakeStorage.prototype.getWalletIds = function() {
|
|||
var split = ii.split('::');
|
||||
if (split.length == 2) {
|
||||
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);
|
||||
uniq[walletId] = 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,17 @@
|
|||
'use strict';
|
||||
var copay = copay || require('../copay');
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var LocalEncrypted = copay.StorageLocalEncrypted;
|
||||
|
||||
|
||||
var fakeWallet = 'fake-wallet-id';
|
||||
var timeStamp = Date.now();
|
||||
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() {
|
||||
var s = new LocalEncrypted({
|
||||
|
|
@ -22,6 +25,8 @@ describe('Storage/LocalEncrypted model', function() {
|
|||
});
|
||||
should.exist(s2);
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail when encrypting without a password', function() {
|
||||
var s2 = new LocalEncrypted({
|
||||
localStorage: localMock,
|
||||
|
|
@ -81,6 +86,18 @@ describe('Storage/LocalEncrypted model', function() {
|
|||
//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() {
|
||||
it('should remove an item', function() {
|
||||
|
|
@ -131,18 +148,20 @@ describe('Storage/LocalEncrypted model', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('#WalletLock', function() {
|
||||
it('should get/set/remove opened', function() {
|
||||
if (is_browser) {
|
||||
describe('#getSessionId', function() {
|
||||
it('should get SessionId', function() {
|
||||
var s = new LocalEncrypted({
|
||||
localStorage: localMock,
|
||||
password: 'password'
|
||||
});
|
||||
s.setLock('walletId');
|
||||
s.getLock('walletId').should.equal(true);
|
||||
s.removeLock('walletId');
|
||||
should.not.exist(s.getLock('walletId'));
|
||||
var sid = s.getSessionId();
|
||||
should.exist(sid);
|
||||
var sid2 = s.getSessionId();
|
||||
sid2.should.equal(sid);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
describe('#getWallets', function() {
|
||||
it('should retreive wallets from storage', function() {
|
||||
|
|
@ -217,4 +236,3 @@ describe('Storage/LocalEncrypted model', function() {
|
|||
should.not.exist(s.getGlobal('a'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1024,22 +1024,6 @@ describe('Wallet model', function() {
|
|||
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() {
|
||||
|
|
|
|||
|
|
@ -298,6 +298,7 @@ describe('WalletFactory model', function() {
|
|||
var w = wf.create({
|
||||
name: 'test wallet'
|
||||
});
|
||||
|
||||
ws = wf.getWallets();
|
||||
ws.length.should.equal(1);
|
||||
ws[0].name.should.equal('test wallet');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue