all tests passing

This commit is contained in:
Manuel Araoz 2014-06-18 10:21:26 -03:00
parent 889edf4b92
commit b7af51ceee
3 changed files with 20 additions and 6 deletions

View File

@ -181,6 +181,7 @@ TxProposals.prototype.merge = function(inTxp) {
var v1 = inTxp; var v1 = inTxp;
ret = v0.merge(v1); ret = v0.merge(v1);
} else { } else {
this.txps[ntxid] = inTxp;
ret.hasChanged = true; ret.hasChanged = true;
ret.events.push({ ret.events.push({
type: 'new', type: 'new',

View File

@ -366,6 +366,7 @@ Wallet.prototype.sendAllTxProposals = function(recipients) {
Wallet.prototype.sendTxProposal = function(ntxid, recipients) { Wallet.prototype.sendTxProposal = function(ntxid, recipients) {
preconditions.checkArgument(ntxid); preconditions.checkArgument(ntxid);
preconditions.checkState(this.txProposals.txps[ntxid]);
this.log('### SENDING txProposal '+ntxid+' TO:', recipients || 'All', this.txProposals); this.log('### SENDING txProposal '+ntxid+' TO:', recipients || 'All', this.txProposals);
this.network.send(recipients, { this.network.send(recipients, {
type: 'txProposal', type: 'txProposal',
@ -437,8 +438,8 @@ Wallet.prototype.generateAddress = function(isChange, cb) {
Wallet.prototype.getTxProposals = function() { Wallet.prototype.getTxProposals = function() {
var ret = []; var ret = [];
var copayers = this.getRegisteredCopayerIds(); var copayers = this.getRegisteredCopayerIds();
for (var k in this.txProposals.txps) { for (var ntxid in this.txProposals.txps) {
var txp = this.txProposals.getTxProposal(k, copayers); var txp = this.txProposals.getTxProposal(ntxid, copayers);
txp.signedByUs = txp.signedBy[this.getMyCopayerId()] ? true : false; txp.signedByUs = txp.signedBy[this.getMyCopayerId()] ? true : false;
txp.rejectedByUs = txp.rejectedBy[this.getMyCopayerId()] ? true : false; txp.rejectedByUs = txp.rejectedBy[this.getMyCopayerId()] ? true : false;
if (this.totalCopayers - txp.rejectCount < this.requiredCopayers) { if (this.totalCopayers - txp.rejectCount < this.requiredCopayers) {

View File

@ -361,7 +361,7 @@ describe('Wallet model', function() {
it('handle network txProposals correctly', function() { it('handle network txProposals correctly', function() {
var w = createW(); var w = createW();
var txps = { var txp = {
'txProposal': { 'txProposal': {
"seenBy": { "seenBy": {
"undefined": 1402337282806 "undefined": 1402337282806
@ -403,7 +403,7 @@ describe('Wallet model', function() {
} }
} }
}; };
w._handleTxProposal('senderID', txps, true); w._handleTxProposal('senderID', txp, true);
Object.keys(w.txProposals.txps).length.should.equal(1); Object.keys(w.txProposals.txps).length.should.equal(1);
w.getTxProposals().length.should.equal(1); w.getTxProposals().length.should.equal(1);
}); });
@ -592,9 +592,21 @@ describe('Wallet model', function() {
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(ntxid) {
w.sendTxProposal.should.throw('Illegal Argument.'); w.sendTxProposal.bind(w).should.throw('Illegal Argument.');
(function() { (function() {
w.sendTxProposal(ntxid) w.sendTxProposal(ntxid);
}).should.not.throw();
done();
});
});
it('should send all TxProposal', function(done) {
var w = createW2();
var utxo = createUTXO(w);
w.blockchain.fixUnspent(utxo);
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
w.sendAllTxProposals.bind(w).should.not.throw();
(function() {
w.sendAllTxProposals();
}).should.not.throw(); }).should.not.throw();
done(); done();
}); });