fix walletLock test
This commit is contained in:
parent
b3ed2a2ea8
commit
f1e6d6cfc6
8 changed files with 269 additions and 153 deletions
|
|
@ -5,8 +5,9 @@ function LocalStorage(opts) {
|
|||
|
||||
FakeLocalStorage = {};
|
||||
FakeLocalStorage.length = 0;
|
||||
FakeLocalStorage.removeItem = function(key) {
|
||||
FakeLocalStorage.removeItem = function(key,cb) {
|
||||
delete ls[key];
|
||||
cb();
|
||||
};
|
||||
|
||||
FakeLocalStorage.getItem = function(k,cb) {
|
||||
|
|
|
|||
|
|
@ -11,57 +11,65 @@ FakeStorage.prototype._setPassphrase = function(password) {
|
|||
this.storage.passphrase = password;
|
||||
};
|
||||
|
||||
FakeStorage.prototype.setGlobal = function(id, v) {
|
||||
FakeStorage.prototype.setGlobal = function(id, v, cb) {
|
||||
this.storage[id] = typeof v === 'object' ? JSON.stringify(v) : v;
|
||||
cb();
|
||||
};
|
||||
|
||||
FakeStorage.prototype.getGlobal = function(id) {
|
||||
return this.storage[id];
|
||||
FakeStorage.prototype.getGlobal = function(id, cb) {
|
||||
return cb(this.storage[id]);
|
||||
};
|
||||
|
||||
FakeStorage.prototype.setLastOpened = function(val) {
|
||||
FakeStorage.prototype.setLastOpened = function(val, cb) {
|
||||
this.storage['lastOpened'] = val;
|
||||
return cb();
|
||||
};
|
||||
|
||||
FakeStorage.prototype.getLastOpened = function() {
|
||||
return this.storage['lastOpened'];
|
||||
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) {
|
||||
return this.storage[id + '::lock'];
|
||||
FakeStorage.prototype.getLock = function(id,cb) {
|
||||
return cb(this.storage[id + '::lock']);
|
||||
}
|
||||
|
||||
FakeStorage.prototype.getSessionId = function() {
|
||||
return this.sessionId || 'aSessionId';
|
||||
FakeStorage.prototype.getSessionId = function(cb) {
|
||||
this.sessionId = this.sessionId || 'aSessionId';
|
||||
return cb(this.sessionId);
|
||||
};
|
||||
|
||||
|
||||
FakeStorage.prototype.removeLock = function(id) {
|
||||
FakeStorage.prototype.removeLock = function(id,cb) {
|
||||
delete this.storage[id + '::lock'];
|
||||
cb();
|
||||
}
|
||||
|
||||
FakeStorage.prototype.removeGlobal = function(id) {
|
||||
FakeStorage.prototype.removeGlobal = function(id,cb) {
|
||||
delete this.storage[id];
|
||||
cb();
|
||||
};
|
||||
|
||||
|
||||
FakeStorage.prototype.set = function(wid, id, payload) {
|
||||
FakeStorage.prototype.set = function(wid, id, payload, cb) {
|
||||
this.storage[wid + '::' + id] = payload;
|
||||
if (cb) return cb();
|
||||
};
|
||||
|
||||
FakeStorage.prototype.get = function(wid, id) {
|
||||
return this.storage[wid + '::' + id];
|
||||
FakeStorage.prototype.get = function(wid, id, cb) {
|
||||
return cb(this.storage[wid + '::' + id]);
|
||||
};
|
||||
|
||||
FakeStorage.prototype.clear = function() {
|
||||
FakeStorage.prototype.clear = function(cb) {
|
||||
delete this['storage'];
|
||||
cb();
|
||||
};
|
||||
|
||||
FakeStorage.prototype.getWalletIds = function() {
|
||||
FakeStorage.prototype.getWalletIds = function(cb) {
|
||||
var walletIds = [];
|
||||
var uniq = {};
|
||||
|
||||
|
|
@ -79,10 +87,10 @@ FakeStorage.prototype.getWalletIds = function() {
|
|||
}
|
||||
}
|
||||
}
|
||||
return walletIds;
|
||||
return cb(walletIds);
|
||||
};
|
||||
|
||||
FakeStorage.prototype.deleteWallet = function(walletId) {
|
||||
FakeStorage.prototype.deleteWallet = function(walletId, cb) {
|
||||
var toDelete = {};
|
||||
toDelete['nameFor::' + walletId] = 1;
|
||||
|
||||
|
|
@ -98,17 +106,17 @@ FakeStorage.prototype.deleteWallet = function(walletId) {
|
|||
};
|
||||
|
||||
|
||||
FakeStorage.prototype.getName = function(walletId) {
|
||||
return this.getGlobal('nameFor::' + walletId);
|
||||
FakeStorage.prototype.getName = function(walletId,cb) {
|
||||
return this.getGlobal('nameFor::' + walletId,cb);
|
||||
};
|
||||
|
||||
|
||||
FakeStorage.prototype.setName = function(walletId, name) {
|
||||
this.setGlobal('nameFor::' + walletId, name);
|
||||
FakeStorage.prototype.setName = function(walletId, name, cb) {
|
||||
this.setGlobal('nameFor::' + walletId, name, cb);
|
||||
};
|
||||
|
||||
|
||||
FakeStorage.prototype.getWallets = function() {
|
||||
FakeStorage.prototype.getWallets = function(cb) {
|
||||
var wallets = [];
|
||||
var ids = this.getWalletIds();
|
||||
|
||||
|
|
@ -118,14 +126,14 @@ FakeStorage.prototype.getWallets = function() {
|
|||
name: this.getName(ids[i]),
|
||||
});
|
||||
}
|
||||
return wallets;
|
||||
return cb(wallets);
|
||||
};
|
||||
|
||||
FakeStorage.prototype.setFromObj = function(walletId, obj) {
|
||||
FakeStorage.prototype.setFromObj = function(walletId, obj, cb) {
|
||||
for (var k in obj) {
|
||||
this.set(walletId, k, obj[k]);
|
||||
}
|
||||
this.setName(walletId, obj.opts.name);
|
||||
this.setName(walletId, obj.opts.name, cb);
|
||||
};
|
||||
|
||||
module.exports = FakeStorage;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue