mirror of https://github.com/BTCPrivate/copay.git
burn in hell fake storage
This commit is contained in:
parent
5886af5420
commit
8bc1eb15e4
|
@ -45,8 +45,6 @@ module.exports = function(grunt) {
|
|||
'js/models/**/*.js',
|
||||
'js/models/*.js',
|
||||
'plugins/*.js',
|
||||
'copay.js',
|
||||
'utils/*.js'
|
||||
],
|
||||
tasks: ['shell:dev']
|
||||
},
|
||||
|
@ -181,7 +179,7 @@ module.exports = function(grunt) {
|
|||
},
|
||||
jsdoc: {
|
||||
dist : {
|
||||
src: ['js/models/core/*.js'],
|
||||
src: ['js/models/core/*.js', 'js/models/*.js', 'plugins/*.js'],
|
||||
options: {
|
||||
destination: 'doc',
|
||||
configure: 'jsdoc.conf.json',
|
||||
|
|
|
@ -22,9 +22,6 @@
|
|||
<section class="left-small">
|
||||
<a class="left-off-canvas-toggle menu-icon" ><span></span></a>
|
||||
</section>
|
||||
<section ng-controller="SidebarController" class="right-small text-center">
|
||||
<a href="#" ng-click="signout()"><i class="size-24 fi-power"></i></a>
|
||||
</section>
|
||||
|
||||
<section class="middle tab-bar-section">
|
||||
<h1 class="right">
|
||||
|
|
|
@ -27,6 +27,7 @@ function Storage(opts) {
|
|||
|
||||
var pps = {};
|
||||
Storage.prototype._getPassphrase = function() {
|
||||
|
||||
if (!pps[this.__uniqueid])
|
||||
throw new Error('NOPASSPHRASE: No passphrase set');
|
||||
|
||||
|
|
|
@ -60,6 +60,8 @@ module.exports = function(config) {
|
|||
'test/mocks/FakeWallet.js',
|
||||
'test/mocks/FakeBlockchainSocket.js',
|
||||
'test/mocks/FakePayProServer.js',
|
||||
'test/mocks/FakeLocalStorage.js',
|
||||
'test/mocks/FakeStorage.js',
|
||||
|
||||
'test/mocha.conf.js',
|
||||
|
||||
|
|
13
package.json
13
package.json
|
@ -13,7 +13,7 @@
|
|||
"dependencies": {
|
||||
"browser-request": "^0.3.2",
|
||||
"inherits": "^2.0.1",
|
||||
"mocha": "^1.21.4",
|
||||
"mocha": "^1.18.2",
|
||||
"mocha-lcov-reporter": "0.0.1",
|
||||
"optimist": "^0.6.1",
|
||||
"preconditions": "^1.0.7",
|
||||
|
@ -27,14 +27,12 @@
|
|||
"chrome": "source browser-extensions/chrome/build.sh",
|
||||
"setup-shell": "node shell/scripts/download-atom-shell.js",
|
||||
"start": "node server.js",
|
||||
"coverage": "mochacoverage",
|
||||
"test": "mocha --ui exports --reporter spec",
|
||||
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --reporter spec test",
|
||||
"test": "sh test/run.sh",
|
||||
"dist": "node shell/scripts/dist.js",
|
||||
"sign": "gpg -u 1112CFA1 --output browser-extensions/firefox/copay.xpi.sig --detach-sig browser-extensions/firefox/copay.xpi; gpg -u 1112CFA1 --output browser-extensions/chrome/copay-chrome-extension.zip.sig --detach-sig browser-extensions/chrome/copay-chrome-extension.zip",
|
||||
"verify": "gpg --verify browser-extensions/firefox/copay.xpi.sig browser-extensions/firefox/copay.xpi; gpg --verify browser-extensions/chrome/copay-chrome-extension.zip.sig browser-extensions/chrome/copay-chrome-extension.zip",
|
||||
"postinstall": "./node_modules/.bin/grunt",
|
||||
"monitor": "mocha --ui exports --reporter min --watch",
|
||||
"debugtest": "mocha --debug-brk --ui exports --reporter spec"
|
||||
"postinstall": "./node_modules/.bin/grunt"
|
||||
},
|
||||
"keywords": [
|
||||
"wallet",
|
||||
|
@ -83,8 +81,7 @@
|
|||
"shelljs": "0.3.0",
|
||||
"socket.io-client": "1.0.6",
|
||||
"travis-cov": "0.2.5",
|
||||
"uglifyify": "1.2.3",
|
||||
"mochawrapper": ""
|
||||
"uglifyify": "1.2.3"
|
||||
},
|
||||
"main": "app.js",
|
||||
"homepage": "https://github.com/bitpay/copay",
|
||||
|
|
|
@ -1,162 +0,0 @@
|
|||
var FakeStorage = function() {
|
||||
this.reset();
|
||||
};
|
||||
|
||||
|
||||
FakeStorage.prototype.reset = function(password) {
|
||||
this.storage = {};
|
||||
};
|
||||
|
||||
FakeStorage.prototype.setPassphrase = function(password) {
|
||||
this.storage.passphrase = password;
|
||||
};
|
||||
|
||||
FakeStorage.prototype.setGlobal = function(id, v, cb) {
|
||||
this.storage[id] = typeof v === 'object' ? JSON.stringify(v) : v;
|
||||
cb();
|
||||
};
|
||||
|
||||
FakeStorage.prototype.getGlobal = function(id, cb) {
|
||||
return cb(this.storage[id]);
|
||||
};
|
||||
|
||||
FakeStorage.prototype.getMany = function(wid, fields, cb) {
|
||||
var self = this;
|
||||
var ret = [];
|
||||
for (var ii in fields) {
|
||||
var k = fields[ii];
|
||||
ret[k] = this.storage[wid + '::' + k];
|
||||
}
|
||||
|
||||
return cb(ret);
|
||||
};
|
||||
|
||||
|
||||
|
||||
FakeStorage.prototype.setLastOpened = function(val, cb) {
|
||||
this.storage['lastOpened'] = val;
|
||||
return cb();
|
||||
};
|
||||
|
||||
FakeStorage.prototype.getLastOpened = function(cb) {
|
||||
return cb(this.storage['lastOpened']);
|
||||
};
|
||||
|
||||
FakeStorage.prototype.setLock = function(id) {
|
||||
this.storage[id + '::lock'] = true;
|
||||
return cb();
|
||||
}
|
||||
|
||||
FakeStorage.prototype.getLock = function(id, cb) {
|
||||
return cb(this.storage[id + '::lock']);
|
||||
}
|
||||
|
||||
FakeStorage.prototype.getSessionId = function(cb) {
|
||||
this.sessionId = this.sessionId || 'aSessionId';
|
||||
return cb(this.sessionId);
|
||||
};
|
||||
|
||||
|
||||
FakeStorage.prototype.removeLock = function(id, cb) {
|
||||
delete this.storage[id + '::lock'];
|
||||
cb();
|
||||
}
|
||||
|
||||
FakeStorage.prototype.removeGlobal = function(id, cb) {
|
||||
delete this.storage[id];
|
||||
cb();
|
||||
};
|
||||
|
||||
|
||||
FakeStorage.prototype.set = function(wid, id, payload, cb) {
|
||||
this.storage[wid + '::' + id] = payload;
|
||||
if (cb) return cb();
|
||||
};
|
||||
|
||||
FakeStorage.prototype.get = function(wid, id, cb) {
|
||||
return cb(this.storage[wid + '::' + id]);
|
||||
};
|
||||
|
||||
FakeStorage.prototype.clear = function(cb) {
|
||||
delete this['storage'];
|
||||
cb();
|
||||
};
|
||||
|
||||
FakeStorage.prototype.getWalletIds = function(cb) {
|
||||
var walletIds = [];
|
||||
var uniq = {};
|
||||
|
||||
for (var ii in this.storage) {
|
||||
var split = ii.split('::');
|
||||
if (split.length == 2) {
|
||||
var walletId = split[0];
|
||||
|
||||
if (!walletId || walletId === 'nameFor' || walletId === 'lock')
|
||||
continue;
|
||||
|
||||
if (typeof uniq[walletId] === 'undefined') {
|
||||
walletIds.push(walletId);
|
||||
uniq[walletId] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cb(walletIds);
|
||||
};
|
||||
|
||||
FakeStorage.prototype.deleteWallet = function(walletId, cb) {
|
||||
var toDelete = {};
|
||||
toDelete['nameFor::' + walletId] = 1;
|
||||
|
||||
for (var key in this.storage) {
|
||||
var split = key.split('::');
|
||||
if (split.length == 2 && split[0] === walletId) {
|
||||
toDelete[key] = 1;
|
||||
}
|
||||
}
|
||||
var l = toDelete.length,
|
||||
j = 0;
|
||||
|
||||
if (!l)
|
||||
return cb(new Error('WNOTFOUND: Wallet not found'));
|
||||
|
||||
for (var i in toDelete) {
|
||||
this.removeGlobal(i, cb);
|
||||
if (++j == l)
|
||||
return cb(err);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
FakeStorage.prototype.getName = function(walletId, cb) {
|
||||
this.getGlobal('nameFor::' + walletId, cb);
|
||||
};
|
||||
|
||||
|
||||
FakeStorage.prototype.setName = function(walletId, name, cb) {
|
||||
this.setGlobal('nameFor::' + walletId, name, cb);
|
||||
};
|
||||
|
||||
|
||||
FakeStorage.prototype.getWallets = function(cb) {
|
||||
var wallets = [];
|
||||
var self= this;
|
||||
this.getWalletIds(function(ids) {
|
||||
for (var i in ids) {
|
||||
wallets.push({
|
||||
id: ids[i],
|
||||
name: self.storage['nameFor::' + ids[i]],
|
||||
});
|
||||
}
|
||||
return cb(wallets);
|
||||
});
|
||||
};
|
||||
|
||||
FakeStorage.prototype.setFromObj = function(walletId, obj, cb) {
|
||||
for (var k in obj) {
|
||||
this.set(walletId, k, obj[k]);
|
||||
}
|
||||
this.setName(walletId, obj.opts.name, cb);
|
||||
};
|
||||
|
||||
module.exports = FakeStorage;
|
|
@ -11,7 +11,6 @@ if (is_browser) {
|
|||
}
|
||||
var Wallet = copay.Wallet;
|
||||
var PrivateKey = copay.PrivateKey;
|
||||
var Storage = require('./mocks/FakeStorage');
|
||||
var Network = require('./mocks/FakeNetwork');
|
||||
var Blockchain = require('./mocks/FakeBlockchain');
|
||||
var bitcore = bitcore || require('bitcore');
|
||||
|
@ -21,6 +20,10 @@ var Address = bitcore.Address;
|
|||
var PayPro = bitcore.PayPro;
|
||||
var bignum = bitcore.Bignum;
|
||||
var startServer = copay.FakePayProServer; // TODO should be require('./mocks/FakePayProServer');
|
||||
var localMock = require('./mocks/FakeLocalStorage');
|
||||
var sessionMock = require('./mocks/FakeLocalStorage');
|
||||
var Storage = copay.Storage;
|
||||
|
||||
|
||||
var server;
|
||||
|
||||
|
@ -30,6 +33,10 @@ var walletConfig = {
|
|||
spendUnconfirmed: true,
|
||||
reconnectDelay: 100,
|
||||
networkName: 'testnet',
|
||||
storage: {
|
||||
storage: localMock,
|
||||
sessionStorage: sessionMock,
|
||||
}
|
||||
};
|
||||
|
||||
var getNewEpk = function() {
|
||||
|
|
|
@ -25,8 +25,7 @@ describe('Storage model', function() {
|
|||
});
|
||||
should.exist(s2);
|
||||
});
|
||||
it.only('should fail when encrypting without a password', function() {
|
||||
|
||||
it('should fail when encrypting without a password', function() {
|
||||
var s2 = new Storage({
|
||||
storage: localMock,
|
||||
sessionStorage: sessionMock,
|
||||
|
|
|
@ -13,7 +13,7 @@ if (is_browser) {
|
|||
var copayConfig = require('../config');
|
||||
var Wallet = copay.Wallet;
|
||||
var PrivateKey = copay.PrivateKey;
|
||||
var Storage = require('./mocks/FakeStorage');
|
||||
var Storage = copay.Storage;
|
||||
var Network = require('./mocks/FakeNetwork');
|
||||
var Blockchain = require('./mocks/FakeBlockchain');
|
||||
var Builder = require('./mocks/FakeBuilder');
|
||||
|
@ -21,6 +21,8 @@ var bitcore = bitcore || require('bitcore');
|
|||
var TransactionBuilder = bitcore.TransactionBuilder;
|
||||
var Transaction = bitcore.Transaction;
|
||||
var Address = bitcore.Address;
|
||||
var localMock = require('./mocks/FakeLocalStorage');
|
||||
var sessionMock = require('./mocks/FakeLocalStorage');
|
||||
|
||||
var walletConfig = {
|
||||
requiredCopayers: 3,
|
||||
|
@ -28,6 +30,10 @@ var walletConfig = {
|
|||
spendUnconfirmed: true,
|
||||
reconnectDelay: 100,
|
||||
networkName: 'testnet',
|
||||
storage: {
|
||||
storage: localMock,
|
||||
sessionStorage: sessionMock,
|
||||
}
|
||||
};
|
||||
|
||||
var getNewEpk = function() {
|
||||
|
|
|
@ -13,12 +13,19 @@ var copayConfig = require('../config');
|
|||
var WalletLock = copay.WalletLock;
|
||||
|
||||
var PrivateKey = copay.PrivateKey;
|
||||
var Storage = require('./mocks/FakeStorage');
|
||||
var localMock = require('./mocks/FakeLocalStorage');
|
||||
var sessionMock = require('./mocks/FakeLocalStorage');
|
||||
var Storage = copay.Storage;
|
||||
|
||||
|
||||
|
||||
var storage;
|
||||
describe('WalletLock model', function() {
|
||||
beforeEach(function() {
|
||||
storage = new Storage();
|
||||
storage = new Storage({
|
||||
storage: localMock,
|
||||
sessionStorage: sessionMock,
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail with missing args', function() {
|
||||
|
|
|
@ -104,9 +104,6 @@ var createBundle = function(opts) {
|
|||
//include dev dependencies
|
||||
b.require('sinon');
|
||||
b.require('blanket');
|
||||
b.require('./test/mocks/FakeStorage', {
|
||||
expose: './mocks/FakeStorage'
|
||||
});
|
||||
b.require('./test/mocks/FakeLocalStorage', {
|
||||
expose: './mocks/FakeLocalStorage'
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue