refactor join wallet tests
This commit is contained in:
parent
c1a0ec6f5d
commit
e665db210b
|
@ -157,6 +157,8 @@ CopayServer.prototype.joinWallet = function(opts, cb) {
|
||||||
|
|
||||||
Utils.checkRequired(opts, ['walletId', 'name', 'xPubKey', 'xPubKeySignature']);
|
Utils.checkRequired(opts, ['walletId', 'name', 'xPubKey', 'xPubKeySignature']);
|
||||||
|
|
||||||
|
if (_.isEmpty(opts.name)) return cb(new ClientError('Invalid copayer name'));
|
||||||
|
|
||||||
Utils.runLocked(opts.walletId, cb, function(cb) {
|
Utils.runLocked(opts.walletId, cb, function(cb) {
|
||||||
self.storage.fetchWallet(opts.walletId, function(err, wallet) {
|
self.storage.fetchWallet(opts.walletId, function(err, wallet) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
|
@ -308,21 +308,24 @@ describe('Copay server', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#joinWallet', function() {
|
describe('#joinWallet', function() {
|
||||||
var server;
|
var server, walletId;
|
||||||
beforeEach(function() {
|
beforeEach(function(done) {
|
||||||
server = new CopayServer();
|
server = new CopayServer();
|
||||||
});
|
|
||||||
|
|
||||||
it('should join existing wallet', function(done) {
|
|
||||||
var walletOpts = {
|
var walletOpts = {
|
||||||
name: 'my wallet',
|
name: 'my wallet',
|
||||||
m: 2,
|
m: 2,
|
||||||
n: 3,
|
n: 3,
|
||||||
pubKey: keyPair.pub,
|
pubKey: keyPair.pub,
|
||||||
};
|
};
|
||||||
|
server.createWallet(walletOpts, function(err, wId) {
|
||||||
server.createWallet(walletOpts, function(err, walletId) {
|
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
|
should.exist.walletId;
|
||||||
|
walletId = wId;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should join existing wallet', function(done) {
|
||||||
var copayerOpts = {
|
var copayerOpts = {
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
name: 'me',
|
name: 'me',
|
||||||
|
@ -343,11 +346,25 @@ describe('Copay server', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should fail to join with no name', function(done) {
|
||||||
|
var copayerOpts = {
|
||||||
|
walletId: walletId,
|
||||||
|
name: '',
|
||||||
|
xPubKey: someXPubKeys[0],
|
||||||
|
xPubKeySignature: someXPubKeysSignatures[0],
|
||||||
|
};
|
||||||
|
server.joinWallet(copayerOpts, function(err, copayerId) {
|
||||||
|
should.not.exist(copayerId);
|
||||||
|
err.should.exist;
|
||||||
|
err.message.should.contain('name');
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to join non-existent wallet', function(done) {
|
it('should fail to join non-existent wallet', function(done) {
|
||||||
var copayerOpts = {
|
var copayerOpts = {
|
||||||
walletId: '234',
|
walletId: '123',
|
||||||
name: 'me',
|
name: 'me',
|
||||||
xPubKey: 'dummy',
|
xPubKey: 'dummy',
|
||||||
xPubKeySignature: 'dummy',
|
xPubKeySignature: 'dummy',
|
||||||
|
@ -359,34 +376,14 @@ describe('Copay server', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to join full wallet', function(done) {
|
it('should fail to join full wallet', function(done) {
|
||||||
var walletOpts = {
|
helpers.createAndJoinWallet(1, 1, function(s, wallet) {
|
||||||
name: 'my wallet',
|
var copayerOpts = {
|
||||||
m: 1,
|
walletId: wallet.id,
|
||||||
n: 1,
|
|
||||||
pubKey: keyPair.pub,
|
|
||||||
};
|
|
||||||
server.createWallet(walletOpts, function(err, walletId) {
|
|
||||||
should.not.exist(err);
|
|
||||||
var copayer1Opts = {
|
|
||||||
walletId: walletId,
|
|
||||||
id: '111',
|
|
||||||
name: 'me',
|
name: 'me',
|
||||||
xPubKey: someXPubKeys[0],
|
|
||||||
xPubKeySignature: someXPubKeysSignatures[0],
|
|
||||||
};
|
|
||||||
var copayer2Opts = {
|
|
||||||
walletId: walletId,
|
|
||||||
id: '222',
|
|
||||||
name: 'me 2',
|
|
||||||
xPubKey: someXPubKeys[1],
|
xPubKey: someXPubKeys[1],
|
||||||
xPubKeySignature: someXPubKeysSignatures[1],
|
xPubKeySignature: someXPubKeysSignatures[1],
|
||||||
};
|
};
|
||||||
server.joinWallet(copayer1Opts, function(err, copayer1Id) {
|
server.joinWallet(copayerOpts, function(err) {
|
||||||
should.not.exist(err);
|
|
||||||
helpers.getAuthServer(copayer1Id, function(server) {
|
|
||||||
server.getWallet({}, function(err, wallet) {
|
|
||||||
wallet.status.should.equal('complete');
|
|
||||||
server.joinWallet(copayer2Opts, function(err, copayer2Id) {
|
|
||||||
should.exist(err);
|
should.exist(err);
|
||||||
err.code.should.equal('WFULL');
|
err.code.should.equal('WFULL');
|
||||||
err.message.should.equal('Wallet full');
|
err.message.should.equal('Wallet full');
|
||||||
|
@ -394,22 +391,10 @@ describe('Copay server', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fail to re-join wallet', function(done) {
|
it('should fail to re-join wallet', function(done) {
|
||||||
var walletOpts = {
|
|
||||||
name: 'my wallet',
|
|
||||||
m: 1,
|
|
||||||
n: 1,
|
|
||||||
pubKey: keyPair.pub,
|
|
||||||
};
|
|
||||||
server.createWallet(walletOpts, function(err, walletId) {
|
|
||||||
should.not.exist(err);
|
|
||||||
var copayerOpts = {
|
var copayerOpts = {
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
id: '111',
|
|
||||||
name: 'me',
|
name: 'me',
|
||||||
xPubKey: someXPubKeys[0],
|
xPubKey: someXPubKeys[0],
|
||||||
xPubKeySignature: someXPubKeysSignatures[0],
|
xPubKeySignature: someXPubKeysSignatures[0],
|
||||||
|
@ -424,19 +409,8 @@ describe('Copay server', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
it('should fail to join with bad formated signature', function(done) {
|
it('should fail to join with bad formated signature', function(done) {
|
||||||
var walletOpts = {
|
|
||||||
id: '123',
|
|
||||||
name: 'my wallet',
|
|
||||||
m: 1,
|
|
||||||
n: 1,
|
|
||||||
pubKey: aPubKey,
|
|
||||||
};
|
|
||||||
server.createWallet(walletOpts, function(err, walletId) {
|
|
||||||
should.not.exist(err);
|
|
||||||
var copayerOpts = {
|
var copayerOpts = {
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
name: 'me',
|
name: 'me',
|
||||||
|
@ -448,22 +422,10 @@ describe('Copay server', function() {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
it('should fail to join with null signature', function(done) {
|
it('should fail to join with null signature', function(done) {
|
||||||
var walletOpts = {
|
|
||||||
id: '123',
|
|
||||||
name: 'my wallet',
|
|
||||||
m: 1,
|
|
||||||
n: 1,
|
|
||||||
pubKey: aPubKey,
|
|
||||||
};
|
|
||||||
server.createWallet(walletOpts, function(err) {
|
|
||||||
should.not.exist(err);
|
|
||||||
var copayerOpts = {
|
var copayerOpts = {
|
||||||
walletId: '123',
|
walletId: walletId,
|
||||||
id: '111',
|
|
||||||
name: 'me',
|
name: 'me',
|
||||||
xPubKey: someXPubKeys[0],
|
xPubKey: someXPubKeys[0],
|
||||||
};
|
};
|
||||||
|
@ -474,30 +436,19 @@ describe('Copay server', function() {
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('should fail to join with wrong signature', function(done) {
|
it('should fail to join with wrong signature', function(done) {
|
||||||
var walletOpts = {
|
|
||||||
id: '123',
|
|
||||||
name: 'my wallet',
|
|
||||||
m: 1,
|
|
||||||
n: 1,
|
|
||||||
pubKey: aPubKey,
|
|
||||||
};
|
|
||||||
server.createWallet(walletOpts, function(err, walletId) {
|
|
||||||
should.not.exist(err);
|
|
||||||
var copayerOpts = {
|
var copayerOpts = {
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
name: 'me',
|
name: 'me',
|
||||||
xPubKey: someXPubKeys[0],
|
xPubKey: someXPubKeys[0],
|
||||||
xPubKeySignature: someXPubKeysSignatures[0],
|
xPubKeySignature: someXPubKeysSignatures[1],
|
||||||
};
|
};
|
||||||
server.joinWallet(copayerOpts, function(err) {
|
server.joinWallet(copayerOpts, function(err) {
|
||||||
err.message.should.equal('Bad request');
|
err.message.should.equal('Bad request');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('should set pkr and status = complete on last copayer joining (2-3)', function(done) {
|
it('should set pkr and status = complete on last copayer joining (2-3)', function(done) {
|
||||||
helpers.createAndJoinWallet(2, 3, function(server) {
|
helpers.createAndJoinWallet(2, 3, function(server) {
|
||||||
|
|
Loading…
Reference in New Issue