Improved tests

This commit is contained in:
Ivan Socolsky 2014-09-29 17:36:34 -03:00
commit 2c53bc073e
4 changed files with 281 additions and 142 deletions

View file

@ -129,7 +129,7 @@ TxProposal.fromObj = function(o, forceOpts) {
forceOpts = forceOpts || {};
if (forceOpts){
if (forceOpts) {
o.builderObj.opts = o.builderObj.opts || {};
}
@ -232,6 +232,10 @@ TxProposal.prototype.mergeBuilder = function(incoming) {
};
TxProposal.prototype.getSeen = function(copayerId) {
return this.seenBy[copayerId];
};
TxProposal.prototype.setSeen = function(copayerId) {
if (!this.seenBy[copayerId])
this.seenBy[copayerId] = Date.now();

View file

@ -341,7 +341,6 @@ Wallet.prototype._checkSentTx = function(ntxid, cb) {
this.blockchain.getTransaction(txid, function(err, tx) {
if (err) return cb(false);
txp.setSent(tx.txid);
cb(ret);
});
};
@ -370,21 +369,26 @@ Wallet.prototype._onTxProposal = function(senderId, data) {
}
if (m) {
if (m.hasChanged) {
if (!m.txp.getSeen(this.getMyCopayerId())) {
m.txp.setSeen(this.getMyCopayerId());
this.sendSeen(m.ntxid);
var tx = m.txp.builder.build();
if (tx.isComplete()) {
this._checkSentTx(m.ntxid, function(ret) {
if (ret) {
self.emit('txProposalsUpdated');
self.store();
}
});
} else {
}
var tx = m.txp.builder.build();
if (tx.isComplete()) {
this._checkSentTx(m.ntxid, function(ret) {
if (ret) {
m.txp.setSent(m.mtxid);
self.emit('txProposalsUpdated');
self.store();
}
});
} else {
if (m.hasChanged) {
this.sendTxProposal(m.ntxid);
}
}
this.emit('txProposalsUpdated');
this.store();
}
@ -1125,9 +1129,8 @@ Wallet.prototype.getTxProposals = function() {
var txp = this.txProposals.getTxProposal(ntxid, copayers);
txp.signedByUs = txp.signedBy[this.getMyCopayerId()] ? true : false;
txp.rejectedByUs = txp.rejectedBy[this.getMyCopayerId()] ? true : false;
if (this.totalCopayers - txp.rejectCount < this.requiredCopayers) {
txp.finallyRejected = true;
}
txp.finallyRejected = this.totalCopayers - txp.rejectCount < this.requiredCopayers;
txp.isPending = !txp.finallyRejected && !txp.sentTxid;
if (!txp.readonly || txp.finallyRejected || txp.sentTs) {
ret.push(txp);
@ -1423,9 +1426,7 @@ Wallet.prototype.receivePaymentRequest = function(options, pr, cb) {
expires: expires,
memo: memo || 'This server would like some BTC from you.',
payment_url: payment_url,
merchant_data: merchant_data
? merchant_data.toString('hex')
: null
merchant_data: merchant_data ? merchant_data.toString('hex') : null
},
signature: sig.toString('hex'),
ca: trust.caName,
@ -2106,41 +2107,34 @@ Wallet.prototype.removeTxWithSpentInputs = function(cb) {
cb = cb || function() {};
var txps = [];
var maxRejectCount = this.maxRejectCount();
for (var ntxid in this.txProposals.txps) {
var txp = this.txProposals.txps[ntxid];
txp.ntxid = ntxid;
if (txp.isPending(maxRejectCount)) {
txps.push(txp);
}
}
var inputs = [];
txps.forEach(function(txp) {
txp.builder.utxos.forEach(function(utxo) {
inputs.push({
var txps = _.where(this.getTxProposals(), {
isPending: true
});
var inputs = _.flatten(_.map(txps, function(txp) {
return _.map(txp.builder.utxos, function(utxo) {
return {
ntxid: txp.ntxid,
txid: utxo.txid,
vout: utxo.vout
});
vout: utxo.vout,
};
});
});
}));
if (inputs.length === 0)
return;
return cb();
var proposalsChanged = false;
this.blockchain.getUnspent(this.getAddressesStr(), function(err, unspentList) {
if (err) return cb(err);
unspentList.forEach(function(unspent) {
inputs.forEach(function(input) {
_.each(unspentList, function(unspent) {
_.each(inputs, function(input) {
input.unspent = input.unspent || (input.txid === unspent.txid && input.vout === unspent.vout);
});
});
inputs.forEach(function(input) {
_.each(inputs, function(input) {
if (!input.unspent) {
proposalsChanged = true;
self.txProposals.deleteOne(input.ntxid);
@ -2152,7 +2146,7 @@ Wallet.prototype.removeTxWithSpentInputs = function(cb) {
self.store();
}
cb(null);
return cb();
});
};

View file

@ -122,7 +122,7 @@ angular.module('copayApp.services')
notification.info('Transaction Update', $filter('translate')('A transaction was rejected by') + ' ' + user);
break;
case 'corrupt':
notification.error('Transaction Error', $filter('translate')('Received corrupt transaction from') + ' ' + user);
notification.error('Transaction Error', $filter('translate')('Received corrupt transaction from') + ' ' + user);
break;
}
});
@ -177,8 +177,6 @@ angular.module('copayApp.services')
if (!w) return root.onErrorDigest();
if (!w.isReady()) return;
w.removeTxWithSpentInputs();
$rootScope.balanceByAddr = {};
$rootScope.updatingBalance = true;
@ -232,12 +230,9 @@ angular.module('copayApp.services')
return txs.push(null);
}
if (myCopayerId != i.creator && !i.finallyRejected && !i.sentTs && !i.rejectedByUs && !i.signedByUs) {
if (i.isPending && myCopayerId != i.creator && !i.rejectedByUs && !i.signedByUs) {
pendingForUs++;
}
if (!i.finallyRejected && !i.sentTs) {
i.isPending = 1;
}
if (!!opts.pending == !!i.isPending) {
var tx = i.builder.build();
@ -262,6 +257,8 @@ angular.module('copayApp.services')
}
});
w.removeTxWithSpentInputs();
$rootScope.txs = txs;
$rootScope.txsOpts = opts;
if ($rootScope.pendingTxCount < pendingForUs) {