mirror of https://github.com/BTCPrivate/copay.git
test passing
This commit is contained in:
parent
e0b04401c9
commit
2c354525ea
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue