diff --git a/lib/server.js b/lib/server.js index b434649..bc26d0d 100644 --- a/lib/server.js +++ b/lib/server.js @@ -587,12 +587,12 @@ WalletService.prototype.joinWallet = function(opts, cb) { return cb(new ClientError()); } - if (wallet.copayers.length == wallet.n) return cb(Errors.WALLET_FULL); - if (_.find(wallet.copayers, { xPubKey: opts.xPubKey })) return cb(Errors.COPAYER_IN_WALLET); + if (wallet.copayers.length == wallet.n) return cb(Errors.WALLET_FULL); + self._addCopayerToWallet(wallet, opts, cb); }); }); diff --git a/test/integration/server.js b/test/integration/server.js index a6d2282..c5735c0 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -940,8 +940,8 @@ describe('Wallet service', function() { server = new WalletService(); var walletOpts = { name: 'my wallet', - m: 2, - n: 3, + m: 1, + n: 2, pubKey: TestData.keyPair.pub, }; server.createWallet(walletOpts, function(err, wId) { @@ -1054,6 +1054,23 @@ describe('Wallet service', function() { }); }); + it('should return copayer in wallet error before full wallet', function(done) { + helpers.createAndJoinWallet(1, 1, function(s, wallet) { + var copayerOpts = helpers.getSignedCopayerOpts({ + walletId: wallet.id, + name: 'me', + xPubKey: TestData.copayers[0].xPubKey_44H_0H_0H, + requestPubKey: TestData.copayers[0].pubKey_1H_0, + supportBIP44AndP2PKH: true, + }); + server.joinWallet(copayerOpts, function(err) { + should.exist(err); + err.code.should.equal('COPAYER_IN_WALLET'); + done(); + }); + }); + }); + it('should fail to re-join wallet', function(done) { var copayerOpts = helpers.getSignedCopayerOpts({ walletId: walletId,