From d4b2ac1ad4f875c7aa22deb0c63e44f75b864724 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 15 Apr 2014 15:50:22 -0300 Subject: [PATCH] add wallet tests --- js/models/core/Wallet.js | 18 +++++++++-------- test/test.wallet.js | 42 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index f876ba3d0..75674a567 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -35,6 +35,7 @@ Wallet.prototype._startInterface = function(config) { Wallet.prototype.create = function(opts) { + opts = opts || {}; this.id = opts.id || Wallet.getRandomId(); this.log('### CREATING NEW WALLET.' + (opts.id ? ' USING ID: ' + opts.id : ' NEW ID')); @@ -67,14 +68,6 @@ Wallet.prototype._checkLoad = function(walletId) { this.storage.get(walletId, 'txProposals') && this.storage.get(walletId, 'privateKey') ; - -console.log('[Wallet.js.71]', - this.storage.get(walletId, 'publicKeyRing'), - this.storage.get(walletId, 'txProposals'), - this.storage.get(walletId, 'privateKey')); - -console.log('[Wallet.js.73:ret:]',walletId, ret); //TODO - return ret; } @@ -169,6 +162,15 @@ Wallet.prototype.addSeenToTxProposals = function() { return ret; }; + +Wallet.prototype.getAddresses = function() { + return this.publicKeyRing.getAddresses(); +}; + +Wallet.prototype.listUnspent = function(cb) { + this.blockchain.listUnspent(this.getAddresses(), cb); +}; + // // HERE? not sure // Wallet.prototype.cleanPeers = function() { // this.storage.remove('peerData'); diff --git a/test/test.wallet.js b/test/test.wallet.js index 54a487da2..c43bfbbe0 100644 --- a/test/test.wallet.js +++ b/test/test.wallet.js @@ -9,6 +9,13 @@ var Wallet = require('soop').load('../js/models/core/Wallet', { Blockchain: copay.Insight }); + +var addCopayers = function (w) { + for(var i=0; i<4; i++) { + w.publicKeyRing.addCopayer(); + } +}; + describe('Wallet model', function() { var config = { wallet: { @@ -19,13 +26,44 @@ describe('Wallet model', function() { var opts = {}; - it.skip('should create an instance', function () { + it('should create an instance', function () { var opts = {}; - var w = Wallet.create(config, opts); + var w = new Wallet(config); should.exist(w); }); + it('should fail to load', function () { + var opts = {}; + var w = new Wallet(config); + w.load(123); + should.not.exist(w.id); + }); + + + it('should create', function () { + var opts = {}; + var w = new Wallet(config); + w.create(); + should.exist(w.id); + should.exist(w.publicKeyRing); + should.exist(w.privateKey); + should.exist(w.txProposals); + }); + + it('should create', function () { + var opts = {}; + var w = new Wallet(config); + w.create(); + addCopayers(w); + w.publicKeyRing.generateAddress(false); + + should.exist(w.id); + w.publicKeyRing.isComplete().should.equal(true); + }); + + + describe('factory', function() { it('should create the factory', function() { should.exist(Wallet.factory);