implement get status & improve tests

This commit is contained in:
Ivan Socolsky 2015-08-18 17:56:46 -03:00
parent d47bb65fdd
commit f8d9ca542d
2 changed files with 73 additions and 1 deletions

View File

@ -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

View File

@ -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();
});
});
});