Browse Source

test legacy/new clients interacting

activeAddress
Ivan Socolsky 9 years ago
parent
commit
a77c81ee7a
  1. 8
      lib/server.js
  2. 103
      test/integration/server.js

8
lib/server.js

@ -203,7 +203,7 @@ WalletService.prototype._runLocked = function(cb, task) {
* @param {number} opts.n - Total copayers. * @param {number} opts.n - Total copayers.
* @param {string} opts.pubKey - Public key to verify copayers joining have access to the wallet secret. * @param {string} opts.pubKey - Public key to verify copayers joining have access to the wallet secret.
* @param {string} [opts.network = 'livenet'] - The Bitcoin network for this wallet. * @param {string} [opts.network = 'livenet'] - The Bitcoin network for this wallet.
* @param {string} [opts.supportBIP44AndP2PKH = false] - Client supports BIP44 & P2PKH for new wallets. * @param {string} [opts.supportBIP44AndP2PKH = true] - Client supports BIP44 & P2PKH for new wallets.
*/ */
WalletService.prototype.createWallet = function(opts, cb) { WalletService.prototype.createWallet = function(opts, cb) {
var self = this, var self = this,
@ -220,6 +220,8 @@ WalletService.prototype.createWallet = function(opts, cb) {
if (!_.contains(['livenet', 'testnet'], opts.network)) if (!_.contains(['livenet', 'testnet'], opts.network))
return cb(new ClientError('Invalid network')); return cb(new ClientError('Invalid network'));
opts.supportBIP44AndP2PKH = _.isBoolean(opts.supportBIP44AndP2PKH) ? opts.supportBIP44AndP2PKH : true;
var derivationStrategy = opts.supportBIP44AndP2PKH ? WalletUtils.DERIVATION_STRATEGIES.BIP44 : WalletUtils.DERIVATION_STRATEGIES.BIP45; var derivationStrategy = opts.supportBIP44AndP2PKH ? WalletUtils.DERIVATION_STRATEGIES.BIP44 : WalletUtils.DERIVATION_STRATEGIES.BIP45;
var addressType = (opts.n == 1 && opts.supportBIP44AndP2PKH) ? WalletUtils.SCRIPT_TYPES.P2PKH : WalletUtils.SCRIPT_TYPES.P2SH; var addressType = (opts.n == 1 && opts.supportBIP44AndP2PKH) ? WalletUtils.SCRIPT_TYPES.P2PKH : WalletUtils.SCRIPT_TYPES.P2SH;
@ -553,7 +555,7 @@ WalletService.prototype._clientSupportsTXPv2 = function() {
* @param {string} opts.requestPubKey - Public Key used to check requests from this copayer. * @param {string} opts.requestPubKey - Public Key used to check requests from this copayer.
* @param {string} opts.copayerSignature - S(name|xPubKey|requestPubKey). Used by other copayers to verify that the copayer joining knows the wallet secret. * @param {string} opts.copayerSignature - S(name|xPubKey|requestPubKey). Used by other copayers to verify that the copayer joining knows the wallet secret.
* @param {string} opts.customData - (optional) Custom data for this copayer. * @param {string} opts.customData - (optional) Custom data for this copayer.
* @param {string} [opts.supportBIP44AndP2PKH = false] - Client supports BIP44 & P2PKH for joining wallets. * @param {string} [opts.supportBIP44AndP2PKH = true] - Client supports BIP44 & P2PKH for joining wallets.
*/ */
WalletService.prototype.joinWallet = function(opts, cb) { WalletService.prototype.joinWallet = function(opts, cb) {
var self = this; var self = this;
@ -564,6 +566,8 @@ WalletService.prototype.joinWallet = function(opts, cb) {
if (_.isEmpty(opts.name)) if (_.isEmpty(opts.name))
return cb(new ClientError('Invalid copayer name')); return cb(new ClientError('Invalid copayer name'));
opts.supportBIP44AndP2PKH = _.isBoolean(opts.supportBIP44AndP2PKH) ? opts.supportBIP44AndP2PKH : true;
self.walletId = opts.walletId; self.walletId = opts.walletId;
self._runLocked(cb, function(cb) { self._runLocked(cb, function(cb) {
self.storage.fetchWallet(opts.walletId, function(err, wallet) { self.storage.fetchWallet(opts.walletId, function(err, wallet) {

103
test/integration/server.js

@ -96,14 +96,15 @@ helpers.createAndJoinWallet = function(m, n, opts, cb) {
var copayerIds = []; var copayerIds = [];
var offset = opts.offset || 0; var offset = opts.offset || 0;
var supportBIP44AndP2PKH = _.isBoolean(opts.supportBIP44AndP2PKH) ? opts.supportBIP44AndP2PKH : true;
var walletOpts = { var walletOpts = {
name: 'a wallet', name: 'a wallet',
m: m, m: m,
n: n, n: n,
pubKey: TestData.keyPair.pub, pubKey: TestData.keyPair.pub,
supportBIP44AndP2PKH: supportBIP44AndP2PKH,
}; };
if (_.isBoolean(opts.supportBIP44AndP2PKH))
walletOpts.supportBIP44AndP2PKH = opts.supportBIP44AndP2PKH;
server.createWallet(walletOpts, function(err, walletId) { server.createWallet(walletOpts, function(err, walletId) {
if (err) return cb(err); if (err) return cb(err);
@ -112,11 +113,12 @@ helpers.createAndJoinWallet = function(m, n, opts, cb) {
var copayerOpts = helpers.getSignedCopayerOpts({ var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId, walletId: walletId,
name: 'copayer ' + (i + 1), name: 'copayer ' + (i + 1),
xPubKey: supportBIP44AndP2PKH ? copayerData.xPubKey_44H_0H_0H : copayerData.xPubKey_45H, xPubKey: (_.isBoolean(opts.supportBIP44AndP2PKH) && !opts.supportBIP44AndP2PKH) ? copayerData.xPubKey_45H : copayerData.xPubKey_44H_0H_0H,
requestPubKey: copayerData.pubKey_1H_0, requestPubKey: copayerData.pubKey_1H_0,
customData: 'custom data ' + (i + 1), customData: 'custom data ' + (i + 1),
supportBIP44AndP2PKH: supportBIP44AndP2PKH,
}); });
if (_.isBoolean(opts.supportBIP44AndP2PKH))
copayerOpts.supportBIP44AndP2PKH = opts.supportBIP44AndP2PKH;
server.joinWallet(copayerOpts, function(err, result) { server.joinWallet(copayerOpts, function(err, result) {
should.not.exist(err); should.not.exist(err);
@ -946,23 +948,8 @@ describe('Wallet service', function() {
}; };
server.createWallet(walletOpts, function(err, wId) { server.createWallet(walletOpts, function(err, wId) {
should.not.exist(err); should.not.exist(err);
should.exist.walletId;
walletId = wId; walletId = wId;
done(); should.exist(walletId);
});
});
it('should fail to join with mismatching address derivation strategy', function(done) {
var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId,
name: 'me',
xPubKey: TestData.copayers[0].xPubKey_45H,
requestPubKey: TestData.copayers[0].pubKey_1H_0,
supportBIP44AndP2PKH: true,
});
server.joinWallet(copayerOpts, function(err, result) {
should.exist(err);
err.message.should.contain('The wallet you are trying to join was created with an older version of the client app');
done(); done();
}); });
}); });
@ -971,7 +958,7 @@ describe('Wallet service', function() {
var copayerOpts = helpers.getSignedCopayerOpts({ var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId, walletId: walletId,
name: 'me', name: 'me',
xPubKey: TestData.copayers[0].xPubKey_45H, xPubKey: TestData.copayers[0].xPubKey_44H_0H_0H,
requestPubKey: TestData.copayers[0].pubKey_1H_0, requestPubKey: TestData.copayers[0].pubKey_1H_0,
customData: 'dummy custom data', customData: 'dummy custom data',
}); });
@ -1011,7 +998,7 @@ describe('Wallet service', function() {
var copayerOpts = helpers.getSignedCopayerOpts({ var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId, walletId: walletId,
name: '', name: '',
xPubKey: TestData.copayers[0].xPubKey_45H, xPubKey: TestData.copayers[0].xPubKey_44H_0H_0H,
requestPubKey: TestData.copayers[0].pubKey_1H_0, requestPubKey: TestData.copayers[0].pubKey_1H_0,
}); });
server.joinWallet(copayerOpts, function(err, result) { server.joinWallet(copayerOpts, function(err, result) {
@ -1043,7 +1030,6 @@ describe('Wallet service', function() {
name: 'me', name: 'me',
xPubKey: TestData.copayers[1].xPubKey_44H_0H_0H, xPubKey: TestData.copayers[1].xPubKey_44H_0H_0H,
requestPubKey: TestData.copayers[1].pubKey_1H_0, requestPubKey: TestData.copayers[1].pubKey_1H_0,
supportBIP44AndP2PKH: true,
}); });
server.joinWallet(copayerOpts, function(err) { server.joinWallet(copayerOpts, function(err) {
should.exist(err); should.exist(err);
@ -1061,7 +1047,6 @@ describe('Wallet service', function() {
name: 'me', name: 'me',
xPubKey: TestData.copayers[0].xPubKey_44H_0H_0H, xPubKey: TestData.copayers[0].xPubKey_44H_0H_0H,
requestPubKey: TestData.copayers[0].pubKey_1H_0, requestPubKey: TestData.copayers[0].pubKey_1H_0,
supportBIP44AndP2PKH: true,
}); });
server.joinWallet(copayerOpts, function(err) { server.joinWallet(copayerOpts, function(err) {
should.exist(err); should.exist(err);
@ -1075,7 +1060,7 @@ describe('Wallet service', function() {
var copayerOpts = helpers.getSignedCopayerOpts({ var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId, walletId: walletId,
name: 'me', name: 'me',
xPubKey: TestData.copayers[0].xPubKey_45H, xPubKey: TestData.copayers[0].xPubKey_44H_0H_0H,
requestPubKey: TestData.copayers[0].pubKey_1H_0, requestPubKey: TestData.copayers[0].pubKey_1H_0,
}); });
server.joinWallet(copayerOpts, function(err) { server.joinWallet(copayerOpts, function(err) {
@ -1093,7 +1078,7 @@ describe('Wallet service', function() {
var copayerOpts = helpers.getSignedCopayerOpts({ var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId, walletId: walletId,
name: 'me', name: 'me',
xPubKey: TestData.copayers[0].xPubKey_45H, xPubKey: TestData.copayers[0].xPubKey_44H_0H_0H,
requestPubKey: TestData.copayers[0].pubKey_1H_0, requestPubKey: TestData.copayers[0].pubKey_1H_0,
}); });
server.joinWallet(copayerOpts, function(err) { server.joinWallet(copayerOpts, function(err) {
@ -1110,7 +1095,7 @@ describe('Wallet service', function() {
copayerOpts = helpers.getSignedCopayerOpts({ copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId, walletId: walletId,
name: 'me', name: 'me',
xPubKey: TestData.copayers[0].xPubKey_45H, xPubKey: TestData.copayers[0].xPubKey_44H_0H_0H,
requestPubKey: TestData.copayers[0].pubKey_1H_0, requestPubKey: TestData.copayers[0].pubKey_1H_0,
}); });
server.joinWallet(copayerOpts, function(err) { server.joinWallet(copayerOpts, function(err) {
@ -1127,7 +1112,7 @@ describe('Wallet service', function() {
var copayerOpts = { var copayerOpts = {
walletId: walletId, walletId: walletId,
name: 'me', name: 'me',
xPubKey: TestData.copayers[0].xPubKey_45H, xPubKey: TestData.copayers[0].xPubKey_44H_0H_0H,
requestPubKey: TestData.copayers[0].pubKey_1H_0, requestPubKey: TestData.copayers[0].pubKey_1H_0,
copayerSignature: 'bad sign', copayerSignature: 'bad sign',
}; };
@ -1141,7 +1126,7 @@ describe('Wallet service', function() {
var copayerOpts = { var copayerOpts = {
walletId: walletId, walletId: walletId,
name: 'me', name: 'me',
xPubKey: TestData.copayers[0].xPubKey_45H, xPubKey: TestData.copayers[0].xPubKey_44H_0H_0H,
requestPubKey: TestData.copayers[0].pubKey_1H_0, requestPubKey: TestData.copayers[0].pubKey_1H_0,
}; };
server.joinWallet(copayerOpts, function(err) { server.joinWallet(copayerOpts, function(err) {
@ -1155,7 +1140,7 @@ describe('Wallet service', function() {
var copayerOpts = helpers.getSignedCopayerOpts({ var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId, walletId: walletId,
name: 'me', name: 'me',
xPubKey: TestData.copayers[0].xPubKey_45H, xPubKey: TestData.copayers[0].xPubKey_44H_0H_0H,
requestPubKey: TestData.copayers[0].pubKey_1H_0, requestPubKey: TestData.copayers[0].pubKey_1H_0,
}); });
copayerOpts.name = 'me2'; copayerOpts.name = 'me2';
@ -1198,6 +1183,62 @@ describe('Wallet service', function() {
}); });
}); });
describe('#joinWallet new/legacy clients', function() {
var server;
beforeEach(function() {
server = new WalletService();
});
it('should fail to join legacy wallet from new client', function(done) {
var walletOpts = {
name: 'my wallet',
m: 1,
n: 2,
pubKey: TestData.keyPair.pub,
supportBIP44AndP2PKH: false,
};
server.createWallet(walletOpts, function(err, walletId) {
should.not.exist(err);
should.exist(walletId);
var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId,
name: 'me',
xPubKey: TestData.copayers[0].xPubKey_44H_0H_0H,
requestPubKey: TestData.copayers[0].pubKey_1H_0,
});
server.joinWallet(copayerOpts, function(err, result) {
should.exist(err);
err.message.should.contain('The wallet you are trying to join was created with an older version of the client app');
done();
});
});
});
it('should fail to join new wallet from legacy client', function(done) {
var walletOpts = {
name: 'my wallet',
m: 1,
n: 2,
pubKey: TestData.keyPair.pub,
};
server.createWallet(walletOpts, function(err, walletId) {
should.not.exist(err);
should.exist(walletId);
var copayerOpts = helpers.getSignedCopayerOpts({
walletId: walletId,
name: 'me',
xPubKey: TestData.copayers[0].xPubKey_45H,
requestPubKey: TestData.copayers[0].pubKey_1H_0,
supportBIP44AndP2PKH: false,
});
server.joinWallet(copayerOpts, function(err, result) {
should.exist(err);
err.code.should.equal('UPGRADE_NEEDED');
done();
});
});
});
});
describe('Address derivation strategy', function() { describe('Address derivation strategy', function() {
var server; var server;
beforeEach(function() { beforeEach(function() {
@ -1209,7 +1250,6 @@ describe('Wallet service', function() {
m: 1, m: 1,
n: 1, n: 1,
pubKey: TestData.keyPair.pub, pubKey: TestData.keyPair.pub,
supportBIP44AndP2PKH: true,
}; };
server.createWallet(walletOpts, function(err, wid) { server.createWallet(walletOpts, function(err, wid) {
should.not.exist(err); should.not.exist(err);
@ -1245,7 +1285,6 @@ describe('Wallet service', function() {
m: 2, m: 2,
n: 3, n: 3,
pubKey: TestData.keyPair.pub, pubKey: TestData.keyPair.pub,
supportBIP44AndP2PKH: true,
}; };
server.createWallet(walletOpts, function(err, wid) { server.createWallet(walletOpts, function(err, wid) {
should.not.exist(err); should.not.exist(err);

Loading…
Cancel
Save