Merge pull request #1199 from isocolsky/test/sendTx

Test wallet#sendTx
This commit is contained in:
Manuel Aráoz 2014-08-27 11:03:41 -03:00
commit a37e31ec80
4 changed files with 35 additions and 4 deletions

View file

@ -15,6 +15,7 @@ var PrivateKey = copay.PrivateKey;
var Storage = require('./mocks/FakeStorage');
var Network = require('./mocks/FakeNetwork');
var Blockchain = require('./mocks/FakeBlockchain');
var Builder = require('./mocks/FakeBuilder');
var bitcore = bitcore || require('bitcore');
var TransactionBuilder = bitcore.TransactionBuilder;
var Transaction = bitcore.Transaction;
@ -104,6 +105,7 @@ describe('Wallet model', function() {
c.verbose = walletConfig.verbose;
c.version = '0.0.1';
return new Wallet(c);
}
@ -739,6 +741,33 @@ 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 check if transaction already sent when failing to send', function(done) {
var w = createW2(null, 1);
var utxo = createUTXO(w);
w.blockchain.fixUnspent(utxo);
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
sinon.stub(w.blockchain, 'sendRawTransaction').yields(undefined);
var spyCheckSentTx = sinon.spy(w, '_checkSentTx');
w.sendTx(ntxid, function () {});
chai.expect(spyCheckSentTx.calledOnce).to.be.true;
done();
});
});
it('should send TxProposal', function(done) {
var w = cachedCreateW2();
var utxo = createUTXO(w);