tests: clarify multisig edge case for easier debugging

This commit is contained in:
Daniel Cousens 2016-09-28 00:46:14 +10:00
parent ae63ae1131
commit 418c315c78

View file

@ -62,11 +62,6 @@ describe('TransactionBuilder', function () {
return baddress.toOutputScript(x)
})
var txHash = new Buffer('0e7cea811c0be9f73c0aca591034396e7264473fc25c1ca45195d7417b36cbe2', 'hex')
var txb
beforeEach(function () {
txb = new TransactionBuilder()
})
describe('fromTransaction', function () {
fixtures.valid.build.forEach(function (f) {
@ -119,6 +114,11 @@ describe('TransactionBuilder', function () {
})
describe('addInput', function () {
var txb
beforeEach(function () {
txb = new TransactionBuilder()
})
it('accepts a txHash, index [and sequence number]', function () {
var vin = txb.addInput(txHash, 1, 54)
assert.strictEqual(vin, 0)
@ -172,6 +172,11 @@ describe('TransactionBuilder', function () {
})
describe('addOutput', function () {
var txb
beforeEach(function () {
txb = new TransactionBuilder()
})
it('accepts an address string and value', function () {
var vout = txb.addOutput(keyPair.getAddress(), 1000)
assert.strictEqual(vout, 0)
@ -237,6 +242,7 @@ describe('TransactionBuilder', function () {
describe('setLockTime', function () {
it('throws if if there exist any scriptSigs', function () {
var txb = new TransactionBuilder()
txb.addInput(txHash, 0)
txb.sign(0, keyPair)
@ -249,7 +255,7 @@ describe('TransactionBuilder', function () {
describe('sign', function () {
fixtures.invalid.sign.forEach(function (f) {
it('throws on ' + f.exception + (f.description ? ' (' + f.description + ')' : ''), function () {
txb = construct(f, false)
var txb = construct(f, false)
f.inputs.forEach(function (input, index) {
input.signs.forEach(function (sign) {
@ -277,8 +283,7 @@ describe('TransactionBuilder', function () {
describe('build', function () {
fixtures.valid.build.forEach(function (f) {
it('builds "' + f.description + '"', function () {
txb = construct(f)
var txb = construct(f)
var tx = txb.build()
assert.strictEqual(tx.toHex(), f.txHex)
})
@ -286,6 +291,8 @@ describe('TransactionBuilder', function () {
fixtures.invalid.build.forEach(function (f) {
describe('for ' + (f.description || f.exception), function () {
var txb
beforeEach(function () {
if (f.txHex) {
txb = TransactionBuilder.fromTransaction(Transaction.fromHex(f.txHex))
@ -311,8 +318,7 @@ describe('TransactionBuilder', function () {
describe('multisig', function () {
fixtures.valid.multisig.forEach(function (f) {
it(f.description, function () {
txb = construct(f, false)
var txb = construct(f, false)
var tx
var network = NETWORKS[f.network]
@ -358,19 +364,26 @@ describe('TransactionBuilder', function () {
})
describe('multisig edge case', function () {
var network = NETWORKS.testnet
it('should handle badly pre-filled OP_0s', function () {
var lameTx = Transaction.fromHex('0100000001cff58855426469d0ef16442ee9c644c4fb13832467bcbc3173168a7916f0714900000000fd16010000483045022100daf0f4f3339d9fbab42b098045c1e4958ee3b308f4ae17be80b63808558d0adb02202f07e3d1f79dc8da285ae0d7f68083d769c11f5621ebd9691d6b48c0d4283d7d014cc952410479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b84104c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a4104f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e67253aeffffffff01e8030000000000001976a914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac00000000')
var network = NETWORKS.testnet
txb = TransactionBuilder.fromTransaction(lameTx, network)
// OP_0 is used where a signature is missing
var redeemScripSig = bscript.fromASM('OP_0 OP_0 3045022100daf0f4f3339d9fbab42b098045c1e4958ee3b308f4ae17be80b63808558d0adb02202f07e3d1f79dc8da285ae0d7f68083d769c11f5621ebd9691d6b48c0d4283d7d01 52410479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b84104c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a4104f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e67253ae')
var redeemScript = bscript.fromASM('OP_2 0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 04c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a 04f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672 OP_3 OP_CHECKMULTISIG')
var tx = new Transaction()
tx.addInput(new Buffer('cff58855426469d0ef16442ee9c644c4fb13832467bcbc3173168a7916f07149', 'hex'), 0, undefined, redeemScripSig)
tx.addOutput(new Buffer('76a914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac', 'hex'), 1000)
// now import the Transaction
var txb = TransactionBuilder.fromTransaction(tx, NETWORKS.testnet)
var keyPair = ECPair.fromWIF('91avARGdfge8E4tZfYLoxeJ5sGBdNJQH4kvjJoQFacbgx3cTMqe', network)
txb.sign(0, keyPair, redeemScript)
var tx = txb.build()
assert.equal(tx.toHex(), '0100000001cff58855426469d0ef16442ee9c644c4fb13832467bcbc3173168a7916f0714900000000fd5e0100483045022100daf0f4f3339d9fbab42b098045c1e4958ee3b308f4ae17be80b63808558d0adb02202f07e3d1f79dc8da285ae0d7f68083d769c11f5621ebd9691d6b48c0d4283d7d01483045022100a346c61738304eac5e7702188764d19cdf68f4466196729db096d6c87ce18cdd022018c0e8ad03054b0e7e235cda6bedecf35881d7aa7d94ff425a8ace7220f38af0014cc952410479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b84104c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a4104f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e67253aeffffffff01e8030000000000001976a914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac00000000')
var tx2 = txb.build()
assert.equal(tx2.getId(), 'eab59618a564e361adef6d918bd792903c3d41bcf1220137364fb847880467f9')
assert.equal(bscript.toASM(tx2.ins[0].script), 'OP_0 3045022100daf0f4f3339d9fbab42b098045c1e4958ee3b308f4ae17be80b63808558d0adb02202f07e3d1f79dc8da285ae0d7f68083d769c11f5621ebd9691d6b48c0d4283d7d01 3045022100a346c61738304eac5e7702188764d19cdf68f4466196729db096d6c87ce18cdd022018c0e8ad03054b0e7e235cda6bedecf35881d7aa7d94ff425a8ace7220f38af001 52410479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b84104c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a4104f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e67253ae')
})
})
})