tests
This commit is contained in:
parent
8d25f23849
commit
42ae722db9
|
@ -1179,7 +1179,7 @@ WalletService.prototype.getSendMaxInfo = function(opts, cb) {
|
||||||
|
|
||||||
var inputs = _.reject(utxos, 'locked');
|
var inputs = _.reject(utxos, 'locked');
|
||||||
if (opts.excludeUnconfirmedUtxos) {
|
if (opts.excludeUnconfirmedUtxos) {
|
||||||
inputs = _.filter(inptus, 'confirmations');
|
inputs = _.filter(inputs, 'confirmations');
|
||||||
}
|
}
|
||||||
inputs = _.sortBy(inputs, 'satoshis');
|
inputs = _.sortBy(inputs, 'satoshis');
|
||||||
|
|
||||||
|
@ -1197,7 +1197,10 @@ WalletService.prototype.getSendMaxInfo = function(opts, cb) {
|
||||||
_.eachRight(inputs, function(input) {
|
_.eachRight(inputs, function(input) {
|
||||||
txp.inputs.push(input);
|
txp.inputs.push(input);
|
||||||
var fee = txp.getEstimatedFee();
|
var fee = txp.getEstimatedFee();
|
||||||
if (fee - lastFee > input.satoshis) return false;
|
if (fee - lastFee > input.satoshis) {
|
||||||
|
txp.inputs.pop();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
lastFee = fee;
|
lastFee = fee;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -3267,7 +3267,6 @@ describe('Wallet service', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should select smaller utxos if within fee constraints', function(done) {
|
it('should select smaller utxos if within fee constraints', function(done) {
|
||||||
helpers.stubUtxos(server, wallet, [1, '800bit', '800bit', '800bit'], function() {
|
helpers.stubUtxos(server, wallet, [1, '800bit', '800bit', '800bit'], function() {
|
||||||
var txOpts = {
|
var txOpts = {
|
||||||
|
@ -3546,6 +3545,20 @@ describe('Wallet service', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#createTx backoff time', function() {
|
||||||
|
var server, wallet, txid;
|
||||||
|
|
||||||
|
beforeEach(function(done) {
|
||||||
|
helpers.createAndJoinWallet(2, 2, function(s, w) {
|
||||||
|
server = s;
|
||||||
|
wallet = w;
|
||||||
|
helpers.stubUtxos(server, wallet, _.range(2, 6), function() {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
it('should ignore small utxos if fee is higher', function(done) {
|
it('should ignore small utxos if fee is higher', function(done) {
|
||||||
helpers.stubUtxos(server, wallet, [].concat(_.times(10, function() {
|
helpers.stubUtxos(server, wallet, [].concat(_.times(10, function() {
|
||||||
return '30bit';
|
return '30bit';
|
||||||
|
@ -3583,6 +3596,116 @@ describe('Wallet service', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#getSendMaxInfo', function() {
|
||||||
|
var server, wallet;
|
||||||
|
beforeEach(function(done) {
|
||||||
|
helpers.createAndJoinWallet(2, 3, function(s, w) {
|
||||||
|
server = s;
|
||||||
|
wallet = w;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be able to get send max info on empty wallet', function(done) {
|
||||||
|
server.getSendMaxInfo({
|
||||||
|
feePerKb: 10000,
|
||||||
|
excludeUnconfirmedUtxos: false,
|
||||||
|
}, function(err, info) {
|
||||||
|
should.not.exist(err);
|
||||||
|
should.exist(info);
|
||||||
|
info.size.should.equal(0);
|
||||||
|
info.amount.should.equal(0);
|
||||||
|
info.fee.should.equal(0);
|
||||||
|
info.nbInputs.should.equal(0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('should correctly get send max info', function(done) {
|
||||||
|
helpers.stubUtxos(server, wallet, [0.1, 0.2, 0.3, 0.4], function() {
|
||||||
|
server.getSendMaxInfo({
|
||||||
|
feePerKb: 10000,
|
||||||
|
excludeUnconfirmedUtxos: false,
|
||||||
|
}, function(err, info) {
|
||||||
|
should.not.exist(err);
|
||||||
|
should.exist(info);
|
||||||
|
info.nbInputs.should.equal(4);
|
||||||
|
info.size.should.equal(1342);
|
||||||
|
info.fee.should.equal(info.size * 10000 / 1000.);
|
||||||
|
info.amount.should.equal(1e8 - info.fee);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('should exclude unconfirmed inputs', function(done) {
|
||||||
|
helpers.stubUtxos(server, wallet, ['u0.1', 0.2, 0.3, 0.4], function() {
|
||||||
|
server.getSendMaxInfo({
|
||||||
|
feePerKb: 10000,
|
||||||
|
excludeUnconfirmedUtxos: true,
|
||||||
|
}, function(err, info) {
|
||||||
|
should.not.exist(err);
|
||||||
|
should.exist(info);
|
||||||
|
info.nbInputs.should.equal(3);
|
||||||
|
info.size.should.equal(1031);
|
||||||
|
info.fee.should.equal(info.size * 10000 / 1000.);
|
||||||
|
info.amount.should.equal(0.9e8 - info.fee);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('should exlude locked inputs', function(done) {
|
||||||
|
helpers.stubUtxos(server, wallet, ['u0.1', 0.1, 0.1, 0.1], function() {
|
||||||
|
var txOpts = {
|
||||||
|
outputs: [{
|
||||||
|
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
|
||||||
|
amount: 0.09e8,
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
helpers.createAndPublishTx(server, txOpts, TestData.copayers[0].privKey_1H_0, function(tx) {
|
||||||
|
should.exist(tx);
|
||||||
|
server.getSendMaxInfo({
|
||||||
|
feePerKb: 10000,
|
||||||
|
excludeUnconfirmedUtxos: true,
|
||||||
|
}, function(err, info) {
|
||||||
|
should.not.exist(err);
|
||||||
|
should.exist(info);
|
||||||
|
info.nbInputs.should.equal(2);
|
||||||
|
info.size.should.equal(720);
|
||||||
|
info.fee.should.equal(info.size * 10000 / 1000.);
|
||||||
|
info.amount.should.equal(0.2e8 - info.fee);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('should ignore utxos not contributing to total amount (below their cost in fee)', function(done) {
|
||||||
|
helpers.stubUtxos(server, wallet, ['u0.1', 0.2, 0.3, 0.4, 0.000001, 0.0002, 0.0003], function() {
|
||||||
|
server.getSendMaxInfo({
|
||||||
|
feePerKb: 0.001e8,
|
||||||
|
excludeUnconfirmedUtxos: false,
|
||||||
|
}, function(err, info) {
|
||||||
|
should.not.exist(err);
|
||||||
|
should.exist(info);
|
||||||
|
info.nbInputs.should.equal(4);
|
||||||
|
info.size.should.equal(1342);
|
||||||
|
info.fee.should.equal(info.size * 0.001e8 / 1000.);
|
||||||
|
info.amount.should.equal(1e8 - info.fee);
|
||||||
|
server.getSendMaxInfo({
|
||||||
|
feePerKb: 0.0001e8,
|
||||||
|
excludeUnconfirmedUtxos: false,
|
||||||
|
}, function(err, info) {
|
||||||
|
should.not.exist(err);
|
||||||
|
should.exist(info);
|
||||||
|
info.nbInputs.should.equal(6);
|
||||||
|
info.size.should.equal(1964);
|
||||||
|
info.fee.should.equal(info.size * 0.0001e8 / 1000.);
|
||||||
|
info.amount.should.equal(1.0005e8 - info.fee);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
describe('#rejectTx', function() {
|
describe('#rejectTx', function() {
|
||||||
var server, wallet, txid;
|
var server, wallet, txid;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue