added redeem script test

refactored the previous multi-sig address test a bit and added a test
to validate the # of signatures required and possible addresses
included in the redeemscript
This commit is contained in:
Julius Taylor 2014-03-27 22:56:10 -04:00
parent 4c82a09aae
commit bad2f769ff

View file

@ -25,30 +25,43 @@ describe('Script', function() {
})
describe('2-of-3 Multi-Signature', function() {
var compressedPubKeys = []
var numSigs
var compressedPubKeys = [];
var numSigs, script, multisig, network
beforeEach(function() {
compressedPubKeys = ['02ea1297665dd733d444f31ec2581020004892cdaaf3dd6c0107c615afb839785f',
'02fab2dea1458990793f56f42e4a47dbf35a12a351f26fa5d7e0cc7447eaafa21f',
'036c6802ce7e8113723dd92cdb852e492ebb157a871ca532c3cb9ed08248ff0e19']
numSigs = 2;
numSigs = 2
})
it('should create valid multi-sig address', function() {
var network = 0x05 //mainnet
var script = Script.createMultiSigOutputScript(numSigs,compressedPubKeys.map(hexToBytes))
var multisig = sha256ripe160(script.buffer)
network = 0x05 //mainnet
script = Script.createMultiSigOutputScript(numSigs,compressedPubKeys.map(hexToBytes))
multisig = sha256ripe160(script.buffer)
var multiSigAddress = Address(multisig,network).toString()
var redeemScript = bytesToHex(script.buffer)
assert.ok(Address.validate(multiSigAddress))
assert.equal(Address.getVersion(multiSigAddress),'0x05')
assert.equal(multiSigAddress,'32vYjxBb7pHJJyXgNk8UoK3BdRDxBzny2v')
assert.equal(Address(sha256ripe160(hexToBytes(redeemScript)),network).toString(),
multiSigAddress)
})
it('should create valid redeemScript', function() {
var redeemScript = script.buffer
var deserialized = new Script(redeemScript)
var numOfSignatures = deserialized.chunks[deserialized.chunks.length-2]-80
var signaturesRequired = deserialized.chunks[0]-80
var sigs = [bytesToHex(deserialized.chunks[1]), bytesToHex(deserialized.chunks[2]),
bytesToHex(deserialized.chunks[3])]
assert.equal(numOfSignatures,3)
assert.equal(signaturesRequired,2)
assert.equal(sigs[0],'02ea1297665dd733d444f31ec2581020004892cdaaf3dd6c0107c615afb839785f')
assert.equal(sigs[1],'02fab2dea1458990793f56f42e4a47dbf35a12a351f26fa5d7e0cc7447eaafa21f')
assert.equal(sigs[2],'036c6802ce7e8113723dd92cdb852e492ebb157a871ca532c3cb9ed08248ff0e19')
assert.equal(Address(sha256ripe160(redeemScript),network).toString(),
'32vYjxBb7pHJJyXgNk8UoK3BdRDxBzny2v')
})
})
})