From ce910fe52fb40f5cb04f9806d0686cc04551637e Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 21 Aug 2014 16:02:02 -0300 Subject: [PATCH] Check tx proposal minimum amount --- config.js | 3 ++- js/controllers/send.js | 1 + js/models/core/Wallet.js | 1 + test/test.Wallet.js | 20 +++++++++++++++++++- views/send.html | 2 +- 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/config.js b/config.js index 659457933..4da6227cc 100644 --- a/config.js +++ b/config.js @@ -11,7 +11,8 @@ var defaultConfig = { // wallet limits limits: { totalCopayers: 12, - mPlusN: 100 + mPlusN: 100, + minAmountSatoshi: 5400, }, // network layer (PeerJS) config diff --git a/js/controllers/send.js b/js/controllers/send.js index c671aeebc..c2e9a039b 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -8,6 +8,7 @@ angular.module('copayApp.controllers').controller('SendController', var satToUnit = 1 / config.unitToSatoshi; $scope.defaultFee = bitcore.TransactionBuilder.FEE_PER_1000B_SAT * satToUnit; $scope.unitToBtc = config.unitToSatoshi / bitcore.util.COIN; + $scope.minAmount = config.limits.minAmountSatoshi * satToUnit; $scope.loadTxs = function() { var opts = { diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 3020159d6..c08687879 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -1534,6 +1534,7 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos preconditions.checkArgument(new Address(toAddress).network().name === this.getNetworkName(), 'networkname mismatch'); preconditions.checkState(pkr.isComplete(), 'pubkey ring incomplete'); preconditions.checkState(priv, 'no private key'); + preconditions.checkArgument(bignum(amountSatStr, 10).cmp(copayConfig.limits.minAmountSatoshi) >= 0, 'invalid amount'); if (comment) preconditions.checkArgument(comment.length <= 100); if (!opts.remainderOut) { diff --git a/test/test.Wallet.js b/test/test.Wallet.js index dae8de607..59ac675ca 100644 --- a/test/test.Wallet.js +++ b/test/test.Wallet.js @@ -630,7 +630,7 @@ describe('Wallet model', function() { return utxo; }; var toAddress = 'mjfAe7YrzFujFf8ub5aUrCaN5GfSABdqjh'; - var amountSatStr = '1000'; + var amountSatStr = '10000'; it('should create transaction', function(done) { var w = cachedCreateW2(); @@ -641,6 +641,7 @@ describe('Wallet model', function() { done(); }); }); + it('should create & sign transaction from received funds', function(done) { var k2 = new PrivateKey({ networkName: config.networkName @@ -724,6 +725,23 @@ describe('Wallet model', function() { }); }); + describe('#createTxSync', function () { + it('should fail if amount below min value', function() { + var w = cachedCreateW2(); + var utxo = createUTXO(w); + + var badCreate = function() { + w.createTxSync( + 'mgGJEugdPnvhmRuFdbdQcFfoFLc1XXeB79', + '123', + null, + utxo + ); + } + chai.expect(badCreate).to.throw('invalid amount'); + }); + }); + describe('#send', function() { it('should call this.network.send', function() { var w = cachedCreateW2(); diff --git a/views/send.html b/views/send.html index 05328c8e3..a2d82be0d 100644 --- a/views/send.html +++ b/views/send.html @@ -67,7 +67,7 @@