mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #1932 from isocolsky/wallet_version
change wallet version when storing
This commit is contained in:
commit
5a61ffa818
|
@ -239,6 +239,7 @@ Identity.prototype.retrieveWalletFromStorage = function(walletId, opts, cb) {
|
|||
Identity.prototype.storeWallet = function(wallet, cb) {
|
||||
preconditions.checkArgument(wallet && _.isObject(wallet));
|
||||
|
||||
wallet.setVersion(this.version);
|
||||
var val = wallet.toObj();
|
||||
var key = wallet.getStorageKey();
|
||||
log.debug('Storing wallet:' + wallet.getName());
|
||||
|
|
|
@ -2623,6 +2623,14 @@ Wallet.prototype.getTransactionHistoryCsv = function(cb) {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @desc Sets the version of this wallet object
|
||||
*
|
||||
* @param {string} version - the new version for the wallet
|
||||
*/
|
||||
Wallet.prototype.setVersion = function(version) {
|
||||
this.version = this.opts.version = version;
|
||||
};
|
||||
|
||||
/**
|
||||
* @desc Return a list of past transactions
|
||||
|
|
|
@ -85,6 +85,7 @@ describe('Identity model', function() {
|
|||
obj: 1
|
||||
});
|
||||
w.getName = sinon.stub().returns('name');
|
||||
w.setVersion = sinon.stub();
|
||||
w.on = sinon.stub();
|
||||
w.netStart = sinon.stub();
|
||||
w.args = args;
|
||||
|
@ -234,8 +235,62 @@ describe('Identity model', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe.skip('#storeWallet', function() {
|
||||
// TODO test storeWallet
|
||||
describe('#storeWallet', function() {
|
||||
var iden = null;
|
||||
var storage = null;
|
||||
beforeEach(function() {
|
||||
storage = sinon.stub();
|
||||
storage.setCredentials = sinon.stub();
|
||||
|
||||
var opts = {
|
||||
email: 'test@test.com',
|
||||
password: '123',
|
||||
network: {
|
||||
testnet: {
|
||||
url: 'https://test-insight.bitpay.com:443'
|
||||
},
|
||||
livenet: {
|
||||
url: 'https://insight.bitpay.com:443'
|
||||
},
|
||||
},
|
||||
storage: storage,
|
||||
};
|
||||
|
||||
iden = new Identity(opts);
|
||||
});
|
||||
|
||||
it('should store a simple wallet', function (done) {
|
||||
storage.setItem = sinon.stub().yields(null);
|
||||
var w = {
|
||||
toObj: sinon.stub().returns({ key1: 'val1' }),
|
||||
getStorageKey: sinon.stub().returns('storage_key'),
|
||||
getName: sinon.stub().returns('name'),
|
||||
setVersion: sinon.spy(),
|
||||
};
|
||||
iden.storeWallet(w, function (err) {
|
||||
should.not.exist(err);
|
||||
storage.setItem.calledOnce.should.be.true;
|
||||
storage.setItem.calledWith('storage_key', { key1: 'val1' });
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should change wallet version when storing', function (done) {
|
||||
storage.setItem = sinon.stub().yields(null);
|
||||
var w = {
|
||||
toObj: sinon.stub().returns({ key1: 'val1' }),
|
||||
getStorageKey: sinon.stub().returns('storage_key'),
|
||||
getName: sinon.stub().returns('name'),
|
||||
setVersion: sinon.spy(),
|
||||
version: '1.0',
|
||||
opts: { version: '1.0' },
|
||||
};
|
||||
iden.version = '2.0';
|
||||
iden.storeWallet(w, function (err) {
|
||||
should.not.exist(err);
|
||||
w.setVersion.calledWith('2.0').should.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue