scripts: extract all scripts to encode/decode/check style
This commit is contained in:
parent
27b48e8aa2
commit
d9fa39a2cc
23 changed files with 852 additions and 729 deletions
test
492
test/fixtures/script.json
vendored
492
test/fixtures/script.json
vendored
|
@ -188,249 +188,253 @@
|
|||
"hex": "4effffffff01"
|
||||
}
|
||||
],
|
||||
"isPubKeyHashInput": [
|
||||
{
|
||||
"description": "pubKeyHash input : extraneous data",
|
||||
"scriptSig": "304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801 02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1 ffffffff"
|
||||
}
|
||||
],
|
||||
"isScriptHashInput": [
|
||||
{
|
||||
"description": "redeemScript not data",
|
||||
"scriptSig": "OP_0 304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801 3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501 OP_RESERVED"
|
||||
},
|
||||
{
|
||||
"description": "redeemScript is a signature, therefore not a valid script",
|
||||
"scriptSig": "OP_0 3045022100e12b17b3a4c80c401a1687487bd2bafee9e5f1f8f1ffc6180ce186672ad7b43a02205e316d1e5e71822f5ef301b694e578fa9c94af4f5f098c952c833f4691307f4e01"
|
||||
}
|
||||
],
|
||||
"isPubKeyInput": [
|
||||
{
|
||||
"description": "non-canonical signature (too short)",
|
||||
"scriptSig": "304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf7593"
|
||||
},
|
||||
{
|
||||
"description": "non-canonical signature (too long)",
|
||||
"scriptSig": "304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca28ffffffff01"
|
||||
},
|
||||
{
|
||||
"description": "non-canonical signature (invalid hashType)",
|
||||
"scriptSig": "304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca28ff"
|
||||
}
|
||||
],
|
||||
"isPubKeyOutput": [
|
||||
{
|
||||
"description": "non-canonical pubkey (too short)",
|
||||
"scriptPubKey": "02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce OP_CHECKSIG"
|
||||
},
|
||||
{
|
||||
"description": "non-canonical pubkey (too long)",
|
||||
"scriptPubKey": "02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1ffffff OP_CHECKSIG"
|
||||
},
|
||||
{
|
||||
"description": "last operator is wrong for pubkey-output",
|
||||
"scriptPubKeyHex": "21027a71801ab59336de37785c50005b6abd8ea859eecce1edbe8e81afa74ee5c752ae"
|
||||
},
|
||||
{
|
||||
"description": "missing OP_CHECKSIG",
|
||||
"scriptPubKeyHex": "21027a71801ab59336de37785c50005b6abd8ea859eecce1edbe8e81afa74ee5c752"
|
||||
},
|
||||
{
|
||||
"description": "non-canonical pubkey (bad prefix)",
|
||||
"scriptPubKey": "427a71801ab59336de37785c50005b6abd8ea859eecce1edbe8e81afa74ee5c752 OP_CHECKSIG"
|
||||
},
|
||||
{
|
||||
"description": "has extra opcode at the end isPubKeyOutput",
|
||||
"scriptPubKey": "027a71801ab59336de37785c50005b6abd8ea859eecce1edbe8e81afa74ee5c752 OP_CHECKSIG OP_0"
|
||||
}
|
||||
],
|
||||
"isPubKeyHashOutput": [
|
||||
{
|
||||
"description": "non-minimal encoded isPubKeyHashOutput (non BIP62 compliant)",
|
||||
"scriptPubKeyHex": "76a94c14aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac"
|
||||
},
|
||||
{
|
||||
"description": "bad OP_DUP isPubKeyHashOutput",
|
||||
"scriptPubKeyHex": "aca914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac"
|
||||
},
|
||||
{
|
||||
"description": "bad OP_HASH160 isPubKeyHashOutput",
|
||||
"scriptPubKeyHex": "76ac14aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac"
|
||||
},
|
||||
{
|
||||
"description": "bad OP_EQUALVERIFY isPubKeyHashOutput",
|
||||
"scriptPubKeyHex": "76a914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5acac"
|
||||
},
|
||||
{
|
||||
"description": "bad OP_CHECKSIG isPubKeyHashOutput",
|
||||
"scriptPubKeyHex": "76a914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c58888"
|
||||
},
|
||||
{
|
||||
"description": "bad length isPubKeyHashOutput",
|
||||
"scriptPubKeyHex": "76a920aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac"
|
||||
},
|
||||
{
|
||||
"description": "has something at the end isPubKeyHashOutput",
|
||||
"scriptPubKeyHex": "76a920aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac00"
|
||||
}
|
||||
],
|
||||
"isScriptHashOutput": [
|
||||
{
|
||||
"description": "non-minimal encoded isScriptHashOutput (non BIP62 compliant)",
|
||||
"scriptPubKeyHex": "a94c14c286a1af0947f58d1ad787385b1c2c4a976f9e7187"
|
||||
},
|
||||
{
|
||||
"description": "wrong OP_HASH160 opcode",
|
||||
"scriptPubKeyHex": "ac4c14c286a1af0947f58d1ad787385b1c2c4a976f9e7187"
|
||||
},
|
||||
{
|
||||
"description": "wrong length marker",
|
||||
"scriptPubKeyHex": "a916c286a1af0947f58d1ad787385b1c2c4a976f9e7187"
|
||||
},
|
||||
{
|
||||
"description": "wrong OP_EQUAL opcode",
|
||||
"scriptPubKeyHex": "a914c286a1af0947f58d1ad787385b1c2c4a976f9e7188"
|
||||
}
|
||||
],
|
||||
"isWitnessPubKeyHashOutput": [
|
||||
{
|
||||
"description": "wrong version",
|
||||
"scriptPubKeyHex": "51149090909090909090909090909090909090909090"
|
||||
},
|
||||
{
|
||||
"description": "wrong length marker",
|
||||
"scriptPubKeyHex": "00209090909090909090909090909090909090909090"
|
||||
}
|
||||
],
|
||||
"isWitnessScriptHashOutput": [
|
||||
{
|
||||
"description": "wrong version",
|
||||
"scriptPubKeyHex": "51209090909090909090909090909090909090909090909090909090909090909090"
|
||||
},
|
||||
{
|
||||
"description": "wrong length marker",
|
||||
"scriptPubKeyHex": "00219090909090909090909090909090909090909090909090909090909090909090"
|
||||
}
|
||||
],
|
||||
"isMultisigOutput": [
|
||||
{
|
||||
"description": "OP_CHECKMULTISIG not found",
|
||||
"scriptPubKey": "OP_0 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 OP_2 OP_HASH160"
|
||||
},
|
||||
{
|
||||
"description": "less than 4 chunks",
|
||||
"scriptPubKey": "OP_0 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 OP_HASH160"
|
||||
},
|
||||
{
|
||||
"description": "m === 0",
|
||||
"scriptPubKey": "OP_0 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 OP_2 OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "m < OP_1",
|
||||
"scriptPubKey": "OP_1NEGATE 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 OP_2 OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "m > OP_16",
|
||||
"scriptPubKey": "OP_NOP 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 OP_2 OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "n === 0",
|
||||
"scriptPubKey": "OP_1 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 OP_0 OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "n < OP_1",
|
||||
"scriptPubKey": "OP_1 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 OP_1NEGATE OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "n > OP_16",
|
||||
"scriptPubKey": "OP_1 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 OP_NOP OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "n < m",
|
||||
"scriptPubKey": "OP_2 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 OP_1 OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "n < len(pubKeys)",
|
||||
"scriptPubKey": "OP_2 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 024289801366bcee6172b771cf5a7f13aaecd237a0b9a1ff9d769cabc2e6b70a34 OP_2 OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "n > len(pubKeys)",
|
||||
"scriptPubKey": "OP_1 024289801366bcee6172b771cf5a7f13aaecd237a0b9a1ff9d769cabc2e6b70a34 OP_2 OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "m is data",
|
||||
"scriptPubKey": "ffff 024289801366bcee6172b771cf5a7f13aaecd237a0b9a1ff9d769cabc2e6b70a34 OP_1 OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "n is data",
|
||||
"scriptPubKey": "OP_1 024289801366bcee6172b771cf5a7f13aaecd237a0b9a1ff9d769cabc2e6b70a34 ffff OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "non-canonical pubKey (bad length)",
|
||||
"scriptPubKey": "OP_1 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ffff OP_1 OP_CHECKMULTISIG"
|
||||
}
|
||||
],
|
||||
"multisigInput": [
|
||||
{
|
||||
"description": "Not enough signatures provided",
|
||||
"type": "multisig",
|
||||
"scriptPubKey": "OP_2 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 OP_2 OP_CHECKMULTISIG",
|
||||
"signatures": []
|
||||
},
|
||||
{
|
||||
"exception": "Not enough signatures provided",
|
||||
"scriptPubKey": "OP_2 02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1 0395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a OP_2 OP_CHECKMULTISIG",
|
||||
"signatures": [
|
||||
"304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801"
|
||||
]
|
||||
},
|
||||
{
|
||||
"exception": "Too many signatures provided",
|
||||
"scriptPubKey": "OP_2 02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1 0395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a OP_2 OP_CHECKMULTISIG",
|
||||
"signatures": [
|
||||
"304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801",
|
||||
"3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501",
|
||||
"3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501"
|
||||
]
|
||||
}
|
||||
],
|
||||
"multisigOutput": [
|
||||
{
|
||||
"exception": "Not enough pubKeys provided",
|
||||
"m": 4,
|
||||
"pubKeys": [
|
||||
"02ea1297665dd733d444f31ec2581020004892cdaaf3dd6c0107c615afb839785f",
|
||||
"02fab2dea1458990793f56f42e4a47dbf35a12a351f26fa5d7e0cc7447eaafa21f",
|
||||
"036c6802ce7e8113723dd92cdb852e492ebb157a871ca532c3cb9ed08248ff0e19"
|
||||
],
|
||||
"signatures": [
|
||||
"304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801"
|
||||
]
|
||||
}
|
||||
],
|
||||
"pubKeyHashOutput": [
|
||||
{
|
||||
"exception": "Expected Buffer\\(Length: 20\\), got Buffer\\(Length: 2\\)",
|
||||
"hash": "ffff"
|
||||
}
|
||||
],
|
||||
"scriptHashOutput": [
|
||||
{
|
||||
"exception": "Expected Buffer\\(Length: 20\\), got Buffer\\(Length: 3\\)",
|
||||
"hash": "ffffff"
|
||||
}
|
||||
],
|
||||
"witnessPubKeyHashOutput": [
|
||||
{
|
||||
"exception": "Expected Buffer\\(Length: 20\\), got Buffer\\(Length: 3\\)",
|
||||
"hash": "ffffff"
|
||||
}
|
||||
],
|
||||
"witnessScriptHashOutput": [
|
||||
{
|
||||
"exception": "Expected Buffer\\(Length: 32\\), got Buffer\\(Length: 3\\)",
|
||||
"hash": "ffffff"
|
||||
}
|
||||
]
|
||||
"pubKey": {
|
||||
"inputs": [
|
||||
{
|
||||
"description": "non-canonical signature (too short)",
|
||||
"scriptSig": "304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf7593"
|
||||
},
|
||||
{
|
||||
"description": "non-canonical signature (too long)",
|
||||
"scriptSig": "304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca28ffffffff01"
|
||||
},
|
||||
{
|
||||
"description": "non-canonical signature (invalid hashType)",
|
||||
"scriptSig": "304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca28ff"
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"description": "non-canonical pubkey (too short)",
|
||||
"scriptPubKey": "02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce OP_CHECKSIG"
|
||||
},
|
||||
{
|
||||
"description": "non-canonical pubkey (too long)",
|
||||
"scriptPubKey": "02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1ffffff OP_CHECKSIG"
|
||||
},
|
||||
{
|
||||
"description": "last operator is wrong for pubkey-output",
|
||||
"scriptPubKeyHex": "21027a71801ab59336de37785c50005b6abd8ea859eecce1edbe8e81afa74ee5c752ae"
|
||||
},
|
||||
{
|
||||
"description": "missing OP_CHECKSIG",
|
||||
"scriptPubKeyHex": "21027a71801ab59336de37785c50005b6abd8ea859eecce1edbe8e81afa74ee5c752"
|
||||
},
|
||||
{
|
||||
"description": "non-canonical pubkey (bad prefix)",
|
||||
"scriptPubKey": "427a71801ab59336de37785c50005b6abd8ea859eecce1edbe8e81afa74ee5c752 OP_CHECKSIG"
|
||||
},
|
||||
{
|
||||
"description": "has extra opcode at the end isPubKeyOutput",
|
||||
"scriptPubKey": "027a71801ab59336de37785c50005b6abd8ea859eecce1edbe8e81afa74ee5c752 OP_CHECKSIG OP_0"
|
||||
}
|
||||
]
|
||||
},
|
||||
"pubKeyHash": {
|
||||
"inputs": [
|
||||
{
|
||||
"description": "pubKeyHash input : extraneous data",
|
||||
"scriptSig": "304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801 02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1 ffffffff"
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"description": "non-minimal encoded isPubKeyHashOutput (non BIP62 compliant)",
|
||||
"scriptPubKeyHex": "76a94c14aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac"
|
||||
},
|
||||
{
|
||||
"description": "bad OP_DUP isPubKeyHashOutput",
|
||||
"scriptPubKeyHex": "aca914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac"
|
||||
},
|
||||
{
|
||||
"description": "bad OP_HASH160 isPubKeyHashOutput",
|
||||
"scriptPubKeyHex": "76ac14aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac"
|
||||
},
|
||||
{
|
||||
"description": "bad OP_EQUALVERIFY isPubKeyHashOutput",
|
||||
"scriptPubKeyHex": "76a914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5acac"
|
||||
},
|
||||
{
|
||||
"description": "bad OP_CHECKSIG isPubKeyHashOutput",
|
||||
"scriptPubKeyHex": "76a914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c58888"
|
||||
},
|
||||
{
|
||||
"description": "bad length isPubKeyHashOutput",
|
||||
"scriptPubKeyHex": "76a920aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac"
|
||||
},
|
||||
{
|
||||
"description": "has something at the end isPubKeyHashOutput",
|
||||
"scriptPubKeyHex": "76a920aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac00"
|
||||
},
|
||||
{
|
||||
"exception": "Expected Buffer\\(Length: 20\\), got Buffer\\(Length: 2\\)",
|
||||
"hash": "ffff"
|
||||
}
|
||||
]
|
||||
},
|
||||
"scriptHash": {
|
||||
"inputs": [
|
||||
{
|
||||
"description": "redeemScript not data",
|
||||
"scriptSig": "OP_0 304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801 3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501 OP_RESERVED"
|
||||
},
|
||||
{
|
||||
"description": "redeemScript is a signature, therefore not a valid script",
|
||||
"scriptSig": "OP_0 3045022100e12b17b3a4c80c401a1687487bd2bafee9e5f1f8f1ffc6180ce186672ad7b43a02205e316d1e5e71822f5ef301b694e578fa9c94af4f5f098c952c833f4691307f4e01"
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"description": "non-minimal encoded isScriptHashOutput (non BIP62 compliant)",
|
||||
"scriptPubKeyHex": "a94c14c286a1af0947f58d1ad787385b1c2c4a976f9e7187"
|
||||
},
|
||||
{
|
||||
"description": "wrong OP_HASH160 opcode",
|
||||
"scriptPubKeyHex": "ac4c14c286a1af0947f58d1ad787385b1c2c4a976f9e7187"
|
||||
},
|
||||
{
|
||||
"description": "wrong length marker",
|
||||
"scriptPubKeyHex": "a916c286a1af0947f58d1ad787385b1c2c4a976f9e7187"
|
||||
},
|
||||
{
|
||||
"description": "wrong OP_EQUAL opcode",
|
||||
"scriptPubKeyHex": "a914c286a1af0947f58d1ad787385b1c2c4a976f9e7188"
|
||||
},
|
||||
{
|
||||
"exception": "Expected Buffer\\(Length: 20\\), got Buffer\\(Length: 3\\)",
|
||||
"hash": "ffffff"
|
||||
}
|
||||
]
|
||||
},
|
||||
"multisig": {
|
||||
"inputs": [
|
||||
{
|
||||
"description": "Not enough signatures provided",
|
||||
"type": "multisig",
|
||||
"scriptPubKey": "OP_2 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 OP_2 OP_CHECKMULTISIG",
|
||||
"signatures": []
|
||||
},
|
||||
{
|
||||
"exception": "Not enough signatures provided",
|
||||
"scriptPubKey": "OP_2 02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1 0395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a OP_2 OP_CHECKMULTISIG",
|
||||
"signatures": [
|
||||
"304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801"
|
||||
]
|
||||
},
|
||||
{
|
||||
"exception": "Too many signatures provided",
|
||||
"scriptPubKey": "OP_2 02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1 0395a9d84d47d524548f79f435758c01faec5da2b7e551d3b8c995b7e06326ae4a OP_2 OP_CHECKMULTISIG",
|
||||
"signatures": [
|
||||
"304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801",
|
||||
"3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501",
|
||||
"3045022100ef253c1faa39e65115872519e5f0a33bbecf430c0f35cf562beabbad4da24d8d02201742be8ee49812a73adea3007c9641ce6725c32cd44ddb8e3a3af460015d140501"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"description": "OP_CHECKMULTISIG not found",
|
||||
"scriptPubKey": "OP_0 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 OP_2 OP_HASH160"
|
||||
},
|
||||
{
|
||||
"description": "less than 4 chunks",
|
||||
"scriptPubKey": "OP_0 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 OP_HASH160"
|
||||
},
|
||||
{
|
||||
"description": "m === 0",
|
||||
"scriptPubKey": "OP_0 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 OP_2 OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "m < OP_1",
|
||||
"scriptPubKey": "OP_1NEGATE 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 OP_2 OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "m > OP_16",
|
||||
"scriptPubKey": "OP_NOP 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 OP_2 OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "n === 0",
|
||||
"scriptPubKey": "OP_1 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 OP_0 OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "n < OP_1",
|
||||
"scriptPubKey": "OP_1 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 OP_1NEGATE OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "n > OP_16",
|
||||
"scriptPubKey": "OP_1 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 OP_NOP OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "n < m",
|
||||
"scriptPubKey": "OP_2 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 OP_1 OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "n < len(pubKeys)",
|
||||
"scriptPubKey": "OP_2 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 02b80011a883a0fd621ad46dfc405df1e74bf075cbaf700fd4aebef6e96f848340 024289801366bcee6172b771cf5a7f13aaecd237a0b9a1ff9d769cabc2e6b70a34 OP_2 OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "n > len(pubKeys)",
|
||||
"scriptPubKey": "OP_1 024289801366bcee6172b771cf5a7f13aaecd237a0b9a1ff9d769cabc2e6b70a34 OP_2 OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "m is data",
|
||||
"scriptPubKey": "ffff 024289801366bcee6172b771cf5a7f13aaecd237a0b9a1ff9d769cabc2e6b70a34 OP_1 OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "n is data",
|
||||
"scriptPubKey": "OP_1 024289801366bcee6172b771cf5a7f13aaecd237a0b9a1ff9d769cabc2e6b70a34 ffff OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"description": "non-canonical pubKey (bad length)",
|
||||
"scriptPubKey": "OP_1 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ffff OP_1 OP_CHECKMULTISIG"
|
||||
},
|
||||
{
|
||||
"exception": "Not enough pubKeys provided",
|
||||
"m": 4,
|
||||
"pubKeys": [
|
||||
"02ea1297665dd733d444f31ec2581020004892cdaaf3dd6c0107c615afb839785f",
|
||||
"02fab2dea1458990793f56f42e4a47dbf35a12a351f26fa5d7e0cc7447eaafa21f",
|
||||
"036c6802ce7e8113723dd92cdb852e492ebb157a871ca532c3cb9ed08248ff0e19"
|
||||
],
|
||||
"signatures": [
|
||||
"304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"witnessPubKeyHash": {
|
||||
"inputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"description": "wrong version",
|
||||
"scriptPubKeyHex": "51149090909090909090909090909090909090909090"
|
||||
},
|
||||
{
|
||||
"description": "wrong length marker",
|
||||
"scriptPubKeyHex": "00209090909090909090909090909090909090909090"
|
||||
},
|
||||
{
|
||||
"exception": "Expected Buffer\\(Length: 20\\), got Buffer\\(Length: 3\\)",
|
||||
"hash": "ffffff"
|
||||
}
|
||||
]
|
||||
},
|
||||
"witnessScriptHash": {
|
||||
"inputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"description": "wrong version",
|
||||
"scriptPubKeyHex": "51209090909090909090909090909090909090909090909090909090909090909090"
|
||||
},
|
||||
{
|
||||
"description": "wrong length marker",
|
||||
"scriptPubKeyHex": "00219090909090909090909090909090909090909090909090909090909090909090"
|
||||
},
|
||||
{
|
||||
"exception": "Expected Buffer\\(Length: 32\\), got Buffer\\(Length: 3\\)",
|
||||
"hash": "ffffff"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
137
test/script.js
137
test/script.js
|
@ -146,44 +146,43 @@ describe('script', function () {
|
|||
})
|
||||
|
||||
;[
|
||||
'PubKey',
|
||||
'PubKeyHash',
|
||||
'ScriptHash',
|
||||
'WitnessPubKeyHash',
|
||||
'WitnessScriptHash',
|
||||
'Multisig',
|
||||
'NullData'
|
||||
].forEach(function (type) {
|
||||
var inputFnName = 'is' + type + 'Input'
|
||||
var outputFnName = 'is' + type + 'Output'
|
||||
'pubKey',
|
||||
'pubKeyHash',
|
||||
'scriptHash',
|
||||
'witnessPubKeyHash',
|
||||
'witnessScriptHash',
|
||||
'multisig',
|
||||
'nullData'
|
||||
].forEach(function (name) {
|
||||
var inputType = bscript[name].input
|
||||
var outputType = bscript[name].output
|
||||
|
||||
var inputFn = bscript[inputFnName]
|
||||
var outputFn = bscript[outputFnName]
|
||||
|
||||
describe('is' + type + 'Input', function () {
|
||||
describe(name + '.input.check', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
var expected = type.toLowerCase() === f.type
|
||||
var expected = name.toLowerCase() === f.type
|
||||
|
||||
if (inputFn && f.scriptSig) {
|
||||
if (inputType && f.scriptSig) {
|
||||
var scriptSig = bscript.fromASM(f.scriptSig)
|
||||
|
||||
it('returns ' + expected + ' for ' + f.scriptSig, function () {
|
||||
assert.strictEqual(inputFn(scriptSig), expected)
|
||||
assert.strictEqual(inputType.check(scriptSig), expected)
|
||||
})
|
||||
|
||||
if (f.typeIncomplete) {
|
||||
var expectedIncomplete = type.toLowerCase() === f.typeIncomplete
|
||||
var expectedIncomplete = name.toLowerCase() === f.typeIncomplete
|
||||
|
||||
it('returns ' + expected + ' for ' + f.scriptSig, function () {
|
||||
assert.strictEqual(inputFn(scriptSig, true), expectedIncomplete)
|
||||
assert.strictEqual(inputType.check(scriptSig, true), expectedIncomplete)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (!(inputFnName in fixtures.invalid)) return
|
||||
if (!(fixtures.invalid[name])) return
|
||||
|
||||
fixtures.invalid[name].inputs.forEach(function (f) {
|
||||
if (!f.scriptSig && !f.scriptSigHex) return
|
||||
|
||||
fixtures.invalid[inputFnName].forEach(function (f) {
|
||||
it('returns false for ' + f.description + ' (' + (f.scriptSig || f.scriptSigHex) + ')', function () {
|
||||
var scriptSig
|
||||
|
||||
|
@ -193,27 +192,29 @@ describe('script', function () {
|
|||
scriptSig = new Buffer(f.scriptSigHex, 'hex')
|
||||
}
|
||||
|
||||
assert.strictEqual(inputFn(scriptSig), false)
|
||||
assert.strictEqual(inputType.check(scriptSig), false)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('is' + type + 'Output', function () {
|
||||
describe(name + '.output.check', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
var expected = type.toLowerCase() === f.type
|
||||
var expected = name.toLowerCase() === f.type
|
||||
|
||||
if (outputFn && f.scriptPubKey) {
|
||||
if (outputType && f.scriptPubKey) {
|
||||
it('returns ' + expected + ' for ' + f.scriptPubKey, function () {
|
||||
var scriptPubKey = bscript.fromASM(f.scriptPubKey)
|
||||
|
||||
assert.strictEqual(outputFn(scriptPubKey), expected)
|
||||
assert.strictEqual(outputType.check(scriptPubKey), expected)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
if (!(outputFnName in fixtures.invalid)) return
|
||||
if (!(fixtures.invalid[name])) return
|
||||
|
||||
fixtures.invalid[name].outputs.forEach(function (f) {
|
||||
if (!f.scriptPubKey && !f.scriptPubKeyHex) return
|
||||
|
||||
fixtures.invalid[outputFnName].forEach(function (f) {
|
||||
it('returns false for ' + f.description + ' (' + (f.scriptPubKey || f.scriptPubKeyHex) + ')', function () {
|
||||
var scriptPubKey
|
||||
|
||||
|
@ -223,39 +224,39 @@ describe('script', function () {
|
|||
scriptPubKey = new Buffer(f.scriptPubKeyHex, 'hex')
|
||||
}
|
||||
|
||||
assert.strictEqual(outputFn(scriptPubKey), false)
|
||||
assert.strictEqual(outputType.check(scriptPubKey), false)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('pubKeyInput', function () {
|
||||
describe('pubKey.input.encode', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'pubkey') return
|
||||
|
||||
it('returns ' + f.scriptSig, function () {
|
||||
var signature = new Buffer(f.signature, 'hex')
|
||||
|
||||
var scriptSig = bscript.pubKeyInput(signature)
|
||||
var scriptSig = bscript.pubKey.input.encode(signature)
|
||||
assert.strictEqual(bscript.toASM(scriptSig), f.scriptSig)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('pubKeyOutput', function () {
|
||||
describe('pubKey.output.encode', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'pubkey') return
|
||||
|
||||
it('returns ' + f.scriptPubKey, function () {
|
||||
var pubKey = new Buffer(f.pubKey, 'hex')
|
||||
var scriptPubKey = bscript.pubKeyOutput(pubKey)
|
||||
var scriptPubKey = bscript.pubKey.output.encode(pubKey)
|
||||
|
||||
assert.strictEqual(bscript.toASM(scriptPubKey), f.scriptPubKey)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('pubKeyHashInput', function () {
|
||||
describe('pubKeyHash.input.encode', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'pubkeyhash') return
|
||||
|
||||
|
@ -264,13 +265,13 @@ describe('script', function () {
|
|||
it('returns ' + f.scriptSig, function () {
|
||||
var signature = new Buffer(f.signature, 'hex')
|
||||
|
||||
var scriptSig = bscript.pubKeyHashInput(signature, pubKey)
|
||||
var scriptSig = bscript.pubKeyHash.input.encode(signature, pubKey)
|
||||
assert.strictEqual(bscript.toASM(scriptSig), f.scriptSig)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('pubKeyHashOutput', function () {
|
||||
describe('pubKeyHash.output.encode', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'pubkeyhash') return
|
||||
|
||||
|
@ -278,23 +279,24 @@ describe('script', function () {
|
|||
var pubKeyHash = bcrypto.hash160(pubKey)
|
||||
|
||||
it('returns ' + f.scriptPubKey, function () {
|
||||
var scriptPubKey = bscript.pubKeyHashOutput(pubKeyHash)
|
||||
var scriptPubKey = bscript.pubKeyHash.output.encode(pubKeyHash)
|
||||
assert.strictEqual(bscript.toASM(scriptPubKey), f.scriptPubKey)
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.invalid.pubKeyHashOutput.forEach(function (f) {
|
||||
fixtures.invalid.pubKeyHash.outputs.forEach(function (f) {
|
||||
if (!f.hash) return
|
||||
var hash = new Buffer(f.hash, 'hex')
|
||||
|
||||
it('throws on ' + f.exception, function () {
|
||||
assert.throws(function () {
|
||||
bscript.pubKeyHashOutput(hash)
|
||||
bscript.pubKeyHash.output.encode(hash)
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('multisigInput', function () {
|
||||
describe('multisig.input.encode', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'multisig') return
|
||||
|
||||
|
@ -303,12 +305,13 @@ describe('script', function () {
|
|||
return signature ? new Buffer(signature, 'hex') : ops.OP_0
|
||||
})
|
||||
|
||||
var scriptSig = bscript.multisigInput(signatures)
|
||||
var scriptSig = bscript.multisig.input.encode(signatures)
|
||||
assert.strictEqual(bscript.toASM(scriptSig), f.scriptSig)
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.invalid.multisigInput.forEach(function (f) {
|
||||
fixtures.invalid.multisig.inputs.forEach(function (f) {
|
||||
if (!f.scriptPubKey) return
|
||||
var scriptPubKey = bscript.fromASM(f.scriptPubKey)
|
||||
|
||||
it('throws on ' + f.exception, function () {
|
||||
|
@ -317,38 +320,39 @@ describe('script', function () {
|
|||
})
|
||||
|
||||
assert.throws(function () {
|
||||
bscript.multisigInput(signatures, scriptPubKey)
|
||||
bscript.multisig.input.encode(signatures, scriptPubKey)
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('multisigOutput', function () {
|
||||
describe('multisig.output.encode', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'multisig') return
|
||||
|
||||
var pubKeys = f.pubKeys.map(function (p) { return new Buffer(p, 'hex') })
|
||||
var scriptPubKey = bscript.multisigOutput(pubKeys.length, pubKeys)
|
||||
var scriptPubKey = bscript.multisig.output.encode(pubKeys.length, pubKeys)
|
||||
|
||||
it('returns ' + f.scriptPubKey, function () {
|
||||
assert.strictEqual(bscript.toASM(scriptPubKey), f.scriptPubKey)
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.invalid.multisigOutput.forEach(function (f) {
|
||||
fixtures.invalid.multisig.outputs.forEach(function (f) {
|
||||
if (!f.pubKeys) return
|
||||
var pubKeys = f.pubKeys.map(function (p) {
|
||||
return new Buffer(p, 'hex')
|
||||
})
|
||||
|
||||
it('throws on ' + f.exception, function () {
|
||||
assert.throws(function () {
|
||||
bscript.multisigOutput(f.m, pubKeys)
|
||||
bscript.multisig.output.encode(f.m, pubKeys)
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('scriptHashInput', function () {
|
||||
describe('scriptHash.input.encode', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'scripthash') return
|
||||
|
||||
|
@ -356,7 +360,7 @@ describe('script', function () {
|
|||
var redeemScriptSig = bscript.fromASM(f.redeemScriptSig)
|
||||
|
||||
it('returns ' + f.scriptSig, function () {
|
||||
var scriptSig = bscript.scriptHashInput(redeemScriptSig, redeemScript)
|
||||
var scriptSig = bscript.scriptHash.input.encode(redeemScriptSig, redeemScript)
|
||||
|
||||
if (f.scriptSig) {
|
||||
assert.strictEqual(bscript.toASM(scriptSig), f.scriptSig)
|
||||
|
@ -367,31 +371,32 @@ describe('script', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('scriptHashOutput', function () {
|
||||
describe('scriptHash.output.encode', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'scripthash') return
|
||||
if (!f.scriptPubKey) return
|
||||
|
||||
it('returns ' + f.scriptPubKey, function () {
|
||||
var redeemScript = bscript.fromASM(f.redeemScript)
|
||||
var scriptPubKey = bscript.scriptHashOutput(bcrypto.hash160(redeemScript))
|
||||
var scriptPubKey = bscript.scriptHash.output.encode(bcrypto.hash160(redeemScript))
|
||||
|
||||
assert.strictEqual(bscript.toASM(scriptPubKey), f.scriptPubKey)
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.invalid.scriptHashOutput.forEach(function (f) {
|
||||
fixtures.invalid.scriptHash.outputs.forEach(function (f) {
|
||||
if (!f.hash) return
|
||||
var hash = new Buffer(f.hash, 'hex')
|
||||
|
||||
it('throws on ' + f.exception, function () {
|
||||
assert.throws(function () {
|
||||
bscript.scriptHashOutput(hash)
|
||||
bscript.scriptHash.output.encode(hash)
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('witnessPubKeyHashOutput', function () {
|
||||
describe('witnessPubKeyHash.output.encode', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'witnesspubkeyhash') return
|
||||
if (!f.scriptPubKey) return
|
||||
|
@ -400,23 +405,24 @@ describe('script', function () {
|
|||
var pubKeyHash = bcrypto.hash160(pubKey)
|
||||
|
||||
it('returns ' + f.scriptPubKey, function () {
|
||||
var scriptPubKey = bscript.witnessPubKeyHashOutput(pubKeyHash)
|
||||
var scriptPubKey = bscript.witnessPubKeyHash.output.encode(pubKeyHash)
|
||||
assert.strictEqual(bscript.toASM(scriptPubKey), f.scriptPubKey)
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.invalid.witnessPubKeyHashOutput.forEach(function (f) {
|
||||
fixtures.invalid.witnessPubKeyHash.outputs.forEach(function (f) {
|
||||
if (!f.hash) return
|
||||
var hash = new Buffer(f.hash, 'hex')
|
||||
|
||||
it('throws on ' + f.exception, function () {
|
||||
assert.throws(function () {
|
||||
bscript.witnessPubKeyHashOutput(hash)
|
||||
bscript.witnessPubKeyHash.output.encode(hash)
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('witnessScriptHashInput', function () {
|
||||
describe('witnessScriptHash.inputs.encode', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'witnessscripthash') return
|
||||
|
||||
|
@ -424,43 +430,44 @@ describe('script', function () {
|
|||
var witnessScriptSig = bscript.fromASM(f.witnessScriptSig)
|
||||
|
||||
it('returns ' + f.witness, function () {
|
||||
var witness = bscript.witnessScriptHashInput(witnessScriptSig, witnessScript)
|
||||
var witness = bscript.witnessScriptHash.input.encode(witnessScriptSig, witnessScript)
|
||||
|
||||
assert.strictEqual(bscript.toASM(witness), f.witness)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('witnessScriptHashOutput', function () {
|
||||
describe('witnessScriptHash.outputs.encode', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'witnessscripthash') return
|
||||
if (!f.scriptPubKey) return
|
||||
|
||||
it('returns ' + f.scriptPubKey, function () {
|
||||
var witnessScriptPubKey = bscript.fromASM(f.witnessScriptPubKey)
|
||||
var scriptPubKey = bscript.witnessScriptHashOutput(bcrypto.hash256(witnessScriptPubKey))
|
||||
var scriptPubKey = bscript.witnessScriptHash.output.encode(bcrypto.hash256(witnessScriptPubKey))
|
||||
|
||||
assert.strictEqual(bscript.toASM(scriptPubKey), f.scriptPubKey)
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.invalid.witnessScriptHashOutput.forEach(function (f) {
|
||||
fixtures.invalid.witnessScriptHash.outputs.forEach(function (f) {
|
||||
if (!f.hash) return
|
||||
var hash = new Buffer(f.hash, 'hex')
|
||||
|
||||
it('throws on ' + f.exception, function () {
|
||||
assert.throws(function () {
|
||||
bscript.witnessScriptHashOutput(hash)
|
||||
bscript.witnessScriptHash.output.encode(hash)
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('nullDataOutput', function () {
|
||||
describe('nullData.output.encode', function () {
|
||||
fixtures.valid.forEach(function (f) {
|
||||
if (f.type !== 'nulldata') return
|
||||
|
||||
var data = new Buffer(f.data, 'hex')
|
||||
var scriptPubKey = bscript.nullDataOutput(data)
|
||||
var scriptPubKey = bscript.nullData.output.encode(data)
|
||||
|
||||
it('returns ' + f.scriptPubKey, function () {
|
||||
assert.strictEqual(bscript.toASM(scriptPubKey), f.scriptPubKey)
|
||||
|
|
|
@ -357,7 +357,7 @@ describe('TransactionBuilder', function () {
|
|||
var signatures = bscript.decompile(scriptSig).slice(1, -1).filter(function (x) { return x !== ops.OP_0 })
|
||||
|
||||
// rebuild/replace the scriptSig without them
|
||||
var replacement = bscript.scriptHashInput(bscript.multisigInput(signatures), redeemScript)
|
||||
var replacement = bscript.scriptHash.input.encode(bscript.multisig.input.encode(signatures), redeemScript)
|
||||
assert.strictEqual(bscript.toASM(replacement), sign.scriptSigFiltered)
|
||||
|
||||
tx.ins[i].script = replacement
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue