From f48898033fd840fe238ee09230afbf5cf2860362 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Mon, 8 Sep 2014 14:24:57 -0300 Subject: [PATCH] more tests fixes --- js/models/core/WalletFactory.js | 3 ++- test/mocks/FakeStorage.js | 25 +++++++++++++----- test/test.WalletFactory.js | 45 ++++++++++++++++++--------------- 3 files changed, 46 insertions(+), 27 deletions(-) diff --git a/js/models/core/WalletFactory.js b/js/models/core/WalletFactory.js index eb0c432af..4ba0ed31a 100644 --- a/js/models/core/WalletFactory.js +++ b/js/models/core/WalletFactory.js @@ -91,6 +91,8 @@ WalletFactory.prototype.fromObj = function(obj, skipFields) { preconditions.checkArgument(obj); + // not stored options + obj.opts = obj.opts || {}; obj.opts.reconnectDelay = this.walletDefaults.reconnectDelay; // this is only used if private key or public key ring is skipped @@ -231,7 +233,6 @@ WalletFactory.prototype.create = function(opts, cb) { opts.totalCopayers = totalCopayers; opts.version = opts.version || this.version; -console.log('[WalletFactory.js.165]'); //TODO var w = new Wallet(opts); var self = this; w.store(function() { diff --git a/test/mocks/FakeStorage.js b/test/mocks/FakeStorage.js index 39a4b2ade..ef8b33b3c 100644 --- a/test/mocks/FakeStorage.js +++ b/test/mocks/FakeStorage.js @@ -20,6 +20,19 @@ FakeStorage.prototype.getGlobal = function(id, cb) { return cb(this.storage[id]); }; +FakeStorage.prototype.getMany = function(wid, fields, cb) { + var self= this; + var ret = []; + for(var ii in fields){ + var k = fields[ii]; + ret[k] = this.storage[wid + '::' + k]; + } + + return cb(ret); +}; + + + FakeStorage.prototype.setLastOpened = function(val, cb) { this.storage['lastOpened'] = val; return cb(); @@ -34,7 +47,7 @@ FakeStorage.prototype.setLock = function(id) { return cb(); } -FakeStorage.prototype.getLock = function(id,cb) { +FakeStorage.prototype.getLock = function(id, cb) { return cb(this.storage[id + '::lock']); } @@ -44,12 +57,12 @@ FakeStorage.prototype.getSessionId = function(cb) { }; -FakeStorage.prototype.removeLock = function(id,cb) { +FakeStorage.prototype.removeLock = function(id, cb) { delete this.storage[id + '::lock']; cb(); } -FakeStorage.prototype.removeGlobal = function(id,cb) { +FakeStorage.prototype.removeGlobal = function(id, cb) { delete this.storage[id]; cb(); }; @@ -78,7 +91,7 @@ FakeStorage.prototype.getWalletIds = function(cb) { if (split.length == 2) { var walletId = split[0]; - if (!walletId || walletId === 'nameFor' || walletId ==='lock') + if (!walletId || walletId === 'nameFor' || walletId === 'lock') continue; if (typeof uniq[walletId] === 'undefined') { @@ -106,8 +119,8 @@ FakeStorage.prototype.deleteWallet = function(walletId, cb) { }; -FakeStorage.prototype.getName = function(walletId,cb) { - return this.getGlobal('nameFor::' + walletId,cb); +FakeStorage.prototype.getName = function(walletId, cb) { + return this.getGlobal('nameFor::' + walletId, cb); }; diff --git a/test/test.WalletFactory.js b/test/test.WalletFactory.js index f736c339f..5148734cf 100644 --- a/test/test.WalletFactory.js +++ b/test/test.WalletFactory.js @@ -85,6 +85,7 @@ function assertObjectEqual(a, b, msg) { describe('WalletFactory model', function() { + var config = { Network: FakeNetwork, Blockchain: FakeBlockchain, @@ -121,42 +122,46 @@ describe('WalletFactory model', function() { it('should be able to create wallets', function(done) { var wf = new WalletFactory(config, '0.0.1'); wf.create(null, function(err, w) { - -console.log('[test.WalletFactory.js.123]'); //TODO - should.not.exist(err); should.exist(w); - w.should.be.instanceof('WalletFactory'); + should.not.exist(err); done(); }); }); - it('should be able to create wallets with given pk', function() { + it('should be able to create wallets with given pk', function(done) { var wf = new WalletFactory(config, '0.0.1'); var priv = 'tprv8ZgxMBicQKsPdEqHcA7RjJTayxA3gSSqeRTttS1JjVbgmNDZdSk9EHZK5pc52GY5xFmwcakmUeKWUDzGoMLGAhrfr5b3MovMUZUTPqisL2m'; - var w = wf.create({ + wf.create({ privateKeyHex: priv, + }, function(err, w) { + w.privateKey.toObj().extendedPrivateKeyString.should.equal(priv); + should.not.exist(err); + done(); }); - w.privateKey.toObj().extendedPrivateKeyString.should.equal(priv); }); - it('should be able to create wallets with random pk', function() { + it('should be able to create wallets with random pk', function(done) { var wf = new WalletFactory(config, '0.0.1'); - var priv = 'tprv8ZgxMBicQKsPdEqHcA7RjJTayxA3gSSqeRTttS1JjVbgmNDZdSk9EHZK5pc52GY5xFmwcakmUeKWUDzGoMLGAhrfr5b3MovMUZUTPqisL2m'; - var w1 = wf.create(); - var w2 = wf.create(); - w1.privateKey.toObj().extendedPrivateKeyString.should.not.equal( - w2.privateKey.toObj().extendedPrivateKeyString - ); + wf.create(null, function(err, w1) { + wf.create(null, function(err, w2) { + w1.privateKey.toObj().extendedPrivateKeyString.should.not.equal( + w2.privateKey.toObj().extendedPrivateKeyString + ); + done(); + }); + }); }); - it('should be able to get wallets', function() { + it.only('should be able to get wallets', function(done) { var wf = new WalletFactory(config, '0.0.1'); - var w = wf.create(); - - var w2 = wf.read(w.id); - should.exist(w2); - w2.id.should.equal(w.id); + wf.create(null, function(err,w){ + wf.read(w.id, [], function(err, w2){ + should.exist(w2); + w2.id.should.equal(w.id); + done(); + }); + }); });