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 10c055b..a1e79a9 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -2308,6 +2308,84 @@ 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 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', + 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.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); + txs.length.should.equal(1); + done(); + }); + }); + }); + }); + }); + }); it('should be able to publish a temporary tx proposal', function(done) { helpers.stubUtxos(server, wallet, [1, 2], function() { var txOpts = {