handle 0 input txs

This commit is contained in:
Ivan Socolsky 2016-03-18 15:56:10 -03:00
parent 93a8d65932
commit 6b8af51993
2 changed files with 19 additions and 1 deletions

View File

@ -1207,6 +1207,9 @@ WalletService.prototype.getSendMaxInfo = function(opts, cb) {
lastFee = fee; lastFee = fee;
}); });
if (_.isEmpty(txp.inputs)) return cb(null, info);
info.size = txp.getEstimatedSize(); info.size = txp.getEstimatedSize();
info.fee = txp.getEstimatedFee(); info.fee = txp.getEstimatedFee();
info.amount = _.sum(txp.inputs, 'satoshis') - info.fee; info.amount = _.sum(txp.inputs, 'satoshis') - info.fee;

View File

@ -3745,7 +3745,6 @@ describe('Wallet service', function() {
}); });
}); });
}); });
it('should exclude unconfirmed inputs', function(done) { it('should exclude unconfirmed inputs', function(done) {
helpers.stubUtxos(server, wallet, ['u0.1', 0.2, 0.3, 0.4], function() { helpers.stubUtxos(server, wallet, ['u0.1', 0.2, 0.3, 0.4], function() {
server.getSendMaxInfo({ server.getSendMaxInfo({
@ -3817,6 +3816,22 @@ describe('Wallet service', function() {
}); });
}); });
}); });
it('should work when all inputs are below their cost in fee', function(done) {
helpers.stubUtxos(server, wallet, ['u 10bit', '10bit', '20bit'], function() {
server.getSendMaxInfo({
feePerKb: 500e2,
returnInputs: true,
}, function(err, info) {
should.not.exist(err);
should.exist(info);
info.inputs.should.be.empty;
info.size.should.equal(0);
info.fee.should.equal(0);
info.amount.should.equal(0);
done();
});
});
});
it('should not go beyond max tx size', function(done) { it('should not go beyond max tx size', function(done) {
var _oldDefault = Defaults.MAX_TX_SIZE_IN_KB; var _oldDefault = Defaults.MAX_TX_SIZE_IN_KB;
Defaults.MAX_TX_SIZE_IN_KB = 2; Defaults.MAX_TX_SIZE_IN_KB = 2;