allow 1 <= n <= 15 && 1 <= m <= n
This commit is contained in:
parent
1ce36b6742
commit
700c898508
|
@ -18,8 +18,8 @@ Wallet.create = function(opts) {
|
||||||
|
|
||||||
var x = new Wallet();
|
var x = new Wallet();
|
||||||
|
|
||||||
$.checkArgument(_.isNumber(opts.m), '"m" is expected to be a number');
|
$.shouldBeNumber(opts.m);
|
||||||
$.checkArgument(_.isNumber(opts.n), '"n" is expected to be a number');
|
$.shouldBeNumber(opts.n);
|
||||||
|
|
||||||
x.version = '1.0.0';
|
x.version = '1.0.0';
|
||||||
x.createdOn = Math.floor(Date.now() / 1000);
|
x.createdOn = Math.floor(Date.now() / 1000);
|
||||||
|
@ -47,8 +47,8 @@ Wallet.create = function(opts) {
|
||||||
Wallet.fromObj = function(obj) {
|
Wallet.fromObj = function(obj) {
|
||||||
var x = new Wallet();
|
var x = new Wallet();
|
||||||
|
|
||||||
$.checkArgument(_.isNumber(obj.m), '"m" is expected to be a number');
|
$.shouldBeNumber(obj.m);
|
||||||
$.checkArgument(_.isNumber(obj.n), '"n" is expected to be a number');
|
$.shouldBeNumber(obj.n);
|
||||||
|
|
||||||
x.version = obj.version;
|
x.version = obj.version;
|
||||||
x.createdOn = obj.createdOn;
|
x.createdOn = obj.createdOn;
|
||||||
|
@ -77,22 +77,6 @@ Wallet.prototype.toObject = function() {
|
||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* For compressed keys, m*73 + n*34 <= 496 */
|
|
||||||
Wallet.COPAYER_PAIR_LIMITS = {
|
|
||||||
1: 1,
|
|
||||||
2: 2,
|
|
||||||
3: 3,
|
|
||||||
4: 4,
|
|
||||||
5: 4,
|
|
||||||
6: 4,
|
|
||||||
7: 3,
|
|
||||||
8: 3,
|
|
||||||
9: 2,
|
|
||||||
10: 2,
|
|
||||||
11: 1,
|
|
||||||
12: 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the maximum allowed number of required copayers.
|
* Get the maximum allowed number of required copayers.
|
||||||
* This is a limit imposed by the maximum allowed size of the scriptSig.
|
* This is a limit imposed by the maximum allowed size of the scriptSig.
|
||||||
|
@ -104,7 +88,7 @@ Wallet.getMaxRequiredCopayers = function(totalCopayers) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.verifyCopayerLimits = function(m, n) {
|
Wallet.verifyCopayerLimits = function(m, n) {
|
||||||
return (n >= 1 && n <= 12) && (m >= 1 && m <= Wallet.COPAYER_PAIR_LIMITS[n]);
|
return (n >= 1 && n <= 15) && (m >= 1 && m <= n);
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.isShared = function() {
|
Wallet.prototype.isShared = function() {
|
||||||
|
|
|
@ -168,7 +168,6 @@ describe('Wallet service', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should fail to create wallet with no name', function(done) {
|
it('should fail to create wallet with no name', function(done) {
|
||||||
var opts = {
|
var opts = {
|
||||||
name: '',
|
name: '',
|
||||||
|
@ -184,37 +183,71 @@ describe('Wallet service', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to create wallet with invalid copayer pairs', function(done) {
|
it('should check m-n combination', function(done) {
|
||||||
var invalidPairs = [{
|
var pairs = [{
|
||||||
m: 0,
|
m: 0,
|
||||||
n: 0
|
n: 0,
|
||||||
}, {
|
valid: false,
|
||||||
m: 0,
|
|
||||||
n: 2
|
|
||||||
}, {
|
|
||||||
m: 2,
|
|
||||||
n: 1
|
|
||||||
}, {
|
|
||||||
m: 0,
|
|
||||||
n: 10
|
|
||||||
}, {
|
}, {
|
||||||
m: 1,
|
m: 1,
|
||||||
n: 20
|
n: 1,
|
||||||
|
valid: true,
|
||||||
|
}, {
|
||||||
|
m: 2,
|
||||||
|
n: 3,
|
||||||
|
valid: true,
|
||||||
|
}, {
|
||||||
|
m: 0,
|
||||||
|
n: 2,
|
||||||
|
valid: false,
|
||||||
|
}, {
|
||||||
|
m: 2,
|
||||||
|
n: 1,
|
||||||
|
valid: false,
|
||||||
|
}, {
|
||||||
|
m: 0,
|
||||||
|
n: 10,
|
||||||
|
valid: false,
|
||||||
|
}, {
|
||||||
|
m: 1,
|
||||||
|
n: 20,
|
||||||
|
valid: false,
|
||||||
}, {
|
}, {
|
||||||
m: 10,
|
m: 10,
|
||||||
n: 10
|
n: 10,
|
||||||
|
valid: true,
|
||||||
|
}, {
|
||||||
|
m: 15,
|
||||||
|
n: 15,
|
||||||
|
valid: true,
|
||||||
|
}, {
|
||||||
|
m: 16,
|
||||||
|
n: 16,
|
||||||
|
valid: false,
|
||||||
|
}, {
|
||||||
|
m: 1,
|
||||||
|
n: 15,
|
||||||
|
valid: true,
|
||||||
|
}, {
|
||||||
|
m: -2,
|
||||||
|
n: -2,
|
||||||
|
valid: false,
|
||||||
}, ];
|
}, ];
|
||||||
var opts = {
|
var opts = {
|
||||||
id: '123',
|
id: '123',
|
||||||
name: 'my wallet',
|
name: 'my wallet',
|
||||||
pubKey: TestData.keyPair.pub,
|
pubKey: TestData.keyPair.pub,
|
||||||
};
|
};
|
||||||
async.each(invalidPairs, function(pair, cb) {
|
async.each(pairs, function(pair, cb) {
|
||||||
opts.m = pair.m;
|
opts.m = pair.m;
|
||||||
opts.n = pair.n;
|
opts.n = pair.n;
|
||||||
server.createWallet(opts, function(err) {
|
server.createWallet(opts, function(err) {
|
||||||
should.exist(err);
|
if (!pair.valid) {
|
||||||
err.message.should.equal('Invalid combination of required copayers / total copayers');
|
should.exist(err);
|
||||||
|
err.message.should.equal('Invalid combination of required copayers / total copayers');
|
||||||
|
} else {
|
||||||
|
should.not.exist(err);
|
||||||
|
}
|
||||||
return cb();
|
return cb();
|
||||||
});
|
});
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
|
|
|
@ -12,22 +12,34 @@ describe('Wallet', function() {
|
||||||
describe('#create', function() {
|
describe('#create', function() {
|
||||||
it('will throw with an invalid string argument for "m" or "n"', function() {
|
it('will throw with an invalid string argument for "m" or "n"', function() {
|
||||||
(function() {
|
(function() {
|
||||||
Wallet.create({m: '2', n: 2});
|
Wallet.create({
|
||||||
}).should.throw('"m" is expected to be a number');
|
m: '2',
|
||||||
|
n: 2
|
||||||
|
});
|
||||||
|
}).should.throw('Variable should be a Number.');
|
||||||
(function() {
|
(function() {
|
||||||
Wallet.create({m: 2, n: '2'});
|
Wallet.create({
|
||||||
}).should.throw('"n" is expected to be a number');
|
m: 2,
|
||||||
|
n: '2'
|
||||||
|
});
|
||||||
|
}).should.throw('Variable should be a Number.');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#fromObj', function() {
|
describe('#fromObj', function() {
|
||||||
it('will throw with an invalid string argument for "m" or "n"', function() {
|
it('will throw with an invalid string argument for "m" or "n"', function() {
|
||||||
(function() {
|
(function() {
|
||||||
Wallet.fromObj({m: '2', n: 2});
|
Wallet.fromObj({
|
||||||
}).should.throw('"m" is expected to be a number');
|
m: '2',
|
||||||
|
n: 2
|
||||||
|
});
|
||||||
|
}).should.throw('Variable should be a Number.');
|
||||||
(function() {
|
(function() {
|
||||||
Wallet.fromObj({m: 2, n: '2'});
|
Wallet.fromObj({
|
||||||
}).should.throw('"n" is expected to be a number');
|
m: 2,
|
||||||
|
n: '2'
|
||||||
|
});
|
||||||
|
}).should.throw('Variable should be a Number.');
|
||||||
});
|
});
|
||||||
it('read a wallet', function() {
|
it('read a wallet', function() {
|
||||||
var w = Wallet.fromObj(testWallet);
|
var w = Wallet.fromObj(testWallet);
|
||||||
|
|
Loading…
Reference in New Issue