Merge pull request #1468 from isocolsky/ref/storage

Refactor wallet storage
This commit is contained in:
Matias Alejo Garcia 2014-09-25 08:17:24 -03:00
commit be72a2b77a
4 changed files with 456 additions and 193 deletions

View file

@ -40,7 +40,6 @@ describe('WalletFactory model', function() {
wf.storage.setLastOpened = sinon.stub().yields(null);
var w = sinon.stub();
w.store = sinon.stub().yields(null);
@ -246,7 +245,7 @@ describe('WalletFactory model', function() {
describe('#read', function() {
it('should fail to read unexisting wallet', function(done) {
wf.storage.getMany = sinon.stub().yields({});
wf.storage.readWallet = sinon.stub().yields(null, {});
wf.read('id', [], function(err, w) {
should.not.exist(w);
@ -258,7 +257,7 @@ describe('WalletFactory model', function() {
});
});
it('should fail to read broken wallet', function(done) {
wf.storage.getMany = sinon.stub().yields({
wf.storage.readWallet = sinon.stub().yields(null, {
'opts': 1
});
wf.read('id', [], function(err, w) {
@ -272,7 +271,7 @@ describe('WalletFactory model', function() {
});
it('should read existing wallet', function(done) {
var wf = new WalletFactory(config, '0.0.1');
wf.storage.getMany = sinon.stub().yields({
wf.storage.readWallet = sinon.stub().yields(null, {
'opts': 1
});
wf.fromObj = sinon.stub().returns('ok');
@ -298,6 +297,7 @@ describe('WalletFactory model', function() {
var s1 = sinon.stub();
s1.store = sinon.stub().yields(null);
wf.read = sinon.stub().yields(null, s1);
wf.migrateWallet = sinon.stub().yields(null);
wf.storage.setLastOpened = sinon.stub().yields(null);
wf.open('dummy', 'xxx', function(err, w) {
@ -314,6 +314,7 @@ describe('WalletFactory model', function() {
var s1 = sinon.stub();
s1.store = sinon.stub().yields(null);
wf.read = sinon.stub().yields(null, s1);
wf.migrateWallet = sinon.stub().yields(null);
wf.storage.setLastOpened = sinon.stub().yields(null);
wf.open('dummy', 'xxx', function(err, w) {
@ -331,6 +332,7 @@ describe('WalletFactory model', function() {
var s1 = sinon.stub();
s1.store = sinon.stub().yields(null);
wf.read = sinon.stub().yields(null, s1);
wf.migrateWallet = sinon.stub().yields(null);
wf.storage.setLastOpened = sinon.stub().yields(null);
wf.open('dummy', 'xxx', function(err, w) {
@ -346,6 +348,7 @@ describe('WalletFactory model', function() {
var s1 = sinon.stub();
s1.store = sinon.stub().yields(null);
wf.read = sinon.stub().yields(null, s1);
wf.migrateWallet = sinon.stub().yields(null);
wf.storage.setLastOpened = sinon.stub().yields(null);
wf.open('dummy', 'xxx', function(err, w) {
@ -354,6 +357,24 @@ describe('WalletFactory model', function() {
done();
});
});
it('should call #migrateWallet', function(done) {
var wf = new WalletFactory(config, '0.0.1');
wf.storage.setPassphrase = sinon.spy();
var s1 = sinon.stub();
s1.store = sinon.stub().yields(null);
wf.read = sinon.stub().yields(null, s1);
wf.migrateWallet = sinon.stub().yields(null);
wf.storage.deleteWallet_Old = sinon.stub().yields(null);
wf.storage.removeGlobal = sinon.stub().yields(null);
wf.storage.setLastOpened = sinon.stub().yields(null);
wf.open('dummy', 'xxx', function(err, w) {
wf.migrateWallet.calledOnce.should.equal(true);
wf.migrateWallet.getCall(0).args[0].should.equal('dummy');
done();
});
});
});
describe('#create', function() {
@ -549,7 +570,6 @@ describe('WalletFactory model', function() {
});
});
});