From 37d27cec40803336556c465020be48bc98212a14 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 7 Mar 2016 09:59:15 -0300 Subject: [PATCH 1/3] create compound index for walletId, createdOn. drop old index --- lib/storage.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/storage.js b/lib/storage.js index c77e3a4..3011cbb 100644 --- a/lib/storage.js +++ b/lib/storage.js @@ -50,7 +50,8 @@ Storage.prototype._createIndexes = function() { id: 1, }); this.db.collection(collections.ADDRESSES).createIndex({ - walletId: 1 + walletId: 1, + createdOn: 1, }); this.db.collection(collections.ADDRESSES).createIndex({ address: 1, @@ -63,6 +64,11 @@ Storage.prototype._createIndexes = function() { type: 1, key: 1, }); + + + this.db.collection(collections.ADDRESSES).dropIndex({ + walletId: 1 + }); }; Storage.prototype.connect = function(opts, cb) { From 722a1d4ae79d1566d3d76556220f3215e5894a3d Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Mon, 29 Feb 2016 12:47:30 -0300 Subject: [PATCH 2/3] add version check --- config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config.js b/config.js index c0479c3..6a7c531 100644 --- a/config.js +++ b/config.js @@ -42,7 +42,8 @@ var config = { }, testnet: { provider: 'insight', - url: 'https://test-insight.bitpay.com:443', + //url: 'https://test-insight.bitpay.com:443', + url: 'http://localhost:3001', // Multiple servers (in priority order) // url: ['http://a.b.c', 'https://test-insight.bitpay.com:443'], }, From 69d099020ff9671ac0b40ca1d7d5cd5194939a11 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 8 Mar 2016 09:28:34 -0300 Subject: [PATCH 3/3] add tests --- test/integration/server.js | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/test/integration/server.js b/test/integration/server.js index 1b78eed..4b6f18d 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -3172,6 +3172,7 @@ describe('Wallet service', function() { describe('UTXO Selection', function() { var server, wallet; beforeEach(function(done) { + log.level = 'debug'; helpers.createAndJoinWallet(2, 3, function(s, w) { server = s; wallet = w; @@ -3198,6 +3199,26 @@ describe('Wallet service', function() { }); }); }); + it('should select a confirmed utxos if within thresholds relative to tx amount', function(done) { + helpers.stubUtxos(server, wallet, [1, 'u 350bit', '100bit', '100bit', '100bit'], function() { + var txOpts = { + outputs: [{ + toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', + amount: 200e2, + }], + feePerKb: 10e2, + }; + server.createTx(txOpts, function(err, txp) { + should.not.exist(err); + should.exist(txp); + txp.inputs.length.should.equal(3); + txp.inputs[0].satoshis.should.equal(10000); + + done(); + }); + }); + }); + it('should select smaller utxos if within fee constraints', function(done) { helpers.stubUtxos(server, wallet, [1, '800bit', '800bit', '800bit'], function() { var txOpts = { @@ -3439,6 +3460,45 @@ describe('Wallet service', function() { }); }); }); + it('should use small utxos if fee is low', function(done) { + helpers.stubUtxos(server, wallet, [].concat(_.times(10, function() { + return '30bit'; + })), function() { + var txOpts = { + outputs: [{ + toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', + amount: 200e2, + }], + feePerKb: 10e2, + }; + server.createTx(txOpts, function(err, txp) { + should.not.exist(err); + should.exist(txp); + txp.inputs.length.should.equal(8); + done(); + }); + }); + }); + it.only('should ignore small utxos if fee is higher', function(done) { + helpers.stubUtxos(server, wallet, [].concat(_.times(10, function() { + return '30bit'; + })), function() { + var txOpts = { + outputs: [{ + toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', + amount: 200e2, + }], + feePerKb: 30e2, + }; + server.createTx(txOpts, function(err, txp) { + err.code.should.equal('INSUFFICIENT_FUNDS_FOR_FEE'); + done(); + }); + }); + }); + + + }); });