more testing

This commit is contained in:
Ivan Socolsky 2016-08-22 20:27:59 -03:00
parent 03858e4f4b
commit c5e4c4b9a4
No known key found for this signature in database
GPG Key ID: FAECE6A05FAA4F56
2 changed files with 65 additions and 14 deletions

View File

@ -1793,8 +1793,8 @@ WalletService.prototype.createTx = function(opts, cb) {
function getFeePerKb(wallet, cb) { function getFeePerKb(wallet, cb) {
if (opts.inputs && _.isNumber(opts.fee)) return null; if (opts.inputs && _.isNumber(opts.fee)) return cb();
if (_.isNumber(opts.feePerKb)) return opts.feePerKb; if (_.isNumber(opts.feePerKb)) return cb(null, opts.feePerKb);
self.getFeeLevels({ self.getFeeLevels({
network: wallet.network network: wallet.network
}, function(err, levels) { }, function(err, levels) {

View File

@ -2360,8 +2360,23 @@ describe('Wallet service', function() {
done(); done();
}); });
}); });
it.skip('should fail to specify both feeLevel & feePerKb', function(done) { it('should fail to specify both feeLevel & feePerKb', function(done) {
helpers.stubUtxos(server, wallet, 2, function() {
var txOpts = {
outputs: [{
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
amount: 1e8,
}],
feeLevel: 'normal',
feePerKb: 123e2,
};
server.createTx(txOpts, function(err, txp) {
should.exist(err);
should.not.exist(txp);
err.toString().should.contain('Only one of feeLevel/feePerKb');
done();
});
});
}); });
it('should be able to create tx with inputs argument', function(done) { it('should be able to create tx with inputs argument', function(done) {
helpers.stubUtxos(server, wallet, [1, 3, 2], function(utxos) { helpers.stubUtxos(server, wallet, [1, 3, 2], function(utxos) {
@ -2731,33 +2746,69 @@ describe('Wallet service', function() {
}); });
}); });
describe.only('Fee levels', function() { describe('Fee levels', function() {
it('should create a tx specifying feeLevel', function(done) { it('should create a tx specifying feeLevel', function(done) {
helpers.stubFeeLevels({ helpers.stubFeeLevels({
1: 40000, 1: 400e2,
2: 20000, 2: 200e2,
6: 18000, 6: 180e2,
24: 9000, 24: 90e2,
}); });
helpers.stubUtxos(server, wallet, [1, 2], function() { helpers.stubUtxos(server, wallet, 2, function() {
var txOpts = { var txOpts = {
outputs: [{ outputs: [{
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
amount: 0.8 * 1e8, amount: 1e8,
}], }],
feeLevel: 'economy', feeLevel: 'economy',
}; };
server.createTx(txOpts, function(err, txp) { server.createTx(txOpts, function(err, txp) {
should.not.exist(err); should.not.exist(err);
should.exist(txp); should.exist(txp);
txp.amount.should.equal(helpers.toSatoshi(0.8));
txp.feePerKb.should.equal(180e2); txp.feePerKb.should.equal(180e2);
done(); done();
}); });
}); });
}); });
it.skip('should fail if the specified fee level does not exist', function(done) {}); it('should fail if the specified fee level does not exist', function(done) {
it.skip('should assume "normal" fee level if no feeLevel and no feePerKb/fee is specified', function(done) {}); helpers.stubUtxos(server, wallet, 2, function() {
var txOpts = {
outputs: [{
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
amount: 1e8,
}],
feeLevel: 'madeUpLevel',
};
server.createTx(txOpts, function(err, txp) {
should.exist(err);
should.not.exist(txp);
err.toString().should.contain('Invalid fee level');
done();
});
});
});
it('should assume "normal" fee level if no feeLevel and no feePerKb/fee is specified', function(done) {
helpers.stubFeeLevels({
1: 400e2,
2: 200e2,
6: 180e2,
24: 90e2,
});
helpers.stubUtxos(server, wallet, 2, function() {
var txOpts = {
outputs: [{
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
amount: 1e8,
}],
};
server.createTx(txOpts, function(err, txp) {
should.not.exist(err);
should.exist(txp);
txp.feePerKb.should.equal(200e2);
done();
});
});
});
}); });
it('should generate new change address for each created tx', function(done) { it('should generate new change address for each created tx', function(done) {
helpers.stubUtxos(server, wallet, [1, 2], function() { helpers.stubUtxos(server, wallet, [1, 2], function() {