From b69edc44f2eef7dafd813be9582b1f52fb6c24a2 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Tue, 26 Jul 2016 11:00:09 -0300 Subject: [PATCH] test tx creation with foreign id --- test/integration/server.js | 78 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/test/integration/server.js b/test/integration/server.js index 4026505..387783d 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -2982,6 +2982,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 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); + done(); + }); + }); + }); + }); + }); + }); it('should be able to publish a temporary tx proposal', function(done) { helpers.stubUtxos(server, wallet, [1, 2], function() { var txOpts = {