From 098188dd3afc0be786b07d7780b287ca80544eba Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 17 Jan 2018 14:25:06 +1100 Subject: [PATCH] tests: add independent error message for missing witnessScript --- src/transaction_builder.js | 7 +++++-- test/fixtures/transaction_builder.json | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/transaction_builder.js b/src/transaction_builder.js index 5760fac..12ff3c3 100644 --- a/src/transaction_builder.js +++ b/src/transaction_builder.js @@ -332,11 +332,14 @@ function prepareInput (input, kpPubKey, redeemScript, witnessValue, witnessScrip signScript = witnessScript } else if (input.prevOutType) { // embedded scripts are not possible without a redeemScript - if (input.prevOutType === scriptTypes.P2SH || - input.prevOutType === scriptTypes.P2WSH) { + if (input.prevOutType === scriptTypes.P2SH) { throw new Error('PrevOutScript is ' + input.prevOutType + ', requires redeemScript') } + if (input.prevOutType === scriptTypes.P2WSH) { + throw new Error('PrevOutScript is ' + input.prevOutType + ', requires witnessScript') + } + prevOutType = input.prevOutType prevOutScript = input.prevOutScript expanded = expandOutput(input.prevOutScript, input.prevOutType, kpPubKey) diff --git a/test/fixtures/transaction_builder.json b/test/fixtures/transaction_builder.json index caf0912..5d746a1 100644 --- a/test/fixtures/transaction_builder.json +++ b/test/fixtures/transaction_builder.json @@ -1966,6 +1966,28 @@ } ] }, + { + "exception": "PrevOutScript is witnessscripthash, requires witnessScript", + "inputs": [ + { + "txId": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "vout": 1, + "prevTxScript": "OP_0 0f9ea7bae7166c980169059e39443ed13324495b0d6678ce716262e879591210", + "signs": [ + { + "keyPair": "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn", + "throws": true + } + ] + } + ], + "outputs": [ + { + "script": "OP_DUP OP_HASH160 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5 OP_EQUALVERIFY OP_CHECKSIG", + "value": 1000 + } + ] + }, { "exception": "Inconsistent redeemScript", "network": "testnet",