fix tests

This commit is contained in:
Matias Alejo Garcia 2014-12-10 18:42:32 -03:00
commit 8f8eae0f05
3 changed files with 19 additions and 12 deletions

View file

@ -1498,7 +1498,8 @@ Wallet.prototype.reject = function(ntxid, cb) {
}); });
// TODO this callback should be triggered by sendRejected, which is trully async // TODO this callback should be triggered by sendRejected, which is trully async
return cb(null, Wallet.TX_REJECTED); if (cb)
cb(null, Wallet.TX_REJECTED);
}; };
/** /**
@ -1521,7 +1522,6 @@ Wallet.prototype.sign = function(ntxid) {
var txp = this.txProposals.get(ntxid); var txp = this.txProposals.get(ntxid);
var keys = this.privateKey.getForPaths(txp.inputChainPaths); var keys = this.privateKey.getForPaths(txp.inputChainPaths);
var signaturesAdded = txp.sign(keys, this.getMyCopayerId()); var signaturesAdded = txp.sign(keys, this.getMyCopayerId());
if (!signaturesAdded) if (!signaturesAdded)
return false; return false;

View file

@ -756,17 +756,24 @@ describe('Wallet model', function() {
toAddress: toAddress, toAddress: toAddress,
amountSat: amountSatStr, amountSat: amountSatStr,
}, function(err, ntxid) { }, function(err, ntxid) {
w.on('txProposalsUpdated', function() { var calledType;
w.privateKey = k2;
w.on('txProposalEvent', function(e) {
calledType = e.type;
});
w.signAndSend(ntxid, function(err, tx, status) {
should.not.exist(err);
var txp = w.txProposals.txps[ntxid]; var txp = w.txProposals.txps[ntxid];
var myId = w.getMyCopayerId(); var myId = w.getMyCopayerId();
txp.signedBy[myId].should.be.above(now - 1); txp.signedBy[myId].should.be.above(now - 1);
should.not.exist(txp.rejectedBy[myId]); should.not.exist(txp.rejectedBy[myId]);
status.should.equal(Wallet.TX_SIGNED);
calledType.should.equal(Wallet.TX_SIGNED);
done(); done();
}); });
w.privateKey = k2;
w.sign(ntxid).should.equal.true;
}); });
}); });
it('should fail to reject a signed transaction', function() { it('should fail to reject a signed transaction', function() {
var w = cachedCreateW2(); var w = cachedCreateW2();
var utxo = createUTXO(w); var utxo = createUTXO(w);
@ -1715,7 +1722,7 @@ describe('Wallet model', function() {
it('should accept a new valid TXP', function(done) { it('should accept a new valid TXP', function(done) {
w.txProposals.get = sinon.stub().returns(null); w.txProposals.get = sinon.stub().returns(null);
w.on('txProposalEvent', function(e) { w.on('txProposalEvent', function(e) {
e.type.should.equal('new'); e.type.should.equal(Wallet.TX_NEW);
w._processIncomingNewTxProposal.called.should.equal(true); w._processIncomingNewTxProposal.called.should.equal(true);
w._getPubkeyToCopayerMap.called.should.equal(true); w._getPubkeyToCopayerMap.called.should.equal(true);
done(); done();
@ -1728,7 +1735,7 @@ describe('Wallet model', function() {
w.txProposals.get = sinon.stub().returns(null); w.txProposals.get = sinon.stub().returns(null);
var secondCall = false; var secondCall = false;
w.on('txProposalEvent', function(e) { w.on('txProposalEvent', function(e) {
e.type.should.equal('new'); e.type.should.equal(Wallet.TX_NEW);
w._processIncomingNewTxProposal.calledOnce.should.equal(true); w._processIncomingNewTxProposal.calledOnce.should.equal(true);
w._getPubkeyToCopayerMap.called.should.equal(true); w._getPubkeyToCopayerMap.called.should.equal(true);
w._onTxProposal('senderID', data); w._onTxProposal('senderID', data);
@ -1810,7 +1817,7 @@ describe('Wallet model', function() {
sinon.stub(txp, '_addSignatureAndVerify').returns(); sinon.stub(txp, '_addSignatureAndVerify').returns();
w.on('txProposalEvent', function(e) { w.on('txProposalEvent', function(e) {
e.type.should.equal('signed'); e.type.should.equal(Wallet.TX_SIGNED);
done(); done();
}) })
w._onSignature('senderID', data); w._onSignature('senderID', data);
@ -1865,7 +1872,7 @@ describe('Wallet model', function() {
spy1.calledOnce.should.equal(true); spy1.calledOnce.should.equal(true);
spy2.callCount.should.equal(1); spy2.callCount.should.equal(1);
spy2.firstCall.args.should.deep.equal(['txProposalEvent', { spy2.firstCall.args.should.deep.equal(['txProposalEvent', {
type: 'rejected', type: Wallet.TX_REJECTED,
cId: 'john', cId: 'john',
txId: 'qwerty', txId: 'qwerty',
}]); }]);
@ -1903,7 +1910,7 @@ describe('Wallet model', function() {
w.txProposals.txps['qwerty'].ok.should.equal(1); w.txProposals.txps['qwerty'].ok.should.equal(1);
spy2.callCount.should.equal(1); spy2.callCount.should.equal(1);
spy2.firstCall.args.should.deep.equal(['txProposalEvent', { spy2.firstCall.args.should.deep.equal(['txProposalEvent', {
type: 'seen', type: Wallet.TX_SEEN,
cId: 'john', cId: 'john',
txId: 'qwerty', txId: 'qwerty',
}]); }]);

View file

@ -84,11 +84,11 @@ describe("Unit: Controllers", function() {
w.broadcastTx = sinon.stub().yields(null); w.broadcastTx = sinon.stub().yields(null);
w.requiresMultipleSignatures = sinon.stub().returns(true); w.requiresMultipleSignatures = sinon.stub().returns(true);
w.getTxProposals = sinon.stub().returns([1, 2, 3]); w.getTxProposals = sinon.stub().returns([1, 2, 3]);
w.getPendingTxProposals = sinon.stub().returns({ w.getPendingTxProposals = sinon.stub().returns(
[{ [{
isPending: true isPending: true
}] }]
}); );
w.getId = sinon.stub().returns(1234); w.getId = sinon.stub().returns(1234);
w.on = sinon.stub().yields({ w.on = sinon.stub().yields({
'e': 'errmsg', 'e': 'errmsg',