Merge pull request #1064 from eordano/fix/multisig
Improve test coverage on multisig
This commit is contained in:
commit
b96ee5ccfe
@ -19,6 +19,9 @@ var TransactionSignature = require('../signature');
|
|||||||
function MultiSigScriptHashInput(input, pubkeys, threshold, signatures) {
|
function MultiSigScriptHashInput(input, pubkeys, threshold, signatures) {
|
||||||
Input.apply(this, arguments);
|
Input.apply(this, arguments);
|
||||||
var self = this;
|
var self = this;
|
||||||
|
pubkeys = pubkeys || input.publicKeys;
|
||||||
|
threshold = threshold || input.threshold;
|
||||||
|
signatures = signatures || input.signatures;
|
||||||
this.publicKeys = _.sortBy(pubkeys, function(publicKey) { return publicKey.toString('hex'); });
|
this.publicKeys = _.sortBy(pubkeys, function(publicKey) { return publicKey.toString('hex'); });
|
||||||
this.redeemScript = Script.buildMultisigOut(this.publicKeys, threshold);
|
this.redeemScript = Script.buildMultisigOut(this.publicKeys, threshold);
|
||||||
$.checkState(Script.buildScriptHashOut(this.redeemScript).equals(this.output.script),
|
$.checkState(Script.buildScriptHashOut(this.redeemScript).equals(this.output.script),
|
||||||
@ -46,14 +49,7 @@ MultiSigScriptHashInput.prototype._deserializeSignatures = function(signatures)
|
|||||||
if (!signature) {
|
if (!signature) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return new TransactionSignature({
|
return new TransactionSignature(signature);
|
||||||
publicKey: new PublicKey(signature.publicKey),
|
|
||||||
prevTxId: signature.txId,
|
|
||||||
outputIndex: signature.outputIndex,
|
|
||||||
inputIndex: signature.inputIndex,
|
|
||||||
signature: Signature.fromString(signature.signature),
|
|
||||||
sigtype: signature.sigtype
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -62,14 +58,7 @@ MultiSigScriptHashInput.prototype._serializeSignatures = function() {
|
|||||||
if (!signature) {
|
if (!signature) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return new TransactionSignature({
|
return signature.toObject();
|
||||||
publicKey: signature.publicKey.toString(),
|
|
||||||
prevTxId: signature.txId,
|
|
||||||
outputIndex: signature.outputIndex,
|
|
||||||
inputIndex: signature.inputIndex,
|
|
||||||
signature: signature.signature.toString(),
|
|
||||||
sigtype: signature.sigtype
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,7 @@ var PrivateKey = bitcore.PrivateKey;
|
|||||||
var Address = bitcore.Address;
|
var Address = bitcore.Address;
|
||||||
var Script = bitcore.Script;
|
var Script = bitcore.Script;
|
||||||
var Signature = bitcore.crypto.Signature;
|
var Signature = bitcore.crypto.Signature;
|
||||||
|
var MultiSigScriptHashInput = bitcore.Transaction.Input.MultiSigScriptHash;
|
||||||
|
|
||||||
describe('MultiSigScriptHashInput', function() {
|
describe('MultiSigScriptHashInput', function() {
|
||||||
|
|
||||||
@ -93,4 +94,21 @@ describe('MultiSigScriptHashInput', function() {
|
|||||||
var sigs = input.getSignatures(transaction, privateKey1, 0);
|
var sigs = input.getSignatures(transaction, privateKey1, 0);
|
||||||
sigs[0].sigtype.should.equal(Signature.SIGHASH_ALL);
|
sigs[0].sigtype.should.equal(Signature.SIGHASH_ALL);
|
||||||
});
|
});
|
||||||
|
it('roundtrips to/from object', function() {
|
||||||
|
var transaction = new Transaction()
|
||||||
|
.from(output, [public1, public2, public3], 2)
|
||||||
|
.to(address, 1000000)
|
||||||
|
.sign(privateKey1);
|
||||||
|
var input = transaction.inputs[0];
|
||||||
|
var roundtrip = new MultiSigScriptHashInput(input.toObject());
|
||||||
|
roundtrip.toObject().should.deep.equal(input.toObject());
|
||||||
|
});
|
||||||
|
it('roundtrips to/from object when not signed', function() {
|
||||||
|
var transaction = new Transaction()
|
||||||
|
.from(output, [public1, public2, public3], 2)
|
||||||
|
.to(address, 1000000);
|
||||||
|
var input = transaction.inputs[0];
|
||||||
|
var roundtrip = new MultiSigScriptHashInput(input.toObject());
|
||||||
|
roundtrip.toObject().should.deep.equal(input.toObject());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user