Browse Source

Merge pull request #1064 from eordano/fix/multisig

Improve test coverage on multisig
patch-2
Manuel Aráoz 10 years ago
parent
commit
b96ee5ccfe
  1. 21
      lib/transaction/input/multisigscripthash.js
  2. 18
      test/transaction/input/multisigscripthash.js

21
lib/transaction/input/multisigscripthash.js

@ -19,6 +19,9 @@ var TransactionSignature = require('../signature');
function MultiSigScriptHashInput(input, pubkeys, threshold, signatures) {
Input.apply(this, arguments);
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.redeemScript = Script.buildMultisigOut(this.publicKeys, threshold);
$.checkState(Script.buildScriptHashOut(this.redeemScript).equals(this.output.script),
@ -46,14 +49,7 @@ MultiSigScriptHashInput.prototype._deserializeSignatures = function(signatures)
if (!signature) {
return undefined;
}
return new TransactionSignature({
publicKey: new PublicKey(signature.publicKey),
prevTxId: signature.txId,
outputIndex: signature.outputIndex,
inputIndex: signature.inputIndex,
signature: Signature.fromString(signature.signature),
sigtype: signature.sigtype
});
return new TransactionSignature(signature);
});
};
@ -62,14 +58,7 @@ MultiSigScriptHashInput.prototype._serializeSignatures = function() {
if (!signature) {
return undefined;
}
return new TransactionSignature({
publicKey: signature.publicKey.toString(),
prevTxId: signature.txId,
outputIndex: signature.outputIndex,
inputIndex: signature.inputIndex,
signature: signature.signature.toString(),
sigtype: signature.sigtype
});
return signature.toObject();
});
};

18
test/transaction/input/multisigscripthash.js

@ -11,6 +11,7 @@ var PrivateKey = bitcore.PrivateKey;
var Address = bitcore.Address;
var Script = bitcore.Script;
var Signature = bitcore.crypto.Signature;
var MultiSigScriptHashInput = bitcore.Transaction.Input.MultiSigScriptHash;
describe('MultiSigScriptHashInput', function() {
@ -93,4 +94,21 @@ describe('MultiSigScriptHashInput', function() {
var sigs = input.getSignatures(transaction, privateKey1, 0);
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…
Cancel
Save