Script/Address: Add check for valid number of threshold needed
This commit is contained in:
parent
c19d5c6501
commit
1a5780e35e
@ -543,6 +543,8 @@ Script.prototype.removeCodeseparators = function() {
|
||||
* public keys before creating the script
|
||||
*/
|
||||
Script.buildMultisigOut = function(publicKeys, threshold, opts) {
|
||||
$.checkArgument(threshold <= publicKeys.length,
|
||||
'Number of required signatures must be less than or equal to the number of public keys');
|
||||
opts = opts || {};
|
||||
var script = new Script();
|
||||
script.add(Opcode.smallInt(threshold));
|
||||
|
||||
@ -499,6 +499,12 @@ describe('Address', function() {
|
||||
var address2 = Address.createMultisig(publics, 2);
|
||||
address.toString().should.equal(address2.toString());
|
||||
});
|
||||
|
||||
it('fails if invalid array is provided', function() {
|
||||
expect(function() {
|
||||
return Address.createMultisig([],3,'testnet');
|
||||
}).to.throw('Number of required signatures must be less than or equal to the number of public keys');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@ -430,6 +430,12 @@ describe('Script', function() {
|
||||
s.toString().should.equal('OP_2 33 0x021f2f6e1e50cb6a953935c3601284925decd3fd21bc445712576873fb8c6ebc18 33 0x022df8750480ad5b26950b25c7ba79d3e37d75f640f8e5d9bcd5b150a0f85014da 33 0x03e3818b65bcc73a7d64064106a859cc1a5a728c4345ff0b641209fba0d90de6e9 OP_3 OP_CHECKMULTISIG');
|
||||
s.isMultisigOut().should.equal(true);
|
||||
});
|
||||
it('should fail when number of required signatures is greater than number of pubkeys', function() {
|
||||
expect(sortkeys.length).to.equal(3);
|
||||
expect(function() {
|
||||
return Script.buildMultisigOut(sortkeys, 4);
|
||||
}).to.throw('Number of required signatures must be less than or equal to the number of public keys');
|
||||
});
|
||||
it('should create unsorted script if specified', function() {
|
||||
var s = Script.buildMultisigOut(sortkeys, 2);
|
||||
var u = Script.buildMultisigOut(sortkeys, 2, {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user