fix tests

This commit is contained in:
Ivan Socolsky 2015-12-10 12:36:30 -03:00
parent 0ab57133fd
commit 9868cd7c34
3 changed files with 33 additions and 17 deletions

View File

@ -37,4 +37,7 @@ Defaults.FEE_LEVELS = [{
defaultValue: 10000
}];
// Minimum nb of addresses a wallet must have to start using 2-step balance optimization
Defaults.TWO_STEP_BALANCE_THRESHOLD = 100;
module.exports = Defaults;

View File

@ -1060,6 +1060,12 @@ WalletService.prototype._getActiveAddresses = function(cb) {
WalletService.prototype.getBalance2Steps = function(opts, cb) {
var self = this;
self.storage.countAddresses(self.walletId, function(err, nbAddresses) {
if (err) return cb(err);
if (nbAddresses < Defaults.TWO_STEP_BALANCE_THRESHOLD) {
return self.getBalance(opts, cb);
}
self._getActiveAddresses(function(err, activeAddresses) {
if (err) return cb(err);
if (_.isEmpty(activeAddresses)) {
@ -1081,6 +1087,7 @@ WalletService.prototype.getBalance2Steps = function(opts, cb) {
});
}
});
});
};

View File

@ -389,6 +389,12 @@ Storage.prototype.fetchAddresses = function(walletId, cb) {
});
};
Storage.prototype.countAddresses = function(walletId, cb) {
this.db.collection(collections.ADDRESSES).find({
walletId: walletId,
}).count(cb);
};
Storage.prototype.storeAddress = function(address, cb) {
var self = this;