test passing
This commit is contained in:
parent
e0b04401c9
commit
2c354525ea
5 changed files with 19 additions and 31 deletions
|
|
@ -16,7 +16,6 @@ angular.module('copayApp.controllers').controller('MoreController',
|
||||||
|
|
||||||
$scope.deleteWallet = function() {
|
$scope.deleteWallet = function() {
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
w.disconnect();
|
|
||||||
walletFactory.delete(w.id, function() {
|
walletFactory.delete(w.id, function() {
|
||||||
controllerUtils.logout();
|
controllerUtils.logout();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ function Wallet(opts) {
|
||||||
this.addressBook = opts.addressBook || {};
|
this.addressBook = opts.addressBook || {};
|
||||||
this.publicKey = this.privateKey.publicHex;
|
this.publicKey = this.privateKey.publicHex;
|
||||||
this.lastTimestamp = opts.lastTimestamp || undefined;
|
this.lastTimestamp = opts.lastTimestamp || undefined;
|
||||||
|
this.lastMessageFrom = {};
|
||||||
|
|
||||||
this.paymentRequests = opts.paymentRequests || {};
|
this.paymentRequests = opts.paymentRequests || {};
|
||||||
|
|
||||||
|
|
@ -313,7 +314,7 @@ Wallet.prototype.updateTimestamp = function(ts) {
|
||||||
|
|
||||||
Wallet.prototype._onNoMessages = function() {
|
Wallet.prototype._onNoMessages = function() {
|
||||||
console.log('No messages at the server. Requesting sync'); //TODO
|
console.log('No messages at the server. Requesting sync'); //TODO
|
||||||
this.sendWalletReady(senderId);
|
this.sendWalletReady();
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype._onData = function(senderId, data, ts) {
|
Wallet.prototype._onData = function(senderId, data, ts) {
|
||||||
|
|
@ -323,7 +324,7 @@ Wallet.prototype._onData = function(senderId, data, ts) {
|
||||||
preconditions.checkArgument(ts);
|
preconditions.checkArgument(ts);
|
||||||
preconditions.checkArgument(typeof ts === 'number');
|
preconditions.checkArgument(typeof ts === 'number');
|
||||||
|
|
||||||
//console.log('RECV', senderId, data);
|
console.log('RECV', senderId, data);
|
||||||
|
|
||||||
if (data.type !== 'walletId' && this.id !== data.walletId) {
|
if (data.type !== 'walletId' && this.id !== data.walletId) {
|
||||||
this.emit('corrupt', senderId);
|
this.emit('corrupt', senderId);
|
||||||
|
|
@ -331,15 +332,18 @@ Wallet.prototype._onData = function(senderId, data, ts) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
// This handler is repeaded on WalletFactory (#join). TODO
|
// This handler is repeaded on WalletFactory (#join). TODO
|
||||||
case 'walletId':
|
case 'walletId':
|
||||||
this.sendWalletReady(senderId);
|
this.sendWalletReady(senderId);
|
||||||
break;
|
break;
|
||||||
case 'walletReady':
|
case 'walletReady':
|
||||||
this.sendPublicKeyRing(senderId);
|
if (this.lastMessageFrom[senderId] !== 'walletReady') {
|
||||||
this.sendAddressBook(senderId);
|
this.sendPublicKeyRing(senderId);
|
||||||
this.sendAllTxProposals(senderId); // send old txps
|
this.sendAddressBook(senderId);
|
||||||
|
this.sendAllTxProposals(senderId); // send old txps
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'publicKeyRing':
|
case 'publicKeyRing':
|
||||||
this._onPublicKeyRing(senderId, data);
|
this._onPublicKeyRing(senderId, data);
|
||||||
|
|
@ -359,13 +363,15 @@ Wallet.prototype._onData = function(senderId, data, ts) {
|
||||||
case 'addressbook':
|
case 'addressbook':
|
||||||
this._onAddressBook(senderId, data);
|
this._onAddressBook(senderId, data);
|
||||||
break;
|
break;
|
||||||
// unused messages
|
// unused messages
|
||||||
case 'disconnect':
|
case 'disconnect':
|
||||||
|
//case 'an other unused message':
|
||||||
break;
|
break;
|
||||||
default:
|
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);
|
this.updateTimestamp(ts);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -290,6 +290,8 @@ Network.prototype.start = function(opts, openCallback) {
|
||||||
this._setupConnectionHandlers(openCallback);
|
this._setupConnectionHandlers(openCallback);
|
||||||
this.socket.emit('subscribe', pubkey);
|
this.socket.emit('subscribe', pubkey);
|
||||||
|
|
||||||
|
|
||||||
|
var fromTs = opts.lastTimestamp + 1;
|
||||||
var self = this,
|
var self = this,
|
||||||
tries = 0;
|
tries = 0;
|
||||||
self.socket.on('insight-error', function(m) {
|
self.socket.on('insight-error', function(m) {
|
||||||
|
|
@ -299,13 +301,13 @@ Network.prototype.start = function(opts, openCallback) {
|
||||||
if (tries++ > 5) {
|
if (tries++ > 5) {
|
||||||
self.emit('serverError');
|
self.emit('serverError');
|
||||||
} else {
|
} else {
|
||||||
self.socket.emit('sync', opts.lastTimestamp + 1);
|
self.socket.emit('sync', fromTs);
|
||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
self.socket.emit('sync', opts.lastTimestamp);
|
self.socket.emit('sync', fromTs);
|
||||||
self.started = true;
|
self.started = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -358,9 +360,7 @@ Network.prototype.send = function(dest, payload, cb) {
|
||||||
var to = dest[ii];
|
var to = dest[ii];
|
||||||
if (to == this.copayerId)
|
if (to == this.copayerId)
|
||||||
continue;
|
continue;
|
||||||
console.log('SEND to: ' + to, this.copayerId, payload);
|
//console.log('SEND to: ' + to, this.copayerId, payload);
|
||||||
|
|
||||||
|
|
||||||
var message = this.encode(to, payload);
|
var message = this.encode(to, payload);
|
||||||
this.socket.emit('message', message);
|
this.socket.emit('message', message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,8 +102,7 @@ FakeWallet.prototype.toEncryptedObj = function() {
|
||||||
return this.enc;
|
return this.enc;
|
||||||
};
|
};
|
||||||
|
|
||||||
FakeWallet.prototype.disconnect = function() {
|
FakeWallet.prototype.close = function() {
|
||||||
this.disconnectCalled = 1;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO a try catch was here
|
// TODO a try catch was here
|
||||||
|
|
|
||||||
|
|
@ -530,15 +530,6 @@ describe('Wallet model', function() {
|
||||||
w._onConnect(newId);
|
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() {
|
it('should register new copayers correctly', function() {
|
||||||
var w = createW();
|
var w = createW();
|
||||||
var r = w.getRegisteredCopayerIds();
|
var r = w.getRegisteredCopayerIds();
|
||||||
|
|
@ -1429,11 +1420,4 @@ describe('Wallet model', function() {
|
||||||
should.exist(n.networkNonce);
|
should.exist(n.networkNonce);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('#disconnect', function() {
|
|
||||||
var w = cachedCreateW();
|
|
||||||
var spy1 = sinon.spy(w, 'send');
|
|
||||||
w.disconnect();
|
|
||||||
spy1.calledOnce.should.be.true;
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue