Browse Source

check fee limits

activeAddress
Ivan Socolsky 9 years ago
parent
commit
77dc536a15
  1. 2
      lib/common/defaults.js
  2. 4
      lib/server.js
  3. 105
      test/integration/server.js

2
lib/common/defaults.js

@ -6,7 +6,7 @@ Defaults.DEFAULT_FEE_PER_KB = 10000;
Defaults.MIN_FEE_PER_KB = 0; Defaults.MIN_FEE_PER_KB = 0;
Defaults.MAX_FEE_PER_KB = 1000000; Defaults.MAX_FEE_PER_KB = 1000000;
Defaults.MIN_TX_FEE = 0; Defaults.MIN_TX_FEE = 0;
Defaults.MAX_TX_FEE = 1 * 1e8; Defaults.MAX_TX_FEE = 0.1 * 1e8;
Defaults.MAX_KEYS = 100; Defaults.MAX_KEYS = 100;

4
lib/server.js

@ -1,4 +1,5 @@
'use strict'; 'use strict';
var _ = require('lodash'); var _ = require('lodash');
var $ = require('preconditions').singleton(); var $ = require('preconditions').singleton();
var async = require('async'); var async = require('async');
@ -1552,7 +1553,8 @@ WalletService.prototype.createTx = function(opts, cb) {
return cb(new ClientError('Required argument missing')); return cb(new ClientError('Required argument missing'));
if (_.isNumber(opts.fee)) { if (_.isNumber(opts.fee)) {
if (opts.fee < Defaults.MIN_FEE || opts.fee > Defaults.MAX_FEE) opts.feePerKb = null;
if (opts.fee < Defaults.MIN_TX_FEE || opts.fee > Defaults.MAX_TX_FEE)
return cb(new ClientError('Invalid fee')); return cb(new ClientError('Invalid fee'));
} else { } else {
opts.fee = null; opts.fee = null;

105
test/integration/server.js

@ -2693,13 +2693,14 @@ describe('Wallet service', function() {
it('should create a tx', function(done) { it('should create a tx', function(done) {
helpers.stubUtxos(server, wallet, [1, 2], function() { helpers.stubUtxos(server, wallet, [1, 2], function() {
var txOpts = helpers.createProposalOpts2([{ var txOpts = {
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', outputs: [{
amount: 0.8 toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
}], { amount: 0.8 * 1e8,
}],
message: 'some message', message: 'some message',
customData: 'some custom data', customData: 'some custom data',
}); };
server.createTx(txOpts, function(err, tx) { server.createTx(txOpts, function(err, tx) {
should.not.exist(err); should.not.exist(err);
should.exist(tx); should.exist(tx);
@ -2723,12 +2724,13 @@ describe('Wallet service', function() {
it('should be able to specify the final fee', function(done) { it('should be able to specify the final fee', function(done) {
helpers.stubUtxos(server, wallet, [1, 2], function() { helpers.stubUtxos(server, wallet, [1, 2], function() {
var txOpts = helpers.createProposalOpts2([{ var txOpts = {
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', outputs: [{
amount: 0.8, toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
}], { amount: 0.8 * 1e8,
}],
fee: 123400, fee: 123400,
}); };
server.createTx(txOpts, function(err, tx) { server.createTx(txOpts, function(err, tx) {
should.not.exist(err); should.not.exist(err);
should.exist(tx); should.exist(tx);
@ -2740,15 +2742,33 @@ describe('Wallet service', function() {
}); });
}); });
it('should check explicit fee to be below max', function(done) {
helpers.stubUtxos(server, wallet, [1, 2], function() {
var txOpts = {
outputs: [{
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
amount: 0.8 * 1e8,
}],
fee: 1e8,
};
server.createTx(txOpts, function(err, tx) {
should.exist(err);
err.message.should.contain('fee');
done();
});
});
});
it('should be able to send a temporary tx proposal', function(done) { it('should be able to send a temporary tx proposal', function(done) {
helpers.stubUtxos(server, wallet, [1, 2], function() { helpers.stubUtxos(server, wallet, [1, 2], function() {
var txOpts = helpers.createProposalOpts2([{ var txOpts = {
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', outputs: [{
amount: 0.8 toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
}], { amount: 0.8 * 1e8,
}],
message: 'some message', message: 'some message',
customData: 'some custom data', customData: 'some custom data',
}); };
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);
@ -2782,12 +2802,13 @@ describe('Wallet service', function() {
it('should fail to send tx proposal with wrong signature', function(done) { it('should fail to send tx proposal with wrong signature', function(done) {
helpers.stubUtxos(server, wallet, [1, 2], function() { helpers.stubUtxos(server, wallet, [1, 2], function() {
var txOpts = helpers.createProposalOpts2([{ var txOpts = {
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', outputs: [{
amount: 0.8 toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
}], { amount: 0.8 * 1e8,
}],
message: 'some message', message: 'some message',
}); };
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);
@ -2805,12 +2826,13 @@ describe('Wallet service', function() {
it('should fail to send tx proposal not signed by the creator', function(done) { it('should fail to send tx proposal not signed by the creator', function(done) {
helpers.stubUtxos(server, wallet, [1, 2], function() { helpers.stubUtxos(server, wallet, [1, 2], function() {
var txOpts = helpers.createProposalOpts2([{ var txOpts = {
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', outputs: [{
amount: 0.8 toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
}], { amount: 0.8 * 1e8,
}],
message: 'some message', message: 'some message',
}); };
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);
@ -2845,12 +2867,13 @@ describe('Wallet service', function() {
should.not.exist(err); should.not.exist(err);
helpers.stubUtxos(server, wallet, [1, 2], function() { helpers.stubUtxos(server, wallet, [1, 2], function() {
var txOpts = helpers.createProposalOpts2([{ var txOpts = {
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', outputs: [{
amount: 0.8 toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
}], { amount: 0.8 * 1e8,
}],
message: 'some message', message: 'some message',
}); };
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);
@ -2879,12 +2902,13 @@ describe('Wallet service', function() {
it('should fail to send a temporary tx proposal if utxos are unavailable', function(done) { it('should fail to send a temporary tx proposal if utxos are unavailable', function(done) {
var txp1, txp2; var txp1, txp2;
var txOpts = helpers.createProposalOpts2([{ var txOpts = {
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', outputs: [{
amount: 0.8 toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
}], { amount: 0.8 * 1e8,
}],
message: 'some message', message: 'some message',
}); };
async.waterfall([ async.waterfall([
@ -2946,13 +2970,14 @@ describe('Wallet service', function() {
it('should fail to list pending proposals from legacy client', function(done) { it('should fail to list pending proposals from legacy client', function(done) {
helpers.stubUtxos(server, wallet, [1, 2], function() { helpers.stubUtxos(server, wallet, [1, 2], function() {
var txOpts = helpers.createProposalOpts2([{ var txOpts = {
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', outputs: [{
amount: 0.8 toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
}], { amount: 0.8 * 1e8,
}],
message: 'some message', message: 'some message',
customData: 'some custom data', customData: 'some custom data',
}); };
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);

Loading…
Cancel
Save