test passing

This commit is contained in:
Matias Alejo Garcia 2014-08-28 19:19:28 -03:00
parent e0b04401c9
commit 2c354525ea
5 changed files with 19 additions and 31 deletions

View File

@ -16,7 +16,6 @@ angular.module('copayApp.controllers').controller('MoreController',
$scope.deleteWallet = function() {
var w = $rootScope.wallet;
w.disconnect();
walletFactory.delete(w.id, function() {
controllerUtils.logout();
});

View File

@ -53,6 +53,7 @@ function Wallet(opts) {
this.addressBook = opts.addressBook || {};
this.publicKey = this.privateKey.publicHex;
this.lastTimestamp = opts.lastTimestamp || undefined;
this.lastMessageFrom = {};
this.paymentRequests = opts.paymentRequests || {};
@ -313,7 +314,7 @@ Wallet.prototype.updateTimestamp = function(ts) {
Wallet.prototype._onNoMessages = function() {
console.log('No messages at the server. Requesting sync'); //TODO
this.sendWalletReady(senderId);
this.sendWalletReady();
};
Wallet.prototype._onData = function(senderId, data, ts) {
@ -323,7 +324,7 @@ Wallet.prototype._onData = function(senderId, data, ts) {
preconditions.checkArgument(ts);
preconditions.checkArgument(typeof ts === 'number');
//console.log('RECV', senderId, data);
console.log('RECV', senderId, data);
if (data.type !== 'walletId' && this.id !== data.walletId) {
this.emit('corrupt', senderId);
@ -331,15 +332,18 @@ Wallet.prototype._onData = function(senderId, data, ts) {
return;
}
switch (data.type) {
// This handler is repeaded on WalletFactory (#join). TODO
case 'walletId':
this.sendWalletReady(senderId);
break;
case 'walletReady':
this.sendPublicKeyRing(senderId);
this.sendAddressBook(senderId);
this.sendAllTxProposals(senderId); // send old txps
if (this.lastMessageFrom[senderId] !== 'walletReady') {
this.sendPublicKeyRing(senderId);
this.sendAddressBook(senderId);
this.sendAllTxProposals(senderId); // send old txps
}
break;
case 'publicKeyRing':
this._onPublicKeyRing(senderId, data);
@ -359,13 +363,15 @@ Wallet.prototype._onData = function(senderId, data, ts) {
case 'addressbook':
this._onAddressBook(senderId, data);
break;
// unused messages
// unused messages
case 'disconnect':
//case 'an other unused message':
break;
default:
throw new Error('unknown message type received: '+ data.type + ' from: ' + senderId)
throw new Error('unknown message type received: ' + data.type + ' from: ' + senderId)
}
this.lastMessageFrom[senderId] = data.type;
this.updateTimestamp(ts);
};

View File

@ -290,6 +290,8 @@ Network.prototype.start = function(opts, openCallback) {
this._setupConnectionHandlers(openCallback);
this.socket.emit('subscribe', pubkey);
var fromTs = opts.lastTimestamp + 1;
var self = this,
tries = 0;
self.socket.on('insight-error', function(m) {
@ -299,13 +301,13 @@ Network.prototype.start = function(opts, openCallback) {
if (tries++ > 5) {
self.emit('serverError');
} else {
self.socket.emit('sync', opts.lastTimestamp + 1);
self.socket.emit('sync', fromTs);
}
}, 500);
});
self.socket.emit('sync', opts.lastTimestamp);
self.socket.emit('sync', fromTs);
self.started = true;
};
@ -358,9 +360,7 @@ Network.prototype.send = function(dest, payload, cb) {
var to = dest[ii];
if (to == this.copayerId)
continue;
console.log('SEND to: ' + to, this.copayerId, payload);
//console.log('SEND to: ' + to, this.copayerId, payload);
var message = this.encode(to, payload);
this.socket.emit('message', message);
}

View File

@ -102,8 +102,7 @@ FakeWallet.prototype.toEncryptedObj = function() {
return this.enc;
};
FakeWallet.prototype.disconnect = function() {
this.disconnectCalled = 1;
FakeWallet.prototype.close = function() {
};
// TODO a try catch was here

View File

@ -530,15 +530,6 @@ describe('Wallet model', function() {
w._onConnect(newId);
});
it('handle disconnections', function(done) {
var w = createW();
w.on('disconnect', function(id) {
id.should.equal(newId);
done();
});
w._onDisconnect(newId);
});
it('should register new copayers correctly', function() {
var w = createW();
var r = w.getRegisteredCopayerIds();
@ -1429,11 +1420,4 @@ describe('Wallet model', function() {
should.exist(n.networkNonce);
});
it('#disconnect', function() {
var w = cachedCreateW();
var spy1 = sinon.spy(w, 'send');
w.disconnect();
spy1.calledOnce.should.be.true;
});
});