From f8d9ca542d99c68086ad7543d4d5fce432228482 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Tue, 18 Aug 2015 17:56:46 -0300 Subject: [PATCH] implement get status & improve tests --- lib/server.js | 45 ++++++++++++++++++++++++++++++++++++++ test/integration/server.js | 29 +++++++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/lib/server.js b/lib/server.js index d881ad9..a3f0631 100644 --- a/lib/server.js +++ b/lib/server.js @@ -272,6 +272,51 @@ WalletService.prototype.getWallet = function(opts, cb) { }); }; +/** + * Retrieves wallet status. + * @param {Object} opts + * @returns {Object} status + */ +WalletService.prototype.getStatus = function(opts, cb) { + var self = this; + + var status = {}; + async.parallel([ + + function(next) { + self.getWallet({}, function(err, wallet) { + if (err) return next(err); + status.wallet = wallet; + next(); + }); + }, + function(next) { + self.getBalance({}, function(err, balance) { + if (err) return next(err); + status.balance = balance; + next(); + }); + }, + function(next) { + self.getPendingTxs({}, function(err, pendingTxps) { + if (err) return next(err); + status.pendingTxps = pendingTxps; + next(); + }); + }, + function(next) { + self.getPreferences({}, function(err, preferences) { + if (err) return next(err); + status.preferences = preferences; + next(); + }); + }, + ], function(err) { + if (err) return cb(err); + return cb(null, status); + }); +}; + /* * Verifies a signature * @param text diff --git a/test/integration/server.js b/test/integration/server.js index d5e6ed1..3fba9fc 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -1131,9 +1131,36 @@ describe('Wallet service', function() { server.getStatus({}, function(err, status) { should.not.exist(err); should.exist(status); + should.exist(status.wallet); + status.wallet.name.should.equal(wallet.name); + should.exist(status.wallet.copayers); + status.wallet.copayers.length.should.equal(1); + should.exist(status.balance); + status.balance.totalAmount.should.equal(0); + should.exist(status.preferences); + should.exist(status.pendingTxps); + status.pendingTxps.should.be.empty; done(); }); }); + it('should get status after tx creation', function(done) { + helpers.stubUtxos(server, wallet, [100, 200], function() { + var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 80, 'some message', TestData.copayers[0].privKey_1H_0); + server.createTx(txOpts, function(err, tx) { + should.not.exist(err); + should.exist(tx); + server.getStatus({}, function(err, status) { + should.not.exist(err); + status.pendingTxps.length.should.equal(1); + var balance = status.balance; + balance.totalAmount.should.equal(helpers.toSatoshi(300)); + balance.lockedAmount.should.equal(tx.inputs[0].satoshis); + balance.availableAmount.should.equal(balance.totalAmount - balance.lockedAmount); + done(); + }); + }); + }); + }); }); describe('#verifyMessageSignature', function() { @@ -1853,8 +1880,8 @@ describe('Wallet service', function() { isChange: true }); change.length.should.equal(1); + done(); }); - done(); }); }); });