Merge pull request #1547 from isocolsky/bug/timestamp

Bug/timestamp
This commit is contained in:
Gustavo Maximiliano Cortez 2014-10-09 13:12:51 -03:00
commit 1519ed73c5
5 changed files with 89 additions and 17 deletions

View file

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

View file

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

View file

@ -100,17 +100,17 @@ angular.module('copayApp.services')
$rootScope.$digest(); $rootScope.$digest();
}); });
w.on('txProposalsUpdated', function(dontDigest) { var updateTxsAndBalance = _.debounce(function() {
root.updateTxs(); root.updateTxs();
// give sometime to the tx to propagate. root.updateBalance(function() {
$timeout(function() { $rootScope.$digest();
root.updateBalance(function() { })
if (!dontDigest) { }, 3000);
$rootScope.$digest();
} w.on('txProposalsUpdated', function(dontDigest) {
}); updateTxsAndBalance();
}, 3000);
}); });
w.on('txProposalEvent', function(e) { w.on('txProposalEvent', function(e) {
var user = w.publicKeyRing.nicknameForCopayer(e.cId); var user = w.publicKeyRing.nicknameForCopayer(e.cId);

View file

@ -112,7 +112,11 @@ describe('TxProposal', function() {
}); });
it('sets force opts', function() { it('sets force opts', function() {
var b = new FakeBuilder(); var b = new FakeBuilder();
b.opts={juan:1, pepe:1, fee:1000}; b.opts = {
juan: 1,
pepe: 1,
fee: 1000
};
var txp; var txp;
var o = { var o = {
creator: 1, creator: 1,
@ -121,9 +125,16 @@ describe('TxProposal', function() {
inputChainPaths: ['m/1'], inputChainPaths: ['m/1'],
}; };
(function() { (function() {
txp = TxProposal.fromObj(o,{pepe:100}); txp = TxProposal.fromObj(o, {
pepe: 100
});
}).should.throw('Invalid tx proposal: no ins'); }).should.throw('Invalid tx proposal: no ins');
o.builderObj.opts.should.deep.equal({juan:1, pepe:100, feeSat:undefined, fee:undefined}); o.builderObj.opts.should.deep.equal({
juan: 1,
pepe: 100,
feeSat: undefined,
fee: undefined
});
}); });
}); });
@ -131,13 +142,36 @@ describe('TxProposal', function() {
describe('#setSent', function() { describe('#setSent', function() {
it('should set txid and timestamp', function() { it('should set txid and timestamp', function() {
var now = Date.now(); var now = Date.now();
var txp = dummyProposal; var txp = new TxProposal({
creator: 1,
createdTs: 1,
builder: new FakeBuilder(),
inputChainPaths: ['m/1'],
});
txp.setSent('3a42'); txp.setSent('3a42');
txp.sentTs.should.gte(now); txp.sentTs.should.gte(now);
txp.sentTxid.should.equal('3a42'); txp.sentTxid.should.equal('3a42');
}); });
}); });
describe('#getSent', function() {
it('should get sent timestamp', function() {
var now = Date.now();
var txp = new TxProposal({
creator: 1,
createdTs: 1,
builder: new FakeBuilder(),
inputChainPaths: ['m/1'],
});
var sentTs = txp.getSent();
should.not.exist(sentTs);
txp.setSent('3a42');
sentTs = txp.getSent();
sentTs.should.gte(now);
});
});
describe('Signature verification', function() { describe('Signature verification', function() {
var validScriptSig = new bitcore.Script(FakeBuilder.VALID_SCRIPTSIG_BUF); var validScriptSig = new bitcore.Script(FakeBuilder.VALID_SCRIPTSIG_BUF);

View file

@ -1564,6 +1564,7 @@ describe('Wallet model', function() {
var txp = { var txp = {
getSeen: sinon.stub().returns(true), getSeen: sinon.stub().returns(true),
setCopayers: sinon.stub().returns(['new copayer']), setCopayers: sinon.stub().returns(['new copayer']),
getSent: sinon.stub().returns(false),
setSent: sinon.spy(), setSent: sinon.spy(),
builder: { builder: {
build: sinon.stub().returns({ build: sinon.stub().returns({
@ -1595,6 +1596,7 @@ describe('Wallet model', function() {
var txp = { var txp = {
getSeen: sinon.stub().returns(true), getSeen: sinon.stub().returns(true),
setCopayers: sinon.stub().returns(['new copayer']), setCopayers: sinon.stub().returns(['new copayer']),
getSent: sinon.stub().returns(false),
setSent: sinon.spy(), setSent: sinon.spy(),
builder: { builder: {
build: sinon.stub().returns({ build: sinon.stub().returns({
@ -1618,6 +1620,38 @@ describe('Wallet model', function() {
done(); 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) { it('should resend when not complete only if changed', function(done) {
var data = { var data = {
txProposal: { txProposal: {