Merge pull request #1315 from isocolsky/fix/insight_down
Catching errors when trying to create new TXP
This commit is contained in:
commit
ea91c603f9
6 changed files with 63 additions and 45 deletions
|
|
@ -121,7 +121,15 @@ angular.module('copayApp.controllers').controller('SendController',
|
||||||
|
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
|
|
||||||
function done(ntxid, merchantData) {
|
function done(err, ntxid, merchantData) {
|
||||||
|
if (err) {
|
||||||
|
var message = 'The transaction' + (w.isShared() ? ' proposal' : '') + ' could not be created';
|
||||||
|
notification.error('Error', message);
|
||||||
|
$scope.loading = false;
|
||||||
|
$scope.loadTxs();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If user is granted the privilege of choosing
|
// If user is granted the privilege of choosing
|
||||||
// their own amount, add it to the tx.
|
// their own amount, add it to the tx.
|
||||||
if (merchantData && +merchantData.total === 0) {
|
if (merchantData && +merchantData.total === 0) {
|
||||||
|
|
|
||||||
|
|
@ -879,7 +879,6 @@ Wallet.prototype.sendAllTxProposals = function(recipients) {
|
||||||
*/
|
*/
|
||||||
Wallet.prototype.sendTxProposal = function(ntxid, recipients) {
|
Wallet.prototype.sendTxProposal = function(ntxid, recipients) {
|
||||||
preconditions.checkArgument(ntxid);
|
preconditions.checkArgument(ntxid);
|
||||||
|
|
||||||
log.debug('### SENDING txProposal ' + ntxid + ' TO:', recipients || 'All', this.txProposals);
|
log.debug('### SENDING txProposal ' + ntxid + ' TO:', recipients || 'All', this.txProposals);
|
||||||
this.send(recipients, {
|
this.send(recipients, {
|
||||||
type: 'txProposal',
|
type: 'txProposal',
|
||||||
|
|
@ -2030,24 +2029,6 @@ Wallet.prototype.removeTxWithSpentInputs = function(cb) {
|
||||||
Wallet.prototype.createTx = function(toAddress, amountSatStr, comment, opts, cb) {
|
Wallet.prototype.createTx = function(toAddress, amountSatStr, comment, opts, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (_.isFunction(amountSatStr)) {
|
|
||||||
var cb = amountSatStr;
|
|
||||||
var merchant = toAddress;
|
|
||||||
return this.createPaymentTx({
|
|
||||||
uri: merchant
|
|
||||||
}, cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_.isFunction(comment)) {
|
|
||||||
var cb = comment;
|
|
||||||
var merchant = toAddress;
|
|
||||||
var comment = amountSatStr;
|
|
||||||
return this.createPaymentTx({
|
|
||||||
uri: merchant,
|
|
||||||
memo: comment
|
|
||||||
}, cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_.isFunction(opts)) {
|
if (_.isFunction(opts)) {
|
||||||
cb = opts;
|
cb = opts;
|
||||||
opts = {};
|
opts = {};
|
||||||
|
|
@ -2059,14 +2040,18 @@ Wallet.prototype.createTx = function(toAddress, amountSatStr, comment, opts, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getUnspent(function(err, safeUnspent) {
|
this.getUnspent(function(err, safeUnspent) {
|
||||||
|
if (err) return cb(new Error('Could not get list of UTXOs'));
|
||||||
|
|
||||||
var ntxid = self.createTxSync(toAddress, amountSatStr, comment, safeUnspent, opts);
|
var ntxid = self.createTxSync(toAddress, amountSatStr, comment, safeUnspent, opts);
|
||||||
if (ntxid) {
|
if (!ntxid) {
|
||||||
self.sendIndexes();
|
return cb(new Error('Error creating TX'));
|
||||||
self.sendTxProposal(ntxid);
|
|
||||||
self.store();
|
|
||||||
self.emit('txProposalsUpdated');
|
|
||||||
}
|
}
|
||||||
return cb(ntxid);
|
|
||||||
|
self.sendIndexes();
|
||||||
|
self.sendTxProposal(ntxid);
|
||||||
|
self.store();
|
||||||
|
self.emit('txProposalsUpdated');
|
||||||
|
return cb(null, ntxid);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ var FakeWallet = function() {
|
||||||
|
|
||||||
FakeWallet.prototype.createTx = function(toAddress, amountSatStr, comment, opts, cb) {
|
FakeWallet.prototype.createTx = function(toAddress, amountSatStr, comment, opts, cb) {
|
||||||
var callback = cb || opts;
|
var callback = cb || opts;
|
||||||
callback({});
|
callback(null, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
FakeWallet.prototype.sendTx = function(ntxid, cb) {
|
FakeWallet.prototype.sendTx = function(ntxid, cb) {
|
||||||
|
|
|
||||||
|
|
@ -739,7 +739,7 @@ describe('PayPro (in Wallet) model', function() {
|
||||||
uri = address.split(/\s+/)[1];
|
uri = address.split(/\s+/)[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
w.createTx(uri, commentText, function(ntxid, merchantData) {
|
w.createPaymentTx({ uri: uri, memo: commentText }, function(ntxid, merchantData) {
|
||||||
if (w.isShared()) {
|
if (w.isShared()) {
|
||||||
should.exist(ntxid);
|
should.exist(ntxid);
|
||||||
should.exist(merchantData);
|
should.exist(merchantData);
|
||||||
|
|
@ -760,7 +760,7 @@ describe('PayPro (in Wallet) model', function() {
|
||||||
should.exist(w);
|
should.exist(w);
|
||||||
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
||||||
var commentText = 'Hello, server. I\'d like to make a payment.';
|
var commentText = 'Hello, server. I\'d like to make a payment.';
|
||||||
w.createTx(address, commentText, function(ntxid, merchantData) {
|
w.createPaymentTx({ uri: address, memo: commentText }, function(ntxid, merchantData) {
|
||||||
if (w.isShared()) {
|
if (w.isShared()) {
|
||||||
should.exist(ntxid);
|
should.exist(ntxid);
|
||||||
should.exist(merchantData);
|
should.exist(merchantData);
|
||||||
|
|
@ -780,7 +780,7 @@ describe('PayPro (in Wallet) model', function() {
|
||||||
should.exist(w);
|
should.exist(w);
|
||||||
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
||||||
var commentText = 'Hello, server. I\'d like to make a payment.';
|
var commentText = 'Hello, server. I\'d like to make a payment.';
|
||||||
w.createTx(address, commentText, function(ntxid, merchantData) {
|
w.createPaymentTx({ uri: address, memo: commentText }, function(ntxid, merchantData) {
|
||||||
should.exist(ntxid);
|
should.exist(ntxid);
|
||||||
should.exist(merchantData);
|
should.exist(merchantData);
|
||||||
|
|
||||||
|
|
@ -816,7 +816,7 @@ describe('PayPro (in Wallet) model', function() {
|
||||||
should.exist(w);
|
should.exist(w);
|
||||||
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
||||||
var commentText = 'Hello, server. I\'d like to make a payment.';
|
var commentText = 'Hello, server. I\'d like to make a payment.';
|
||||||
w.createTx(address, commentText, function(ntxid, merchantData) {
|
w.createPaymentTx({ uri: address, memo: commentText }, function(ntxid, merchantData) {
|
||||||
should.exist(ntxid);
|
should.exist(ntxid);
|
||||||
should.exist(merchantData);
|
should.exist(merchantData);
|
||||||
|
|
||||||
|
|
@ -843,7 +843,7 @@ describe('PayPro (in Wallet) model', function() {
|
||||||
should.exist(w);
|
should.exist(w);
|
||||||
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
||||||
var commentText = 'Hello, server. I\'d like to make a payment.';
|
var commentText = 'Hello, server. I\'d like to make a payment.';
|
||||||
w.createTx(address, commentText, function(ntxid, merchantData) {
|
w.createPaymentTx({ uri: address, memo: commentText }, function(ntxid, merchantData) {
|
||||||
should.exist(ntxid);
|
should.exist(ntxid);
|
||||||
should.exist(merchantData);
|
should.exist(merchantData);
|
||||||
|
|
||||||
|
|
@ -869,7 +869,7 @@ describe('PayPro (in Wallet) model', function() {
|
||||||
should.exist(w);
|
should.exist(w);
|
||||||
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
|
||||||
var commentText = 'Hello, server. I\'d like to make a payment.';
|
var commentText = 'Hello, server. I\'d like to make a payment.';
|
||||||
w.createTx(address, commentText, function(ntxid, merchantData) {
|
w.createPaymentTx({ uri: address, memo: commentText }, function(ntxid, merchantData) {
|
||||||
should.exist(ntxid);
|
should.exist(ntxid);
|
||||||
should.exist(merchantData);
|
should.exist(merchantData);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -694,7 +694,7 @@ describe('Wallet model', function() {
|
||||||
var w = cachedCreateW2();
|
var w = cachedCreateW2();
|
||||||
var utxo = createUTXO(w);
|
var utxo = createUTXO(w);
|
||||||
w.blockchain.fixUnspent(utxo);
|
w.blockchain.fixUnspent(utxo);
|
||||||
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
||||||
ntxid.length.should.equal(64);
|
ntxid.length.should.equal(64);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
@ -708,7 +708,7 @@ describe('Wallet model', function() {
|
||||||
var w = createW2([k2]);
|
var w = createW2([k2]);
|
||||||
var utxo = createUTXO(w);
|
var utxo = createUTXO(w);
|
||||||
w.blockchain.fixUnspent(utxo);
|
w.blockchain.fixUnspent(utxo);
|
||||||
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
||||||
w.on('txProposalsUpdated', function() {
|
w.on('txProposalsUpdated', function() {
|
||||||
w.getTxProposals()[0].signedByUs.should.equal(true);
|
w.getTxProposals()[0].signedByUs.should.equal(true);
|
||||||
w.getTxProposals()[0].rejectedByUs.should.equal(false);
|
w.getTxProposals()[0].rejectedByUs.should.equal(false);
|
||||||
|
|
@ -724,7 +724,7 @@ describe('Wallet model', function() {
|
||||||
var w = cachedCreateW2();
|
var w = cachedCreateW2();
|
||||||
var utxo = createUTXO(w);
|
var utxo = createUTXO(w);
|
||||||
w.blockchain.fixUnspent(utxo);
|
w.blockchain.fixUnspent(utxo);
|
||||||
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
||||||
(function() {
|
(function() {
|
||||||
w.reject(ntxid);
|
w.reject(ntxid);
|
||||||
}).should.throw('reject a signed');
|
}).should.throw('reject a signed');
|
||||||
|
|
@ -736,7 +736,7 @@ describe('Wallet model', function() {
|
||||||
var oldK = w.privateKey;
|
var oldK = w.privateKey;
|
||||||
var utxo = createUTXO(w);
|
var utxo = createUTXO(w);
|
||||||
w.blockchain.fixUnspent(utxo);
|
w.blockchain.fixUnspent(utxo);
|
||||||
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
||||||
var s = sinon.stub(w, 'getMyCopayerId').returns('213');
|
var s = sinon.stub(w, 'getMyCopayerId').returns('213');
|
||||||
Object.keys(w.txProposals.get(ntxid).rejectedBy).length.should.equal(0);
|
Object.keys(w.txProposals.get(ntxid).rejectedBy).length.should.equal(0);
|
||||||
w.reject(ntxid);
|
w.reject(ntxid);
|
||||||
|
|
@ -750,7 +750,7 @@ describe('Wallet model', function() {
|
||||||
var w = createW2(null, 1);
|
var w = createW2(null, 1);
|
||||||
var utxo = createUTXO(w);
|
var utxo = createUTXO(w);
|
||||||
w.blockchain.fixUnspent(utxo);
|
w.blockchain.fixUnspent(utxo);
|
||||||
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
||||||
w.sendTx(ntxid, function(txid) {
|
w.sendTx(ntxid, function(txid) {
|
||||||
txid.length.should.equal(64);
|
txid.length.should.equal(64);
|
||||||
done();
|
done();
|
||||||
|
|
@ -761,7 +761,7 @@ describe('Wallet model', function() {
|
||||||
var w = createW2(null, 1);
|
var w = createW2(null, 1);
|
||||||
var utxo = createUTXO(w);
|
var utxo = createUTXO(w);
|
||||||
w.blockchain.fixUnspent(utxo);
|
w.blockchain.fixUnspent(utxo);
|
||||||
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
||||||
var txp = w.txProposals.get(ntxid);
|
var txp = w.txProposals.get(ntxid);
|
||||||
// Assign fake builder
|
// Assign fake builder
|
||||||
txp.builder = new Builder();
|
txp.builder = new Builder();
|
||||||
|
|
@ -776,7 +776,7 @@ describe('Wallet model', function() {
|
||||||
var w = createW2(null, 1);
|
var w = createW2(null, 1);
|
||||||
var utxo = createUTXO(w);
|
var utxo = createUTXO(w);
|
||||||
w.blockchain.fixUnspent(utxo);
|
w.blockchain.fixUnspent(utxo);
|
||||||
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
||||||
sinon.stub(w.blockchain, 'broadcast').yields({statusCode: 303});
|
sinon.stub(w.blockchain, 'broadcast').yields({statusCode: 303});
|
||||||
var spyCheckSentTx = sinon.spy(w, '_checkSentTx');
|
var spyCheckSentTx = sinon.spy(w, '_checkSentTx');
|
||||||
w.sendTx(ntxid, function () {});
|
w.sendTx(ntxid, function () {});
|
||||||
|
|
@ -788,7 +788,7 @@ describe('Wallet model', function() {
|
||||||
var w = cachedCreateW2();
|
var w = cachedCreateW2();
|
||||||
var utxo = createUTXO(w);
|
var utxo = createUTXO(w);
|
||||||
w.blockchain.fixUnspent(utxo);
|
w.blockchain.fixUnspent(utxo);
|
||||||
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
||||||
w.sendTxProposal.bind(w).should.throw('Illegal Argument.');
|
w.sendTxProposal.bind(w).should.throw('Illegal Argument.');
|
||||||
(function() {
|
(function() {
|
||||||
w.sendTxProposal(ntxid);
|
w.sendTxProposal(ntxid);
|
||||||
|
|
@ -801,7 +801,7 @@ describe('Wallet model', function() {
|
||||||
var w = cachedCreateW2();
|
var w = cachedCreateW2();
|
||||||
var utxo = createUTXO(w);
|
var utxo = createUTXO(w);
|
||||||
w.blockchain.fixUnspent(utxo);
|
w.blockchain.fixUnspent(utxo);
|
||||||
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
||||||
w.sendAllTxProposals.bind(w).should.not.throw();
|
w.sendAllTxProposals.bind(w).should.not.throw();
|
||||||
(function() {
|
(function() {
|
||||||
w.sendAllTxProposals();
|
w.sendAllTxProposals();
|
||||||
|
|
@ -810,6 +810,19 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#createTx', function () {
|
||||||
|
it('should fail if insight server is down', function (done) {
|
||||||
|
var w = cachedCreateW2();
|
||||||
|
var utxo = createUTXO(w);
|
||||||
|
w.blockchain.fixUnspent(utxo);
|
||||||
|
sinon.stub(w, 'getUnspent').yields('error', null);
|
||||||
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
||||||
|
chai.expect(err.message).to.equal('Could not get list of UTXOs');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('#createTxSync', function() {
|
describe('#createTxSync', function() {
|
||||||
it('should fail if amount below min value', function() {
|
it('should fail if amount below min value', function() {
|
||||||
var w = cachedCreateW2();
|
var w = cachedCreateW2();
|
||||||
|
|
@ -833,7 +846,7 @@ describe('Wallet model', function() {
|
||||||
var utxo = createUTXO(w);
|
var utxo = createUTXO(w);
|
||||||
chai.expect(w.getTxProposals().length).to.equal(0);
|
chai.expect(w.getTxProposals().length).to.equal(0);
|
||||||
w.blockchain.fixUnspent(utxo);
|
w.blockchain.fixUnspent(utxo);
|
||||||
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
||||||
w.sendTxProposal(ntxid);
|
w.sendTxProposal(ntxid);
|
||||||
chai.expect(w.getTxProposals().length).to.equal(1);
|
chai.expect(w.getTxProposals().length).to.equal(1);
|
||||||
|
|
||||||
|
|
@ -858,7 +871,7 @@ describe('Wallet model', function() {
|
||||||
utxo[1].vout = 1;
|
utxo[1].vout = 1;
|
||||||
chai.expect(w.getTxProposals().length).to.equal(0);
|
chai.expect(w.getTxProposals().length).to.equal(0);
|
||||||
w.blockchain.fixUnspent(utxo);
|
w.blockchain.fixUnspent(utxo);
|
||||||
w.createTx(toAddress, '100000', null, function(ntxid) {
|
w.createTx(toAddress, '100000', null, function(err, ntxid) {
|
||||||
w.sendTxProposal(ntxid);
|
w.sendTxProposal(ntxid);
|
||||||
chai.expect(w.getTxProposals().length).to.equal(1);
|
chai.expect(w.getTxProposals().length).to.equal(1);
|
||||||
|
|
||||||
|
|
@ -880,7 +893,7 @@ describe('Wallet model', function() {
|
||||||
var utxo = createUTXO(w);
|
var utxo = createUTXO(w);
|
||||||
chai.expect(w.getTxProposals().length).to.equal(0);
|
chai.expect(w.getTxProposals().length).to.equal(0);
|
||||||
w.blockchain.fixUnspent(utxo);
|
w.blockchain.fixUnspent(utxo);
|
||||||
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
|
w.createTx(toAddress, amountSatStr, null, function(err, ntxid) {
|
||||||
w.sendTxProposal(ntxid);
|
w.sendTxProposal(ntxid);
|
||||||
chai.expect(w.getTxProposals().length).to.equal(1);
|
chai.expect(w.getTxProposals().length).to.equal(1);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -285,6 +285,18 @@ describe("Unit: Controllers", function() {
|
||||||
sinon.assert.callCount(scope.loadTxs, 1);
|
sinon.assert.callCount(scope.loadTxs, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not send txp when there is an error at creation', function() {
|
||||||
|
sendForm.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy');
|
||||||
|
sendForm.amount.$setViewValue(1000);
|
||||||
|
scope.wallet.totalCopayers = scope.wallet.requiredCopayers = 1;
|
||||||
|
sinon.stub(scope.wallet, 'createTx').yields('error');
|
||||||
|
var spySendTx = sinon.spy(scope.wallet, 'sendTx');
|
||||||
|
scope.loadTxs = sinon.spy();
|
||||||
|
|
||||||
|
scope.submitForm(sendForm);
|
||||||
|
sinon.assert.callCount(spySendTx, 0);
|
||||||
|
sinon.assert.callCount(scope.loadTxs, 1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Unit: Version Controller", function() {
|
describe("Unit: Version Controller", function() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue