mirror of https://github.com/BTCPrivate/copay.git
Fixes on storage tests (removes current localStorage)
* Fix test that removes localStorage (made clean() function). * Enable the test for LocalPlain model.
This commit is contained in:
parent
56cf7bcc4d
commit
9462da95c0
|
@ -7,8 +7,10 @@ if (typeof process === 'undefined' || !process.version) {
|
||||||
var copay = copay || require('../copay');
|
var copay = copay || require('../copay');
|
||||||
var LocalEncrypted = copay.StorageLocalEncrypted;
|
var LocalEncrypted = copay.StorageLocalEncrypted;
|
||||||
|
|
||||||
|
var fakeWallet = 'fake-wallet-id';
|
||||||
|
var timeStamp = Date.now();
|
||||||
|
|
||||||
describe('Storage/LocalEncrypted model', function() {
|
describe('Storage/LocalEncrypted model', function() {
|
||||||
var wid = 'fake-wallet-id';
|
|
||||||
var s = new LocalEncrypted();
|
var s = new LocalEncrypted();
|
||||||
s._setPassphrase('mysupercoolpassword');
|
s._setPassphrase('mysupercoolpassword');
|
||||||
|
|
||||||
|
@ -18,14 +20,19 @@ if (typeof process === 'undefined' || !process.version) {
|
||||||
});
|
});
|
||||||
it('should fail when encrypting without a password', function() {
|
it('should fail when encrypting without a password', function() {
|
||||||
var s = new LocalEncrypted();
|
var s = new LocalEncrypted();
|
||||||
(function(){s.set(wid, 'x', 1);}).should.throw();
|
(function(){
|
||||||
|
s.set(fakeWallet, timeStamp, 1);
|
||||||
|
localStorage.removeItem(fakeWallet +'::'+ timeStamp);
|
||||||
|
}).should.throw();
|
||||||
});
|
});
|
||||||
it('should be able to encrypt and decrypt', function() {
|
it('should be able to encrypt and decrypt', function() {
|
||||||
s._write('key', 'value');
|
s._write(fakeWallet+timeStamp, 'value');
|
||||||
s._read('key').should.equal('value');
|
s._read(fakeWallet+timeStamp).should.equal('value');
|
||||||
|
localStorage.removeItem(fakeWallet+timeStamp);
|
||||||
});
|
});
|
||||||
it('should be able to set a value', function() {
|
it('should be able to set a value', function() {
|
||||||
s.set(wid, 'x', 1);
|
s.set(fakeWallet, timeStamp, 1);
|
||||||
|
localStorage.removeItem(fakeWallet +'::'+ timeStamp);
|
||||||
});
|
});
|
||||||
var getSetData = [
|
var getSetData = [
|
||||||
1,1000,-15, -1000,
|
1,1000,-15, -1000,
|
||||||
|
@ -40,22 +47,24 @@ if (typeof process === 'undefined' || !process.version) {
|
||||||
];
|
];
|
||||||
getSetData.forEach(function(obj) {
|
getSetData.forEach(function(obj) {
|
||||||
it('should be able to set a value and get it for '+JSON.stringify(obj), function() {
|
it('should be able to set a value and get it for '+JSON.stringify(obj), function() {
|
||||||
s.set(wid, 'x', obj);
|
s.set(fakeWallet, timeStamp, obj);
|
||||||
var obj2 = s.get(wid, 'x');
|
var obj2 = s.get(fakeWallet, timeStamp);
|
||||||
JSON.stringify(obj2).should.equal(JSON.stringify(obj));
|
JSON.stringify(obj2).should.equal(JSON.stringify(obj));
|
||||||
|
localStorage.removeItem(fakeWallet +'::'+ timeStamp);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#export', function() {
|
describe('#export', function() {
|
||||||
it('should export the encrypted wallet', function() {
|
it('should export the encrypted wallet', function() {
|
||||||
localStorage.clear();
|
|
||||||
var storage = new LocalEncrypted({password: 'password'});
|
var storage = new LocalEncrypted({password: 'password'});
|
||||||
storage.set('walletId', 'test', 'testval');
|
storage.set(fakeWallet, timeStamp, 'testval');
|
||||||
var obj = {test:'testval'};
|
var obj = {test:'testval'};
|
||||||
var encrypted = storage.export(obj);
|
var encrypted = storage.export(obj);
|
||||||
encrypted.length.should.be.greaterThan(10);
|
encrypted.length.should.be.greaterThan(10);
|
||||||
|
localStorage.removeItem(fakeWallet +'::'+ timeStamp);
|
||||||
//encrypted.slice(0,6).should.equal("53616c");
|
//encrypted.slice(0,6).should.equal("53616c");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ if (typeof process === 'undefined' || !process.version) {
|
||||||
var copay = copay || require('../copay');
|
var copay = copay || require('../copay');
|
||||||
var LocalPlain = copay.StorageLocalPlain;
|
var LocalPlain = copay.StorageLocalPlain;
|
||||||
|
|
||||||
describe.skip('Storage/LocalPlain model', function() {
|
describe('Storage/LocalPlain model', function() {
|
||||||
|
|
||||||
it('should create an instance', function() {
|
it('should create an instance', function() {
|
||||||
var s = new LocalPlain();
|
var s = new LocalPlain();
|
||||||
|
@ -16,7 +16,9 @@ if (typeof process === 'undefined' || !process.version) {
|
||||||
|
|
||||||
describe('#setFromObj', function() {
|
describe('#setFromObj', function() {
|
||||||
it('should set keys from an object', function() {
|
it('should set keys from an object', function() {
|
||||||
localStorage.clear();
|
var fakeWallet = 'fake-wallet-id';
|
||||||
|
var timeStamp = Date.now();
|
||||||
|
|
||||||
var obj = {
|
var obj = {
|
||||||
test: 'testval',
|
test: 'testval',
|
||||||
opts: {
|
opts: {
|
||||||
|
@ -24,8 +26,13 @@ if (typeof process === 'undefined' || !process.version) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var storage = new LocalPlain();
|
var storage = new LocalPlain();
|
||||||
storage.setFromObj('walletId', obj);
|
storage.setFromObj(fakeWallet+timeStamp, obj);
|
||||||
storage.get('walletId', 'test').should.equal('testval');
|
storage.get(fakeWallet+timeStamp, 'test').should.equal('testval');
|
||||||
|
|
||||||
|
// Clean data used in localstorage
|
||||||
|
localStorage.removeItem(fakeWallet+timeStamp+'::test');
|
||||||
|
localStorage.removeItem(fakeWallet+timeStamp+'::opts');
|
||||||
|
localStorage.removeItem('nameFor::'+fakeWallet+timeStamp);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue