Preserve sent timestamp for incoming proposals

This commit is contained in:
Ivan Socolsky 2014-10-06 18:51:45 -03:00
parent 71e6fce6e6
commit 9d5b26f526
3 changed files with 42 additions and 4 deletions

View File

@ -255,7 +255,9 @@ TxProposal.prototype.setSent = function(sentTxid) {
this.sentTs = Date.now();
};
TxProposal.prototype.getSent = function(sentTxid) {
return !!this.sentTxid;
}
TxProposal.prototype._allSignatures = function() {
var ret = {};

View File

@ -405,9 +405,11 @@ Wallet.prototype._onTxProposal = function(senderId, data) {
if (tx.isComplete()) {
this._checkSentTx(m.ntxid, function(ret) {
if (ret) {
m.txp.setSent(m.ntxid);
self.emit('txProposalsUpdated');
self.store();
if (!m.txp.getSent()) {
m.txp.setSent(m.ntxid);
self.emit('txProposalsUpdated');
self.store();
}
}
});
} else {

View File

@ -1564,6 +1564,7 @@ describe('Wallet model', function() {
var txp = {
getSeen: sinon.stub().returns(true),
setCopayers: sinon.stub().returns(['new copayer']),
getSent: sinon.stub().returns(false),
setSent: sinon.spy(),
builder: {
build: sinon.stub().returns({
@ -1595,6 +1596,7 @@ describe('Wallet model', function() {
var txp = {
getSeen: sinon.stub().returns(true),
setCopayers: sinon.stub().returns(['new copayer']),
getSent: sinon.stub().returns(false),
setSent: sinon.spy(),
builder: {
build: sinon.stub().returns({
@ -1618,6 +1620,38 @@ describe('Wallet model', function() {
done();
});
it('should not overwrite sent info', function(done) {
var data = {
txProposal: {
dummy: 1,
},
};
var txp = {
getSeen: sinon.stub().returns(true),
setCopayers: sinon.stub().returns(['new copayer']),
getSent: sinon.stub().returns(true),
setSent: sinon.spy(),
builder: {
build: sinon.stub().returns({
isComplete: sinon.stub().returns(true),
}),
},
};
w.txProposals.merge = sinon.stub().returns({
ntxid: 1,
txp: txp,
new: false,
hasChanged: false,
});
w._checkSentTx = sinon.stub().yields(true);
w._onTxProposal('senderID', data);
txp.setSent.called.should.be.false;
w.sendTxProposal.called.should.be.false;
done();
});
it('should resend when not complete only if changed', function(done) {
var data = {
txProposal: {