tests: add failing test for #981
This commit is contained in:
parent
9a31b894c1
commit
39a681d2d3
3 changed files with 63 additions and 8 deletions
|
@ -259,7 +259,7 @@ function checkP2SHInput (input, redeemScriptHash) {
|
||||||
if (input.prevOutType !== scriptTypes.P2SH) throw new Error('PrevOutScript must be P2SH')
|
if (input.prevOutType !== scriptTypes.P2SH) throw new Error('PrevOutScript must be P2SH')
|
||||||
|
|
||||||
var prevOutScriptScriptHash = bscript.decompile(input.prevOutScript)[1]
|
var prevOutScriptScriptHash = bscript.decompile(input.prevOutScript)[1]
|
||||||
if (!prevOutScriptScriptHash.equals(redeemScriptHash)) throw new Error('Inconsistent hash160(RedeemScript)')
|
if (!prevOutScriptScriptHash.equals(redeemScriptHash)) throw new Error('Inconsistent hash160(redeemScript)')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ function checkP2WSHInput (input, witnessScriptHash) {
|
||||||
if (input.prevOutType !== scriptTypes.P2WSH) throw new Error('PrevOutScript must be P2WSH')
|
if (input.prevOutType !== scriptTypes.P2WSH) throw new Error('PrevOutScript must be P2WSH')
|
||||||
|
|
||||||
var scriptHash = bscript.decompile(input.prevOutScript)[1]
|
var scriptHash = bscript.decompile(input.prevOutScript)[1]
|
||||||
if (!scriptHash.equals(witnessScriptHash)) throw new Error('Inconsistent sha25(WitnessScript)')
|
if (!scriptHash.equals(witnessScriptHash)) throw new Error('Inconsistent sha256(witnessScript)')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,7 +310,7 @@ function prepareInput (input, kpPubKey, redeemScript, witnessValue, witnessScrip
|
||||||
checkP2SHInput(input, redeemScriptHash)
|
checkP2SHInput(input, redeemScriptHash)
|
||||||
|
|
||||||
expanded = expandOutput(redeemScript, undefined, kpPubKey)
|
expanded = expandOutput(redeemScript, undefined, kpPubKey)
|
||||||
if (!expanded.pubKeys) throw new Error('RedeemScript not supported "' + bscript.toASM(redeemScript) + '"')
|
if (!expanded.pubKeys) throw new Error(expanded.scriptType + ' not supported as redeemScript (' + bscript.toASM(witnessScript) + ')')
|
||||||
|
|
||||||
prevOutType = btemplates.types.P2SH
|
prevOutType = btemplates.types.P2SH
|
||||||
prevOutScript = btemplates.scriptHash.output.encode(redeemScriptHash)
|
prevOutScript = btemplates.scriptHash.output.encode(redeemScriptHash)
|
||||||
|
@ -323,7 +323,7 @@ function prepareInput (input, kpPubKey, redeemScript, witnessValue, witnessScrip
|
||||||
checkP2WSHInput(input, witnessScriptHash)
|
checkP2WSHInput(input, witnessScriptHash)
|
||||||
|
|
||||||
expanded = expandOutput(witnessScript, undefined, kpPubKey)
|
expanded = expandOutput(witnessScript, undefined, kpPubKey)
|
||||||
if (!expanded.pubKeys) throw new Error('WitnessScript not supported "' + bscript.toASM(redeemScript) + '"')
|
if (!expanded.pubKeys) throw new Error(expanded.scriptType + ' not supported as witnessScript (' + bscript.toASM(witnessScript) + ')')
|
||||||
|
|
||||||
prevOutType = btemplates.types.P2WSH
|
prevOutType = btemplates.types.P2WSH
|
||||||
prevOutScript = btemplates.witnessScriptHash.output.encode(witnessScriptHash)
|
prevOutScript = btemplates.witnessScriptHash.output.encode(witnessScriptHash)
|
||||||
|
|
53
test/fixtures/transaction_builder.json
vendored
53
test/fixtures/transaction_builder.json
vendored
|
@ -1040,8 +1040,8 @@
|
||||||
{
|
{
|
||||||
"keyPair": "L2FroWqrUgsPpTMhpXcAFnVDLPTToDbveh3bhDaU4jhe7Cw6YujN",
|
"keyPair": "L2FroWqrUgsPpTMhpXcAFnVDLPTToDbveh3bhDaU4jhe7Cw6YujN",
|
||||||
"hashType": 1,
|
"hashType": 1,
|
||||||
"witnessScript": "038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b OP_CHECKSIG",
|
|
||||||
"redeemScript": "OP_0 0f9ea7bae7166c980169059e39443ed13324495b0d6678ce716262e879591210",
|
"redeemScript": "OP_0 0f9ea7bae7166c980169059e39443ed13324495b0d6678ce716262e879591210",
|
||||||
|
"witnessScript": "038de63cf582d058a399a176825c045672d5ff8ea25b64d28d4375dcdb14c02b2b OP_CHECKSIG",
|
||||||
"value": 80000
|
"value": 80000
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -1922,6 +1922,57 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"description": "Transaction w/ P2WSH(P2PK), signing with uncompressed public key",
|
||||||
|
"exception": "BIP143 rejects uncompressed public keys in P2WPKH or P2WSH",
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"txId": "2fddebc1a7e67e04fc6b77645ae9ae10eeaa35e168606587d79b031ebca33345",
|
||||||
|
"vout": 0,
|
||||||
|
"prevTxScript": "OP_0 5339df4de3854c4208376443ed075014ad996aa349ad6b5abf6c4d20f604d348",
|
||||||
|
"signs": [
|
||||||
|
{
|
||||||
|
"keyPair": "5JiHJJjdufSiMxbvnyNcKtQNLYH6SvUpQnRv9yZENFDWTQKQkzC",
|
||||||
|
"witnessScript": "04f56d09b32cefc818735150bf8560eefdaf30d2edb3fe557bf27682aedaed81bf9aaff7eeb496e088058ec548826c12b521dbb566a862d9b67677910c2b421e06 OP_CHECKSIG",
|
||||||
|
"value": 80000,
|
||||||
|
"throws": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"script": "OP_DUP OP_HASH160 851a33a5ef0d4279bd5854949174e2c65b1d4500 OP_EQUALVERIFY OP_CHECKSIG",
|
||||||
|
"value": 60000
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Transaction w/ P2SH(P2WSH(P2PK)), signing with uncompressed public key",
|
||||||
|
"exception": "BIP143 rejects uncompressed public keys in P2WPKH or P2WSH",
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"txId": "2fddebc1a7e67e04fc6b77645ae9ae10eeaa35e168606587d79b031ebca33345",
|
||||||
|
"vout": 0,
|
||||||
|
"prevTxScript": "OP_HASH160 5afe12b2827e3eac05fe3f17c59406ef262aa177 OP_EQUAL",
|
||||||
|
"signs": [
|
||||||
|
{
|
||||||
|
"keyPair": "5JiHJJjdufSiMxbvnyNcKtQNLYH6SvUpQnRv9yZENFDWTQKQkzC",
|
||||||
|
"redeemScript": "OP_0 5339df4de3854c4208376443ed075014ad996aa349ad6b5abf6c4d20f604d348",
|
||||||
|
"witnessScript": "04f56d09b32cefc818735150bf8560eefdaf30d2edb3fe557bf27682aedaed81bf9aaff7eeb496e088058ec548826c12b521dbb566a862d9b67677910c2b421e06 OP_CHECKSIG",
|
||||||
|
"value": 80000,
|
||||||
|
"throws": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"script": "OP_DUP OP_HASH160 851a33a5ef0d4279bd5854949174e2c65b1d4500 OP_EQUALVERIFY OP_CHECKSIG",
|
||||||
|
"value": 60000
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"exception": "RedeemScript not supported \"OP_RETURN 06deadbeef03f895a2ad89fb6d696497af486cb7c644a27aa568c7a18dd06113401115185474\"",
|
"exception": "RedeemScript not supported \"OP_RETURN 06deadbeef03f895a2ad89fb6d696497af486cb7c644a27aa568c7a18dd06113401115185474\"",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
|
|
|
@ -315,17 +315,21 @@ describe('TransactionBuilder', function () {
|
||||||
input.signs.forEach(function (sign) {
|
input.signs.forEach(function (sign) {
|
||||||
var keyPairNetwork = NETWORKS[sign.network || f.network]
|
var keyPairNetwork = NETWORKS[sign.network || f.network]
|
||||||
var keyPair2 = ECPair.fromWIF(sign.keyPair, keyPairNetwork)
|
var keyPair2 = ECPair.fromWIF(sign.keyPair, keyPairNetwork)
|
||||||
var redeemScript
|
var redeemScript, witnessScript
|
||||||
|
|
||||||
if (sign.redeemScript) {
|
if (sign.redeemScript) {
|
||||||
redeemScript = bscript.fromASM(sign.redeemScript)
|
redeemScript = bscript.fromASM(sign.redeemScript)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sign.witnessScript) {
|
||||||
|
witnessScript = bscript.fromASM(sign.witnessScript)
|
||||||
|
}
|
||||||
|
|
||||||
if (!sign.throws) {
|
if (!sign.throws) {
|
||||||
txb.sign(index, keyPair2, redeemScript, sign.hashType, sign.value)
|
txb.sign(index, keyPair2, redeemScript, sign.hashType, sign.value, witnessScript)
|
||||||
} else {
|
} else {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
txb.sign(index, keyPair2, redeemScript, sign.hashType, sign.value)
|
txb.sign(index, keyPair2, redeemScript, sign.hashType, sign.value, witnessScript)
|
||||||
}, new RegExp(f.exception))
|
}, new RegExp(f.exception))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue