Check fail when sending incomplete tx

This commit is contained in:
Ivan Socolsky 2014-08-27 09:47:45 -03:00
commit 63fb94c2be
3 changed files with 17 additions and 3 deletions

View file

@ -798,7 +798,6 @@ Wallet.prototype.sendTx = function(ntxid, cb) {
if (txp.merchant) { if (txp.merchant) {
return this.sendPaymentTx(ntxid, cb); return this.sendPaymentTx(ntxid, cb);
} }
var tx = txp.builder.build(); var tx = txp.builder.build();
if (!tx.isComplete()) if (!tx.isComplete())
throw new Error('Tx is not complete. Can not broadcast'); throw new Error('Tx is not complete. Can not broadcast');

View file

@ -8,7 +8,6 @@ function Tx() {
this.ins = [{s: VALID_SCRIPTSIG_BUF }]; this.ins = [{s: VALID_SCRIPTSIG_BUF }];
}; };
Tx.prototype.getHashType = function() { Tx.prototype.getHashType = function() {
return 1; return 1;
}; };
@ -20,7 +19,6 @@ Tx.prototype.hashForSignature = function() {
return new Buffer('31103626e162f1cbfab6b95b08c9f6e78aae128523261cb37f8dfd4783cb09a7', 'hex'); return new Buffer('31103626e162f1cbfab6b95b08c9f6e78aae128523261cb37f8dfd4783cb09a7', 'hex');
}; };
function FakeBuilder() { function FakeBuilder() {
this.test = 1; this.test = 1;
this.tx = new Tx(); this.tx = new Tx();

View file

@ -15,6 +15,7 @@ var PrivateKey = copay.PrivateKey;
var Storage = require('./mocks/FakeStorage'); var Storage = require('./mocks/FakeStorage');
var Network = require('./mocks/FakeNetwork'); var Network = require('./mocks/FakeNetwork');
var Blockchain = require('./mocks/FakeBlockchain'); var Blockchain = require('./mocks/FakeBlockchain');
var Builder = require('./mocks/FakeBuilder');
var bitcore = bitcore || require('bitcore'); var bitcore = bitcore || require('bitcore');
var TransactionBuilder = bitcore.TransactionBuilder; var TransactionBuilder = bitcore.TransactionBuilder;
var Transaction = bitcore.Transaction; var Transaction = bitcore.Transaction;
@ -104,6 +105,7 @@ describe('Wallet model', function() {
c.verbose = config.verbose; c.verbose = config.verbose;
c.version = '0.0.1'; c.version = '0.0.1';
return new Wallet(c); return new Wallet(c);
} }
@ -739,6 +741,21 @@ describe('Wallet model', function() {
}); });
}); });
}); });
it('should fail to send incomplete transaction', function(done) {
var w = createW2(null, 1);
var utxo = createUTXO(w);
w.blockchain.fixUnspent(utxo);
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
var txp = w.txProposals.get(ntxid);
// Assign fake builder
txp.builder = new Builder();
sinon.stub(txp.builder, 'build').returns({ isComplete: function () { return false; }});
(function () {
w.sendTx(ntxid);
}).should.throw('Tx is not complete. Can not broadcast');
done();
});
});
it('should send TxProposal', function(done) { it('should send TxProposal', function(done) {
var w = cachedCreateW2(); var w = cachedCreateW2();
var utxo = createUTXO(w); var utxo = createUTXO(w);