From 376ee5359bf61b4618b1a5ce8fe1cf01509a3065 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 12 Nov 2014 21:59:58 -0300 Subject: [PATCH] fix karma test. rm unused code --- js/models/Identity.js | 39 ------------------------ js/services/controllerUtils.js | 3 +- test/unit/controllers/controllersSpec.js | 14 +-------- test/unit/services/servicesSpec.js | 16 +++++++--- 4 files changed, 15 insertions(+), 57 deletions(-) diff --git a/js/models/Identity.js b/js/models/Identity.js index e04797575..1c71beeba 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -275,45 +275,6 @@ Identity.prototype.close = function(cb) { }, cb); }; -/** - * @desc Imports a wallet from an encrypted string - * @param {string} cypherText - the encrypted object - * @param {string} passphrase - passphrase to decrypt it - * @param {string[]} opts.skipFields - fields to ignore when importing - * @param {string[]} opts.salt - - * @param {string[]} opts.iterations - - * @param {string[]} opts.importFunction - for stubbing - * @return {Wallet} - */ - -// This is not used in favor of Compatibility. importEncryptedWallet - -// Identity.prototype.importEncryptedWallet = function(cypherText, password, opts, cb) { -// var crypto = opts.cryptoUtil || cryptoUtil; -// var obj = crypto.decrypt(password, cypherText); -// console.log('[Identity.js.290:obj:]',obj); //TODO -// -// if (!obj) { -// // 0.7.3 broken KDF -// log.debug('Trying legacy encryption...'); -// console.log('[Identity.js.296:password:]',password); //TODO -// var passphrase = crypto.kdf(password, 'mjuBtGybi/4=', 100); -// console.log('[Identity.js.296:passphrase:]',passphrase); //TODO -// obj = crypto.decrypt(passphrase, ejson); -// console.log('[Identity.js.297:obj:]',obj); //TODO -// } -// console.log('[Identity.js.300:obj:]',obj); //TOD -// -// if (!obj) -// return cb(new Error('Could not decrypt')); -// try { -// obj = JSON.parse(obj); -// } catch (e) { -// return cb(new Error('Could not decrypt')); -// } -// return this.importWalletFromObj(obj, opts, cb) -// }; -// Identity.prototype.importWalletFromObj = function(obj, opts, cb) { var self = this; preconditions.checkArgument(cb); diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index c5c46a7ba..60e6cbef4 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -266,8 +266,8 @@ angular.module('copayApp.services') r.totalBalance = balanceSat * satToUnit; r.totalBalanceBTC = (balanceSat / COIN); r.availableBalance = safeBalanceSat * satToUnit; - r.safeUnspentCount = safeUnspentCount; r.availableBalanceBTC = (safeBalanceSat / COIN); + r.safeUnspentCount = safeUnspentCount; r.lockedBalance = (balanceSat - safeBalanceSat) * satToUnit; r.lockedBalanceBTC = (balanceSat - safeBalanceSat) / COIN; @@ -309,6 +309,7 @@ angular.module('copayApp.services') }; root.updateBalance = function(w, cb, refreshAll) { + w = w || $rootScope.wallet; if (!w) return root.onErrorDigest(); if (!w.isReady()) return; diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index 10dc77fac..634cc5517 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -422,24 +422,12 @@ describe("Unit: Controllers", function() { expect(scope.isMobile).not.to.equal(null); }); it('should autotop balance correctly', function() { - scope.topAmount(form); + scope.setTopAmount(form); form.amount.$setViewValue(123356); expect(scope.amount).to.equal(123356); expect(form.amount.$invalid).to.equal(false); expect(form.amount.$pristine).to.equal(false); }); - it('should return available amount', function() { - form.amount.$setViewValue(123356); - var amount = scope.getAvailableAmount(); - expect(amount).to.equal(123356); - }); - it('should return 0 if available amount below minimum fee', function() { - inject(function($compile, $rootScope, $controller) { - $rootScope.availableBalance = 1; - }); - var amount = scope.getAvailableAmount(); - expect(amount).to.equal(0); - }); }); describe('Import Controller', function() { diff --git a/test/unit/services/servicesSpec.js b/test/unit/services/servicesSpec.js index 58183054c..fc044e4b8 100644 --- a/test/unit/services/servicesSpec.js +++ b/test/unit/services/servicesSpec.js @@ -74,11 +74,16 @@ describe("Angular services", function() { expect(controllerUtils.updateBalance).not.to.equal(null); var Waddr = Object.keys($rootScope.wallet.balanceByAddr)[0]; var a = {}; - a[Waddr] = 100; - w.getBalance = sinon.stub().returns(100000001, 90000002, a); + a[Waddr] = 200; + w.getBalance = sinon.stub().yields(null, 100000001, a, 90000002, 5); + + var orig =controllerUtils.isFocusedWallet; + controllerUtils.isFocusedWallet = sinon.stub().returns(true); //retuns values in DEFAULT UNIT(bits) controllerUtils.updateBalance(null, function() { + + expect($rootScope.totalBalanceBTC).to.be.equal(1.00000001); expect($rootScope.availableBalanceBTC).to.be.equal(0.90000002); expect($rootScope.lockedBalanceBTC).to.be.equal(0.09999999); @@ -87,9 +92,12 @@ describe("Angular services", function() { expect($rootScope.availableBalance).to.be.equal(900000.02); expect($rootScope.lockedBalance).to.be.equal(99999.99); - expect($rootScope.addrInfos).not.to.equal(null); - expect($rootScope.addrInfos[0].address).to.equal(Waddr); + expect($rootScope.balanceByAddr[Waddr]).to.equal(2); + expect($rootScope.safeUnspentCount).to.equal(5); + expect($rootScope.topAmount).to.equal(899800.02); }); + + controllerUtils.isFocusedWallet = orig; })); it('should set the rootScope', inject(function(controllerUtils, $rootScope) {