From 7073cef3f66b0226d07816734675aff1b6462936 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Fri, 19 Aug 2016 12:32:11 -0300 Subject: [PATCH 1/2] restore foreign ID tests --- test/integration/server.js | 88 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/test/integration/server.js b/test/integration/server.js index 10c055b..618f15d 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -2308,6 +2308,94 @@ describe('Wallet service', function() { }); }); }); + it('should create a tx with foreign ID', function(done) { + helpers.stubUtxos(server, wallet, 2, function() { + var txOpts = { + txProposalId: '123', + outputs: [{ + toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', + amount: 1e8, + }], + feePerKb: 100e2, + }; + server.createTx(txOpts, function(err, tx) { + should.not.exist(err); + should.exist(tx); + tx.id.should.equal('123'); + done(); + }); + }); + }); + it('should return already created tx if same foreign ID is specified and tx still unpublished', function(done) { + helpers.stubUtxos(server, wallet, 2, function() { + var txOpts = { + txProposalId: '123', + outputs: [{ + toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', + amount: 1e8, + }], + feePerKb: 100e2, + }; + server.createTx(txOpts, function(err, tx) { + should.not.exist(err); + should.exist(tx); + tx.id.should.equal('123'); + server.createTx(txOpts, function(err, tx) { + should.not.exist(err); + should.exist(tx); + tx.id.should.equal('123'); + server.storage.fetchTxs(wallet.id, {}, function(err, txs) { + should.not.exist(err); + should.exist(txs); + txs.length.should.equal(1); + done(); + }); + }); + }); + }); + }); + it('should fail to create tx if same foreign ID is specified and tx already published', function(done) { + helpers.stubUtxos(server, wallet, [2, 2, 2], function() { + var txOpts = { + txProposalId: '123', + outputs: [{ + toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', + amount: 1e8, + }], + feePerKb: 100e2, + }; + server.createTx(txOpts, function(err, tx) { + should.not.exist(err); + should.exist(tx); + tx.id.should.equal('123'); + var publishOpts = helpers.getProposalSignatureOpts(tx, TestData.copayers[0].privKey_1H_0); + server.publishTx(publishOpts, function(err) { + should.not.exist(err); + server.createTx(txOpts, function(err, tx) { + should.exist(err); + should.not.exist(tx); + err.code.should.equal('TX_ALREADY_EXISTS'); + server.storage.fetchTxs(wallet.id, {}, function(err, txs) { + should.not.exist(err); + should.exist(txs); + txs.length.should.equal(1); + txOpts.txProposalId = null; + server.createTx(txOpts, function(err, tx) { + should.not.exist(err); + should.exist(tx); + tx.id.should.not.equal('123'); + server.storage.fetchTxs(wallet.id, {}, function(err, txs) { + should.not.exist(err); + txs.length.should.equal(2); + done(); + }); + }); + }); + }); + }); + }); + }); + }); it('should be able to publish a temporary tx proposal', function(done) { helpers.stubUtxos(server, wallet, [1, 2], function() { var txOpts = { From 6d98c8beef8f213ff94f14cd0792267363984555 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Fri, 19 Aug 2016 13:08:14 -0300 Subject: [PATCH 2/2] return tx with same foreign ID regardless of status --- lib/errors/errordefinitions.js | 1 - lib/server.js | 10 +--------- test/integration/server.js | 22 ++++++---------------- 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/lib/errors/errordefinitions.js b/lib/errors/errordefinitions.js index 3a09d69..f5c8c2f 100644 --- a/lib/errors/errordefinitions.js +++ b/lib/errors/errordefinitions.js @@ -23,7 +23,6 @@ var errors = { NOT_AUTHORIZED: 'Not authorized', TOO_MANY_KEYS: 'Too many keys registered', TX_ALREADY_BROADCASTED: 'The transaction proposal is already broadcasted', - TX_ALREADY_EXISTS: 'A transaction proposal with the same id already exists', TX_CANNOT_CREATE: 'Cannot create TX proposal during backoff time', TX_CANNOT_REMOVE: 'Cannot remove this tx proposal during locktime', TX_MAX_SIZE_EXCEEDED: 'TX exceeds maximum allowed size', diff --git a/lib/server.js b/lib/server.js index 1864ad0..bcbe178 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1776,15 +1776,7 @@ WalletService.prototype.createTx = function(opts, cb) { function checkTxpAlreadyExists(txProposalId, cb) { if (!txProposalId) return cb(); - - self.storage.fetchTx(self.walletId, txProposalId, function(err, txp) { - if (err || !txp) return cb(err); - if (txp.status == 'temporary') { - return cb(null, txp); - } else { - return cb(Errors.TX_ALREADY_EXISTS); - } - }); + self.storage.fetchTx(self.walletId, txProposalId, cb); }; self._runLocked(cb, function(cb) { diff --git a/test/integration/server.js b/test/integration/server.js index 618f15d..a1e79a9 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -2354,7 +2354,7 @@ describe('Wallet service', function() { }); }); }); - it('should fail to create tx if same foreign ID is specified and tx already published', function(done) { + it('should return already published tx if same foreign ID is specified and tx already published', function(done) { helpers.stubUtxos(server, wallet, [2, 2, 2], function() { var txOpts = { txProposalId: '123', @@ -2372,24 +2372,14 @@ describe('Wallet service', function() { server.publishTx(publishOpts, function(err) { should.not.exist(err); server.createTx(txOpts, function(err, tx) { - should.exist(err); - should.not.exist(tx); - err.code.should.equal('TX_ALREADY_EXISTS'); + should.not.exist(err); + should.exist(tx); + tx.id.should.equal('123'); + tx.status.should.equal('pending'); server.storage.fetchTxs(wallet.id, {}, function(err, txs) { should.not.exist(err); - should.exist(txs); txs.length.should.equal(1); - txOpts.txProposalId = null; - server.createTx(txOpts, function(err, tx) { - should.not.exist(err); - should.exist(tx); - tx.id.should.not.equal('123'); - server.storage.fetchTxs(wallet.id, {}, function(err, txs) { - should.not.exist(err); - txs.length.should.equal(2); - done(); - }); - }); + done(); }); }); });