ALL TEST PASSING!!!
This commit is contained in:
parent
ad22b24d83
commit
5cf4fe0b66
5 changed files with 184 additions and 71 deletions
|
|
@ -111,7 +111,7 @@ Storage.prototype.getSessionId = function(cb) {
|
|||
return cb(sessionId);
|
||||
|
||||
sessionId = bitcore.SecureRandom.getRandomBuffer(8).toString('hex');
|
||||
self.sessionStorage.setItem('sessionId', sessionId, function(){
|
||||
self.sessionStorage.setItem('sessionId', sessionId, function() {
|
||||
return cb(sessionId);
|
||||
});
|
||||
});
|
||||
|
|
@ -232,31 +232,36 @@ Storage.prototype.deleteWallet = function(walletId, cb) {
|
|||
preconditions.checkArgument(walletId);
|
||||
preconditions.checkArgument(cb);
|
||||
var err;
|
||||
var self = this;
|
||||
|
||||
var toDelete = {};
|
||||
toDelete['nameFor::' + walletId] = 1;
|
||||
|
||||
this.storage.allKeys(function(allKeys) {
|
||||
for (var key in allKeys) {
|
||||
for (var ii in allKeys) {
|
||||
var key = allKeys[ii];
|
||||
var split = key.split('::');
|
||||
if (split.length == 2 && split[0] === walletId) {
|
||||
toDelete[key] = 1;
|
||||
};
|
||||
}
|
||||
var l = Object.keys(toDelete).length,
|
||||
j = 0;
|
||||
if (!l)
|
||||
return cb(new Error('WNOTFOUND: Wallet not found'));
|
||||
|
||||
toDelete['nameFor::' + walletId] = 1;
|
||||
l++;
|
||||
|
||||
for (var i in toDelete) {
|
||||
self.removeGlobal(i, function() {
|
||||
if (++j == l)
|
||||
return cb(err);
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
var l = toDelete.length,
|
||||
j = 0;
|
||||
|
||||
if (!l)
|
||||
return cb(new Error('WNOTFOUND: Wallet not found'));
|
||||
|
||||
for (var i in toDelete) {
|
||||
this.removeGlobal(i, function() {
|
||||
if (++j == l)
|
||||
return cb(err);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Storage.prototype.setLastOpened = function(walletId, cb) {
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ function WalletFactory(config, version, pluginManager) {
|
|||
|
||||
this.storage = new this.Storage(storageOpts);
|
||||
|
||||
<<<<<<< HEAD
|
||||
this.networks = {
|
||||
'livenet': new this.Network(config.network.livenet),
|
||||
'testnet': new this.Network(config.network.testnet),
|
||||
|
|
@ -63,6 +64,10 @@ function WalletFactory(config, version, pluginManager) {
|
|||
};
|
||||
|
||||
this.walletDefaults = config.wallet;
|
||||
=======
|
||||
this.networkName = config.networkName;
|
||||
this.walletDefaults = config.wallet || {};
|
||||
>>>>>>> ALL TEST PASSING!!!
|
||||
this.version = version;
|
||||
};
|
||||
|
||||
|
|
@ -90,7 +95,6 @@ WalletFactory.prototype.fromObj = function(obj, skipFields) {
|
|||
preconditions.checkState(networkName);
|
||||
preconditions.checkArgument(obj);
|
||||
|
||||
|
||||
// not stored options
|
||||
obj.opts = obj.opts || {};
|
||||
obj.opts.reconnectDelay = this.walletDefaults.reconnectDelay;
|
||||
|
|
@ -418,7 +422,7 @@ WalletFactory.prototype.joinCreateSession = function(opts, cb) {
|
|||
joinNetwork.start(opts, function() {
|
||||
joinNetwork.greet(decodedSecret.pubKey, opts.secretNumber);
|
||||
joinNetwork.on('data', function(sender, data) {
|
||||
if (data.type === 'walletId') {
|
||||
if (data.type === 'walletId' && data.opts) {
|
||||
if (data.networkName !== decodedSecret.networkName) {
|
||||
return cb('badNetwork');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,5 +36,4 @@ describe('Passphrase model', function() {
|
|||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ describe('Storage model', function() {
|
|||
storage: localMock,
|
||||
sessionStorage: sessionMock,
|
||||
});
|
||||
s._setPassphrase('mysupercoolpassword');
|
||||
s.setPassphrase('mysupercoolpassword');
|
||||
|
||||
it('should create an instance', function() {
|
||||
var s2 = new Storage({
|
||||
|
|
@ -210,8 +210,8 @@ describe('Storage model', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
describe('#deleteWallet', function(done) {
|
||||
it('should delete a wallet', function() {
|
||||
describe('#deleteWallet', function() {
|
||||
it('should fail to delete a unexisting wallet', function(done) {
|
||||
var s = new Storage({
|
||||
storage: localMock,
|
||||
sessionStorage: sessionMock,
|
||||
|
|
@ -219,9 +219,26 @@ describe('Storage model', function() {
|
|||
});
|
||||
s.set('1', "hola", 'juan', function() {
|
||||
s.set('2', "hola", 'juan', function() {
|
||||
s.deleteWallet('1', function() {
|
||||
s.deleteWallet('3', function(err) {
|
||||
err.toString().should.include('WNOTFOUND');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should delete a wallet', function(done) {
|
||||
var s = new Storage({
|
||||
storage: localMock,
|
||||
sessionStorage: sessionMock,
|
||||
password: 'password'
|
||||
});
|
||||
s.set('1', "hola", 'juan', function() {
|
||||
s.set('2', "hola", 'juan', function() {
|
||||
s.deleteWallet('1', function(err) {
|
||||
should.not.exist(err);
|
||||
s.getWallets(function(ws) {
|
||||
s.getWallets().length.should.equal(1);
|
||||
ws.length.should.equal(1);
|
||||
ws[0].should.deep.equal({
|
||||
id: '2',
|
||||
name: undefined
|
||||
|
|
@ -299,4 +316,43 @@ describe('Storage model', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#import', function() {
|
||||
it('should be able to decrypt an old backup', function() {
|
||||
var s = new Storage({
|
||||
storage: localMock,
|
||||
sessionStorage: sessionMock,
|
||||
password: legacyPassword1 ,
|
||||
});
|
||||
var wo = s.import(encryptedLegacy1);
|
||||
should.exist(wo);
|
||||
wo.opts.id.should.equal('48ba2f1ffdfe9708');
|
||||
wo.opts.spendUnconfirmed.should.equal(true);
|
||||
wo.opts.requiredCopayers.should.equal(1);
|
||||
wo.opts.totalCopayers.should.equal(1);
|
||||
wo.opts.name.should.equal('pepe wallet');
|
||||
wo.opts.version.should.equal('0.4.7');
|
||||
wo.publicKeyRing.walletId.should.equal('48ba2f1ffdfe9708');
|
||||
wo.publicKeyRing.networkName.should.equal('testnet');
|
||||
wo.publicKeyRing.requiredCopayers.should.equal(1);
|
||||
wo.publicKeyRing.totalCopayers.should.equal(1);
|
||||
wo.publicKeyRing.indexes.length.should.equal(2);
|
||||
JSON.stringify(wo.publicKeyRing.indexes[0]).should.equal('{"copayerIndex":2147483647,"changeIndex":0,"receiveIndex":1}');
|
||||
JSON.stringify(wo.publicKeyRing.indexes[1]).should.equal('{"copayerIndex":0,"changeIndex":0,"receiveIndex":1}');
|
||||
wo.publicKeyRing.copayersBackup.length.should.equal(1);
|
||||
wo.publicKeyRing.copayersBackup[0].should.equal('0298f65b2694c55f9048bc05f10368242727c7f9d2065cbd788c3ecde1ec57f33f');
|
||||
wo.publicKeyRing.copayersExtPubKeys.length.should.equal(1);
|
||||
wo.publicKeyRing.copayersExtPubKeys[0].should.equal('tpubD9SGoP7CXsqSKTiQxCZSCpicDcophqnE4yuqjfw5M9tAR3fSjT9GDGwPEUFCN7SSmRKGDLZgKQePYFaLWyK32akeSan45TNTd8sgef9Ymh6');
|
||||
wo.privateKey.extendedPrivateKeyString.should.equal('tprv8ZgxMBicQKsPfQCscb7CtJKzixxcVSyrCVcfr3WCFbtT8kYTzNubhjQ5R7AuYJgPCcSH4R8T34YVxeohKGhAB9wbB4eFBbQFjUpjGCqptHm');
|
||||
wo.privateKey.networkName.should.equal('testnet');
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
var legacyPassword1 = '1DUpLRbuVpgLkcEY8gY8iod/SmA7+OheGZJ9PtvmTlvNE0FkEWpCKW9STdzXYJqbn0wiAapE4ojHNYj2hjYYAQ==';
|
||||
var encryptedLegacy1 = 'U2FsdGVkX19yGM1uBAIzQa8Po/dvUicmxt1YyRk/S97PcZ6I6rHMp9dMagIrehg4Qd6JHn/ustmFHS7vmBYj0EBpf6rdXiQezaWnVAJS9/xYjAO36EFUbl+NmUanuwujAxgYdSP/sNssRLeInvExmZYW993EEclxkwL6YUyX66kKsxGQo2oWng0NreBJNhF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as4grxt0CGN6EavzQ==';
|
||||
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue