Skip to content

Commit 5057d8d

Browse files
committed
tests/txb: add P2WSH(multisig), incomplete fixture
1 parent 0157f18 commit 5057d8d

File tree

3 files changed

+68
-9
lines changed

3 files changed

+68
-9
lines changed

src/transaction_builder.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function expandInput (scriptSig, witnessStack) {
8282
script = redeemScript
8383
}
8484

85-
var classifyWitness = bscript.classifyWitness(witnessStack)
85+
var classifyWitness = bscript.classifyWitness(witnessStack, true)
8686
if (classifyWitness === scriptTypes.P2WSH) {
8787
witnessScript = witnessStack[witnessStack.length - 1]
8888
witnessScriptType = bscript.classifyOutput(witnessScript)
@@ -399,7 +399,6 @@ function buildStack (type, signatures, pubKeys, allowIncomplete) {
399399
}
400400

401401
if (!allowIncomplete) throw new Error('Not enough signatures provided')
402-
403402
return []
404403
}
405404

@@ -460,7 +459,7 @@ function buildInput (input, allowIncomplete) {
460459
return {
461460
type: scriptType,
462461
script: bscript.compile(sig),
463-
witness: witness
462+
witness: bscript.toStack(witness)
464463
}
465464
}
466465

test/fixtures/transaction_builder.json

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,11 +1327,68 @@
13271327
}
13281328
],
13291329
"locktime": 0
1330+
},
1331+
{
1332+
"description": "P2SH(P2WSH(multisig 2-of-2)), incomplete",
1333+
"network": "testnet",
1334+
"txHex": "010000000001012915794541ffa77ca795ec7c23ee989a63ccd1a71fab73e1c27ed20c4b6c69a4010000002322002024376a0a9abab599d0e028248d48ebe817bc899efcffa1cd2984d67289daf5afffffffff01b8820100000000001976a914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac040047304402203b334650f1f13574a1c2edc76421867f7252950968bf0293c8b3ed086ab89e3d0220565cafab0a5044617e94756b948241525b2483a52504e1064d29f641fb18129e010047522102bbbd6eb01efcbe4bd9664b886f26f69de5afcb2e479d72596c8bf21929e352e22102d9c3f7180ef13ec5267723c9c2ffab56a4215241f837502ea8977c8532b9ea1952ae00000000",
1335+
"incomplete": true,
1336+
"inputs": [
1337+
{
1338+
"txId": "a4696c4b0cd27ec2e173ab1fa7d1cc639a98ee237cec95a77ca7ff4145791529",
1339+
"vout": 1,
1340+
"signs": [
1341+
{
1342+
"keyPair": "cRAwuVuVSBZMPu7hdrYvMCZ8eevzmkExjFbaBLhqnDdrezxN3nTS",
1343+
"witnessScript": "OP_2 02bbbd6eb01efcbe4bd9664b886f26f69de5afcb2e479d72596c8bf21929e352e2 02d9c3f7180ef13ec5267723c9c2ffab56a4215241f837502ea8977c8532b9ea19 OP_2 OP_CHECKMULTISIG",
1344+
"redeemScript": "OP_0 24376a0a9abab599d0e028248d48ebe817bc899efcffa1cd2984d67289daf5af",
1345+
"value": 100000
1346+
}
1347+
],
1348+
"prevTxScript": "OP_HASH160 b64f1a3eacc1c8515592a6f10457e8ff90e4db6a OP_EQUAL"
1349+
}
1350+
],
1351+
"outputs": [
1352+
{
1353+
"script": "OP_DUP OP_HASH160 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5 OP_EQUALVERIFY OP_CHECKSIG",
1354+
"value": 99000
1355+
}
1356+
]
1357+
},
1358+
{
1359+
"description": "P2SH(P2WSH(multisig 2-of-2))",
1360+
"network": "testnet",
1361+
"txHex": "010000000001012915794541ffa77ca795ec7c23ee989a63ccd1a71fab73e1c27ed20c4b6c69a4010000002322002024376a0a9abab599d0e028248d48ebe817bc899efcffa1cd2984d67289daf5afffffffff01b8820100000000001976a914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac040047304402203b334650f1f13574a1c2edc76421867f7252950968bf0293c8b3ed086ab89e3d0220565cafab0a5044617e94756b948241525b2483a52504e1064d29f641fb18129e0148304502210096e859827fb629b6547658c613f7c8298de151513d74b224560aa8608d521d600220736fb5564322237716ec940de44c67c428198adf5dedfda183c17aa77cd28d640147522102bbbd6eb01efcbe4bd9664b886f26f69de5afcb2e479d72596c8bf21929e352e22102d9c3f7180ef13ec5267723c9c2ffab56a4215241f837502ea8977c8532b9ea1952ae00000000",
1362+
"incomplete": true,
1363+
"inputs": [
1364+
{
1365+
"txId": "a4696c4b0cd27ec2e173ab1fa7d1cc639a98ee237cec95a77ca7ff4145791529",
1366+
"vout": 1,
1367+
"signs": [
1368+
{
1369+
"keyPair": "cRAwuVuVSBZMPu7hdrYvMCZ8eevzmkExjFbaBLhqnDdrezxN3nTS",
1370+
"witnessScript": "OP_2 02bbbd6eb01efcbe4bd9664b886f26f69de5afcb2e479d72596c8bf21929e352e2 02d9c3f7180ef13ec5267723c9c2ffab56a4215241f837502ea8977c8532b9ea19 OP_2 OP_CHECKMULTISIG",
1371+
"redeemScript": "OP_0 24376a0a9abab599d0e028248d48ebe817bc899efcffa1cd2984d67289daf5af",
1372+
"value": 100000
1373+
},
1374+
{
1375+
"keyPair": "cTUFsNeVd8TKU4yREN8nMdViNnHyNvCCYVRmRUmkMLgomiMWTiii",
1376+
"witnessScript": "OP_2 02bbbd6eb01efcbe4bd9664b886f26f69de5afcb2e479d72596c8bf21929e352e2 02d9c3f7180ef13ec5267723c9c2ffab56a4215241f837502ea8977c8532b9ea19 OP_2 OP_CHECKMULTISIG",
1377+
"redeemScript": "OP_0 24376a0a9abab599d0e028248d48ebe817bc899efcffa1cd2984d67289daf5af",
1378+
"value": 100000
1379+
}
1380+
],
1381+
"prevTxScript": "OP_HASH160 b64f1a3eacc1c8515592a6f10457e8ff90e4db6a OP_EQUAL"
1382+
}
1383+
],
1384+
"outputs": [
1385+
{
1386+
"script": "OP_DUP OP_HASH160 aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5 OP_EQUALVERIFY OP_CHECKSIG",
1387+
"value": 99000
1388+
}
1389+
]
13301390
}
1331-
1332-
1333-
]
1334-
,
1391+
],
13351392
"fromTransaction": [
13361393
{
13371394
"description": "Transaction w/ scriptHash(multisig 2-of-2) -> OP_RETURN | 1 OP_0, no signatures",

test/transaction_builder.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ describe('TransactionBuilder', function () {
9191

9292
var tx = Transaction.fromHex(f.txHex)
9393
var txb = TransactionBuilder.fromTransaction(tx, network)
94-
assert.strictEqual(txb.build().toHex(), f.txHex)
94+
var txAfter = f.incomplete ? txb.buildIncomplete() : txb.build()
95+
96+
assert.strictEqual(txAfter.toHex(), f.txHex)
9597
assert.strictEqual(txb.network, network)
9698
})
9799
})
@@ -305,7 +307,8 @@ describe('TransactionBuilder', function () {
305307
fixtures.valid.build.forEach(function (f) {
306308
it('builds "' + f.description + '"', function () {
307309
var txb = construct(f)
308-
var tx = txb.build()
310+
var tx = f.incomplete ? txb.buildIncomplete() : txb.build()
311+
309312
assert.strictEqual(tx.toHex(), f.txHex)
310313
})
311314
})

0 commit comments

Comments
 (0)