add payments p2ms, p2pk, p2pkh, p2sh, p2wpkh, p2wsh
This commit is contained in:
parent
7756c5dd76
commit
f9a739e1db
18 changed files with 2696 additions and 2 deletions
378
test/fixtures/p2ms.json
vendored
Normal file
378
test/fixtures/p2ms.json
vendored
Normal file
|
@ -0,0 +1,378 @@
|
|||
{
|
||||
"valid": [
|
||||
{
|
||||
"description": "output from output",
|
||||
"arguments": {
|
||||
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG"
|
||||
},
|
||||
"expected": {
|
||||
"m": 2,
|
||||
"n": 2,
|
||||
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
|
||||
"pubkeys": [
|
||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000002"
|
||||
],
|
||||
"signatures": null,
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "output from m/pubkeys",
|
||||
"arguments": {
|
||||
"m": 1,
|
||||
"pubkeys": [
|
||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000002"
|
||||
]
|
||||
},
|
||||
"expected": {
|
||||
"m": 1,
|
||||
"n": 2,
|
||||
"output": "OP_1 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
|
||||
"pubkeys": [
|
||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000002"
|
||||
],
|
||||
"signatures": null,
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "input/output from m/pubkeys/signatures",
|
||||
"arguments": {
|
||||
"m": 2,
|
||||
"pubkeys": [
|
||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000002",
|
||||
"030000000000000000000000000000000000000000000000000000000000000003"
|
||||
],
|
||||
"signatures": [
|
||||
"300602010002010001",
|
||||
"300602010102010001"
|
||||
]
|
||||
},
|
||||
"expected": {
|
||||
"m": 2,
|
||||
"n": 3,
|
||||
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 OP_3 OP_CHECKMULTISIG",
|
||||
"pubkeys": [
|
||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000002",
|
||||
"030000000000000000000000000000000000000000000000000000000000000003"
|
||||
],
|
||||
"signatures": [
|
||||
"300602010002010001",
|
||||
"300602010102010001"
|
||||
],
|
||||
"input": "OP_0 300602010002010001 300602010102010001",
|
||||
"witness": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "input/output from output/signatures",
|
||||
"arguments": {
|
||||
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 OP_3 OP_CHECKMULTISIG",
|
||||
"signatures": [
|
||||
"300602010002010001",
|
||||
"300602010102010001"
|
||||
]
|
||||
},
|
||||
"expected": {
|
||||
"m": 2,
|
||||
"n": 3,
|
||||
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 OP_3 OP_CHECKMULTISIG",
|
||||
"pubkeys": [
|
||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000002",
|
||||
"030000000000000000000000000000000000000000000000000000000000000003"
|
||||
],
|
||||
"signatures": [
|
||||
"300602010002010001",
|
||||
"300602010102010001"
|
||||
],
|
||||
"input": "OP_0 300602010002010001 300602010102010001",
|
||||
"witness": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "input/output from input/output",
|
||||
"arguments": {
|
||||
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 OP_3 OP_CHECKMULTISIG",
|
||||
"input": "OP_0 300602010002010001 300602010102010001"
|
||||
},
|
||||
"expected": {
|
||||
"m": 2,
|
||||
"n": 3,
|
||||
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 OP_3 OP_CHECKMULTISIG",
|
||||
"pubkeys": [
|
||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000002",
|
||||
"030000000000000000000000000000000000000000000000000000000000000003"
|
||||
],
|
||||
"signatures": [
|
||||
"300602010002010001",
|
||||
"300602010102010001"
|
||||
],
|
||||
"input": "OP_0 300602010002010001 300602010102010001",
|
||||
"witness": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "input/output from input/output, even if incomplete",
|
||||
"arguments": {
|
||||
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
|
||||
"input": "OP_0 OP_0 300602010102010001"
|
||||
},
|
||||
"options": {
|
||||
"allowIncomplete": true
|
||||
},
|
||||
"expected": {
|
||||
"m": 2,
|
||||
"n": 2,
|
||||
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
|
||||
"pubkeys": [
|
||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000002"
|
||||
],
|
||||
"signatures": [
|
||||
0,
|
||||
"300602010102010001"
|
||||
],
|
||||
"input": "OP_0 OP_0 300602010102010001",
|
||||
"witness": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "input/output from output/signatures, even if incomplete",
|
||||
"arguments": {
|
||||
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
|
||||
"signatures": [
|
||||
0,
|
||||
"300602010102010001"
|
||||
]
|
||||
},
|
||||
"options": {
|
||||
"allowIncomplete": true
|
||||
},
|
||||
"expected": {
|
||||
"m": 2,
|
||||
"n": 2,
|
||||
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
|
||||
"pubkeys": [
|
||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000002"
|
||||
],
|
||||
"signatures": [
|
||||
0,
|
||||
"300602010102010001"
|
||||
],
|
||||
"input": "OP_0 OP_0 300602010102010001",
|
||||
"witness": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"invalid": [
|
||||
{
|
||||
"exception": "Not enough data",
|
||||
"arguments": {}
|
||||
},
|
||||
{
|
||||
"exception": "Not enough data",
|
||||
"arguments": {
|
||||
"m": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Not enough data",
|
||||
"arguments": {
|
||||
"pubkeys": [
|
||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000002"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Non OP_INT chunk (m)",
|
||||
"exception": "Output is invalid",
|
||||
"arguments": {
|
||||
"output": "OP_RESERVED"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Non OP_INT chunk (n)",
|
||||
"exception": "Output is invalid",
|
||||
"arguments": {
|
||||
"output": "OP_1 OP_RESERVED"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Missing OP_CHECKMULTISIG",
|
||||
"exception": "Output is invalid",
|
||||
"arguments": {
|
||||
"output": "OP_1 OP_2 OP_RESERVED"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "m is 0",
|
||||
"exception": "Output is invalid",
|
||||
"arguments": {
|
||||
"output": "OP_0 OP_2 OP_CHECKMULTISIG"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "n is 0 (m > n)",
|
||||
"exception": "Output is invalid",
|
||||
"arguments": {
|
||||
"output": "OP_2 OP_0 OP_CHECKMULTISIG"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "m > n",
|
||||
"exception": "Output is invalid",
|
||||
"arguments": {
|
||||
"output": "OP_3 OP_2 OP_CHECKMULTISIG"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "n !== output pubkeys",
|
||||
"exception": "Output is invalid",
|
||||
"arguments": {
|
||||
"output": "OP_1 030000000000000000000000000000000000000000000000000000000000000001 OP_2 OP_CHECKMULTISIG"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Non-canonical output public key",
|
||||
"exception": "Output is invalid",
|
||||
"arguments": {
|
||||
"output": "OP_1 ffff OP_1 OP_CHECKMULTISIG"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "n mismatch",
|
||||
"arguments": {
|
||||
"n": 2,
|
||||
"output": "OP_1 030000000000000000000000000000000000000000000000000000000000000001 OP_1 OP_CHECKMULTISIG"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "m mismatch",
|
||||
"arguments": {
|
||||
"m": 2,
|
||||
"output": "OP_1 030000000000000000000000000000000000000000000000000000000000000001 OP_1 OP_CHECKMULTISIG"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Pubkeys mismatch",
|
||||
"arguments": {
|
||||
"pubkeys": [
|
||||
"030000000000000000000000000000000000000000000000000000000000000001"
|
||||
],
|
||||
"output": "OP_1 030000000000000000000000000000000000000000000000000000000000000002 OP_1 OP_CHECKMULTISIG"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Pubkey count mismatch",
|
||||
"arguments": {
|
||||
"m": 2,
|
||||
"n": 3,
|
||||
"pubkeys": [
|
||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000002"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Pubkey count cannot be less than m",
|
||||
"arguments": {
|
||||
"m": 4,
|
||||
"pubkeys": [
|
||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000001"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Not enough signatures provided",
|
||||
"arguments": {
|
||||
"m": 2,
|
||||
"pubkeys": [
|
||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000001"
|
||||
],
|
||||
"signatures": [
|
||||
"300602010002010001"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Too many signatures provided",
|
||||
"arguments": {
|
||||
"m": 2,
|
||||
"pubkeys": [
|
||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000001"
|
||||
],
|
||||
"signatures": [
|
||||
"300602010002010001",
|
||||
"300602010002010001",
|
||||
"300602010002010001"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Missing OP_0",
|
||||
"exception": "Input is invalid",
|
||||
"arguments": {
|
||||
"m": 2,
|
||||
"pubkeys": [
|
||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000001"
|
||||
],
|
||||
"input": "OP_RESERVED"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Input has invalid signature\\(s\\)",
|
||||
"arguments": {
|
||||
"m": 1,
|
||||
"pubkeys": [
|
||||
"030000000000000000000000000000000000000000000000000000000000000001"
|
||||
],
|
||||
"input": "OP_0 ffffffffffffffff"
|
||||
}
|
||||
}
|
||||
],
|
||||
"dynamic": {
|
||||
"depends": {
|
||||
"m": [ "output" ],
|
||||
"n": [ "output", [ "m", "pubkeys" ] ],
|
||||
"output": [ "output", [ "m", "pubkeys" ] ],
|
||||
"pubkeys": [ "output" ],
|
||||
"signatures": [ ["input", "output"] ],
|
||||
"input": [ ["signatures", "output"] ],
|
||||
"witness": [ ["input", "output"] ]
|
||||
},
|
||||
"details": [
|
||||
{
|
||||
"description": "p2ms",
|
||||
"m": 2,
|
||||
"n": 3,
|
||||
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 OP_3 OP_CHECKMULTISIG",
|
||||
"pubkeys": [
|
||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000002",
|
||||
"030000000000000000000000000000000000000000000000000000000000000003"
|
||||
],
|
||||
"signatures": [
|
||||
"300602010002010001",
|
||||
"300602010102010001"
|
||||
],
|
||||
"input": "OP_0 300602010002010001 300602010102010001",
|
||||
"witness": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
152
test/fixtures/p2pk.json
vendored
Normal file
152
test/fixtures/p2pk.json
vendored
Normal file
|
@ -0,0 +1,152 @@
|
|||
{
|
||||
"valid": [
|
||||
{
|
||||
"description": "output from output",
|
||||
"arguments": {
|
||||
"output": "030000000000000000000000000000000000000000000000000000000000000001 OP_CHECKSIG"
|
||||
},
|
||||
"expected": {
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"signatures": null,
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "output from pubkey",
|
||||
"arguments": {
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001"
|
||||
},
|
||||
"expected": {
|
||||
"output": "030000000000000000000000000000000000000000000000000000000000000001 OP_CHECKSIG",
|
||||
"signatures": null,
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "input/output from output/signature",
|
||||
"arguments": {
|
||||
"output": "030000000000000000000000000000000000000000000000000000000000000001 OP_CHECKSIG",
|
||||
"signature": "300602010002010001"
|
||||
},
|
||||
"expected": {
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"input": "300602010002010001",
|
||||
"witness": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "input/output from pubkey/signature",
|
||||
"arguments": {
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"signature": "300602010002010001"
|
||||
},
|
||||
"expected": {
|
||||
"output": "030000000000000000000000000000000000000000000000000000000000000001 OP_CHECKSIG",
|
||||
"input": "300602010002010001",
|
||||
"witness": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "input/output from input/output",
|
||||
"arguments": {
|
||||
"output": "030000000000000000000000000000000000000000000000000000000000000001 OP_CHECKSIG",
|
||||
"input": "300602010002010001"
|
||||
},
|
||||
"expected": {
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"signature": "300602010002010001",
|
||||
"witness": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"invalid": [
|
||||
{
|
||||
"exception": "Not enough data",
|
||||
"arguments": {}
|
||||
},
|
||||
{
|
||||
"exception": "Not enough data",
|
||||
"arguments": {
|
||||
"input": "300602010002010001"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Not enough data",
|
||||
"arguments": {
|
||||
"signature": "300602010002010001"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Non-canonical signature",
|
||||
"exception": "Expected property \"signature\" of type \\?isCanonicalScriptSignature, got Buffer",
|
||||
"arguments": {
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"signature": "3044"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Unexpected OP_RESERVED",
|
||||
"exception": "Output is invalid",
|
||||
"arguments": {
|
||||
"output": "OP_RESERVED"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Non-canonical output public key",
|
||||
"exception": "Output pubkey is invalid",
|
||||
"arguments": {
|
||||
"output": "ffff OP_CHECKSIG"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Unexpected OP_0 (at end)",
|
||||
"exception": "Output is invalid",
|
||||
"arguments": {
|
||||
"output": "030000000000000000000000000000000000000000000000000000000000000001 OP_CHECKSIG OP_0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Pubkey mismatch",
|
||||
"arguments": {
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"output": "030000000000000000000000000000000000000000000000000000000000000002 OP_CHECKSIG"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Too many chunks",
|
||||
"exception": "Input is invalid",
|
||||
"arguments": {
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"input": "300602010002010001 OP_RESERVED"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Input has invalid signature",
|
||||
"arguments": {
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"input": "ffffffffffffffff"
|
||||
}
|
||||
}
|
||||
],
|
||||
"dynamic": {
|
||||
"depends": {
|
||||
"output": [ "pubkey" ],
|
||||
"pubkey": [ "output" ],
|
||||
"signature": [ ["input", "output"] ],
|
||||
"input": [ ["signature", "output"] ],
|
||||
"witness": [ ["input", "output"] ]
|
||||
},
|
||||
"details": [
|
||||
{
|
||||
"description": "p2pk",
|
||||
"output": "030000000000000000000000000000000000000000000000000000000000000001 OP_CHECKSIG",
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"signature": "300602010002010001",
|
||||
"input": "300602010002010001",
|
||||
"witness": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
214
test/fixtures/p2pkh.json
vendored
Normal file
214
test/fixtures/p2pkh.json
vendored
Normal file
|
@ -0,0 +1,214 @@
|
|||
{
|
||||
"valid": [
|
||||
{
|
||||
"description": "output from address",
|
||||
"arguments": {
|
||||
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh"
|
||||
},
|
||||
"expected": {
|
||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
|
||||
"signature": null,
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "output from hash",
|
||||
"arguments": {
|
||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1"
|
||||
},
|
||||
"expected": {
|
||||
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
|
||||
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
|
||||
"signature": null,
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "output from output",
|
||||
"arguments": {
|
||||
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG"
|
||||
},
|
||||
"expected": {
|
||||
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
|
||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||
"signature": null,
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "output from pubkey",
|
||||
"arguments": {
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001"
|
||||
},
|
||||
"expected": {
|
||||
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
|
||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
|
||||
"signature": null,
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "input/output from pubkey/signature",
|
||||
"arguments": {
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"signature": "300602010002010001"
|
||||
},
|
||||
"expected": {
|
||||
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
|
||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
|
||||
"input": "300602010002010001 030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"witness": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "input/output from input",
|
||||
"arguments": {
|
||||
"input": "300602010002010001 030000000000000000000000000000000000000000000000000000000000000001"
|
||||
},
|
||||
"expected": {
|
||||
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
|
||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"signature": "300602010002010001",
|
||||
"witness": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"invalid": [
|
||||
{
|
||||
"exception": "Not enough data",
|
||||
"arguments": {}
|
||||
},
|
||||
{
|
||||
"exception": "Not enough data",
|
||||
"arguments": {
|
||||
"signature": "300602010002010001"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Unexpected OP_RESERVED",
|
||||
"exception": "Output is invalid",
|
||||
"arguments": {
|
||||
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_RESERVED"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Unexpected OP_DUP",
|
||||
"exception": "Output is invalid",
|
||||
"arguments": {
|
||||
"output": "OP_DUP OP_DUP 168b992bcfc44050310b3a94bd0771136d0b28d137 OP_EQUALVERIFY"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Hash too short (too many chunks)",
|
||||
"exception": "Output is invalid",
|
||||
"arguments": {
|
||||
"output": "OP_DUP OP_DUP 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_TRUE OP_EQUALVERIFY"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Non-minimally encoded (non BIP62 compliant)",
|
||||
"exception": "Expected property \"output\" of type Buffer\\(Length: 25\\), got Buffer\\(Length: 26\\)",
|
||||
"arguments": {
|
||||
"outputHex": "76a94c14aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Pubkey mismatch",
|
||||
"arguments": {
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"input": "300602010002010001 030000000000000000000000000000000000000000000000000000000000000002"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Input has invalid signature",
|
||||
"arguments": {
|
||||
"input": "ffffffffffffffffff 030000000000000000000000000000000000000000000000000000000000000001"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Input has invalid pubkey",
|
||||
"arguments": {
|
||||
"input": "300602010002010001 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Input has unexpected data",
|
||||
"exception": "Input is invalid",
|
||||
"arguments": {
|
||||
"input": "300602010002010001 030000000000000000000000000000000000000000000000000000000000000001 ffff"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "H(pubkey) != H",
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"hash": "ffffffffffffffffffffffffffffffffffffffff"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "address.hash != H",
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
|
||||
"hash": "ffffffffffffffffffffffffffffffffffffffff"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "address.hash != output.hash",
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
|
||||
"output": "OP_DUP OP_HASH160 ffffffffffffffffffffffffffffffffffffffff OP_EQUALVERIFY OP_CHECKSIG"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "output.hash != H",
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
|
||||
"hash": "ffffffffffffffffffffffffffffffffffffffff"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "H(input.pubkey) != H",
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
"hash": "ffffffffffffffffffffffffffffffffffffffff",
|
||||
"input": "300602010002010001 030000000000000000000000000000000000000000000000000000000000000001"
|
||||
}
|
||||
}
|
||||
],
|
||||
"dynamic": {
|
||||
"depends": {
|
||||
"address": [ "address", "output", "hash", "pubkey", "input" ],
|
||||
"hash": [ "address", "output", "hash", "pubkey", "input" ],
|
||||
"output": [ "address", "output", "hash", "pubkey", "input" ],
|
||||
"pubkey": [ "input" ],
|
||||
"signature": [ "input" ],
|
||||
"input": [ [ "pubkey", "signature" ] ],
|
||||
"witness": [ "input" ]
|
||||
},
|
||||
"details": [
|
||||
{
|
||||
"description": "p2pkh",
|
||||
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
|
||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"signature": "300602010002010001",
|
||||
"input": "300602010002010001 030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"witness": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
346
test/fixtures/p2sh.json
vendored
Normal file
346
test/fixtures/p2sh.json
vendored
Normal file
|
@ -0,0 +1,346 @@
|
|||
{
|
||||
"valid": [
|
||||
{
|
||||
"description": "p2sh-*, out (from address)",
|
||||
"arguments": {
|
||||
"address": "3GETYP4cuSesh2zsPEEYVZqnRedwe4FwUT"
|
||||
},
|
||||
"expected": {
|
||||
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
|
||||
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",
|
||||
"redeem": null,
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "p2sh-*, out (from hash)",
|
||||
"arguments": {
|
||||
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086"
|
||||
},
|
||||
"expected": {
|
||||
"address": "3GETYP4cuSesh2zsPEEYVZqnRedwe4FwUT",
|
||||
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",
|
||||
"redeem": null,
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "p2sh-*, out (from output)",
|
||||
"arguments": {
|
||||
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL"
|
||||
},
|
||||
"expected": {
|
||||
"address": "3GETYP4cuSesh2zsPEEYVZqnRedwe4FwUT",
|
||||
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
|
||||
"redeem": null,
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "p2sh-p2pkh, out (from redeem)",
|
||||
"arguments": {
|
||||
"redeem": {
|
||||
"address": "this is P2PKH context, unknown and ignored by P2SH",
|
||||
"output": "OP_DUP OP_HASH160 c30afa58ae0673b00a45b5c17dff4633780f1400 OP_EQUALVERIFY OP_CHECKSIG"
|
||||
}
|
||||
},
|
||||
"expected": {
|
||||
"address": "3GETYP4cuSesh2zsPEEYVZqnRedwe4FwUT",
|
||||
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
|
||||
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "p2sh-p2wpkh, out (from redeem)",
|
||||
"arguments": {
|
||||
"redeem": {
|
||||
"hash": "this is P2WPKH context, unknown and ignored by P2SH",
|
||||
"output": "OP_0 c30afa58ae0673b00a45b5c17dff4633780f1400"
|
||||
}
|
||||
},
|
||||
"expected": {
|
||||
"address": "325CuTNSYmvurXaBmhNFer5zDkKnDXZggu",
|
||||
"hash": "0432515d8fe8de31be8207987fc6d67b29d5e7cc",
|
||||
"output": "OP_HASH160 0432515d8fe8de31be8207987fc6d67b29d5e7cc OP_EQUAL",
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "p2sh-p2pk, out (from redeem)",
|
||||
"arguments": {
|
||||
"redeem": {
|
||||
"output": "03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058 OP_CHECKSIG",
|
||||
"pubkey": "this is P2WPKH context, unknown and ignored by P2SH"
|
||||
}
|
||||
},
|
||||
"expected": {
|
||||
"address": "36TibC8RrPB9WrBdPoGXhHqDHJosyFVtVQ",
|
||||
"hash": "3454c084887afe854e80221c69d6282926f809c4",
|
||||
"output": "OP_HASH160 3454c084887afe854e80221c69d6282926f809c4 OP_EQUAL",
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "p2sh-p2pkh, in and out (from redeem)",
|
||||
"arguments": {
|
||||
"redeem": {
|
||||
"output": "OP_DUP OP_HASH160 c30afa58ae0673b00a45b5c17dff4633780f1400 OP_EQUALVERIFY OP_CHECKSIG",
|
||||
"input": "3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501 03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058"
|
||||
}
|
||||
},
|
||||
"expected": {
|
||||
"address": "3GETYP4cuSesh2zsPEEYVZqnRedwe4FwUT",
|
||||
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
|
||||
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",
|
||||
"input": "3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501 03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058 76a914c30afa58ae0673b00a45b5c17dff4633780f140088ac",
|
||||
"witness": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "p2sh-p2wpkh, in and out (from redeem w/ witness)",
|
||||
"arguments": {
|
||||
"redeem": {
|
||||
"output": "OP_0 c30afa58ae0673b00a45b5c17dff4633780f1400",
|
||||
"input": "",
|
||||
"witness": [
|
||||
"3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501",
|
||||
"03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058"
|
||||
]
|
||||
}
|
||||
},
|
||||
"expected": {
|
||||
"address": "325CuTNSYmvurXaBmhNFer5zDkKnDXZggu",
|
||||
"hash": "0432515d8fe8de31be8207987fc6d67b29d5e7cc",
|
||||
"output": "OP_HASH160 0432515d8fe8de31be8207987fc6d67b29d5e7cc OP_EQUAL",
|
||||
"input": "0014c30afa58ae0673b00a45b5c17dff4633780f1400",
|
||||
"witness": [
|
||||
"3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501",
|
||||
"03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "p2sh-p2pk, in and out (from input)",
|
||||
"arguments": {
|
||||
"input": "3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501 2103e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058ac"
|
||||
},
|
||||
"expected": {
|
||||
"address": "36TibC8RrPB9WrBdPoGXhHqDHJosyFVtVQ",
|
||||
"hash": "3454c084887afe854e80221c69d6282926f809c4",
|
||||
"output": "OP_HASH160 3454c084887afe854e80221c69d6282926f809c4 OP_EQUAL",
|
||||
"redeem": {
|
||||
"output": "03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058 OP_CHECKSIG",
|
||||
"input": "3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501",
|
||||
"witness": []
|
||||
},
|
||||
"witness": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "p2sh-p2wpkh, in and out (from input AND witness)",
|
||||
"arguments": {
|
||||
"input": "0014c30afa58ae0673b00a45b5c17dff4633780f1400",
|
||||
"witness": [
|
||||
"3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501",
|
||||
"03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058"
|
||||
]
|
||||
},
|
||||
"expected": {
|
||||
"address": "325CuTNSYmvurXaBmhNFer5zDkKnDXZggu",
|
||||
"hash": "0432515d8fe8de31be8207987fc6d67b29d5e7cc",
|
||||
"output": "OP_HASH160 0432515d8fe8de31be8207987fc6d67b29d5e7cc OP_EQUAL",
|
||||
"redeem": {
|
||||
"output": "OP_0 c30afa58ae0673b00a45b5c17dff4633780f1400",
|
||||
"input": "",
|
||||
"witness": [
|
||||
"3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501",
|
||||
"03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"invalid": [
|
||||
{
|
||||
"exception": "Not enough data",
|
||||
"arguments": {}
|
||||
},
|
||||
{
|
||||
"description": "Non-minimally encoded (non BIP62 compliant)",
|
||||
"exception": "Expected property \"output\" of type Buffer\\(Length: 23\\), got Buffer\\(Length: 24\\)",
|
||||
"arguments": {
|
||||
"outputHex": "a94c14c286a1af0947f58d1ad787385b1c2c4a976f9e7187"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Expected OP_HASH160",
|
||||
"exception": "Output is invalid",
|
||||
"arguments": {
|
||||
"output": "OP_HASH256 ffffffffffffffffffffffffffffffffffffffff OP_EQUAL"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "Unexpected OP_RESERVED",
|
||||
"exception": "Output is invalid",
|
||||
"arguments": {
|
||||
"output": "OP_HASH256 ffffffffffffffffffffffffffffffffffffff OP_EQUAL OP_RESERVED"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "address.hash != H",
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
"address": "325CuTNSYmvurXaBmhNFer5zDkKnDXZggu",
|
||||
"hash": "ffffffffffffffffffffffffffffffffffffffff"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "address.hash != output.hash",
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
"address": "325CuTNSYmvurXaBmhNFer5zDkKnDXZggu",
|
||||
"output": "OP_HASH160 ffffffffffffffffffffffffffffffffffffffff OP_EQUAL"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "output.hash != H",
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
"hash": "ffffffffffffffffffffffffffffffffffffffff",
|
||||
"output": "OP_HASH160 0432515d8fe8de31be8207987fc6d67b29d5e7cc OP_EQUAL"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "H(redeem.output) != H",
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
"hash": "ffffffffffffffffffffffffffffffffffffffff",
|
||||
"redeem": {
|
||||
"output": "03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058 OP_CHECKSIG"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Input too short",
|
||||
"arguments": {
|
||||
"input": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Input too short",
|
||||
"arguments": {
|
||||
"inputHex": "01ff02ff"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Input is invalid",
|
||||
"arguments": {
|
||||
"input": "OP_0 OP_0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Redeem.input mismatch",
|
||||
"arguments": {
|
||||
"input": "OP_0 02ffff",
|
||||
"redeem": {
|
||||
"input": "OP_CHECKSIG",
|
||||
"output": "ffff"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Redeem.output mismatch",
|
||||
"arguments": {
|
||||
"input": "OP_0 02ffff",
|
||||
"redeem": {
|
||||
"input": "OP_0",
|
||||
"output": "fff3"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Redeem.output too short",
|
||||
"arguments": {
|
||||
"redeem": {
|
||||
"input": "OP_0",
|
||||
"output": ""
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Redeem.output too short",
|
||||
"arguments": {
|
||||
"inputHex": "021000"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
"hash": "ffffffffffffffffffffffffffffffffffffffff",
|
||||
"redeem": {
|
||||
"input": "OP_0",
|
||||
"output": "ffff"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Empty input",
|
||||
"arguments": {
|
||||
"inputHex": "01ff"
|
||||
}
|
||||
}
|
||||
],
|
||||
"dynamic": {
|
||||
"depends": {
|
||||
"address": [ "address", "output", "hash", "redeem.output", [ "input", "witness" ] ],
|
||||
"hash": [ "address", "output", "hash", "redeem.output", [ "input", "witness" ] ],
|
||||
"output": [ "address", "output", "hash", "redeem.output", [ "input", "witness" ] ],
|
||||
"redeem.output": [ [ "input", "witness" ] ],
|
||||
"redeem.input": [ [ "input", "witness" ] ],
|
||||
"redeem.witness": [ [ "input", "witness" ] ],
|
||||
"input": [ "redeem" ],
|
||||
"witness": [ "redeem" ]
|
||||
},
|
||||
"details": [
|
||||
{
|
||||
"description": "p2sh-p2pkh",
|
||||
"address": "3GETYP4cuSesh2zsPEEYVZqnRedwe4FwUT",
|
||||
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
|
||||
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",
|
||||
"redeem": {
|
||||
"output": "OP_DUP OP_HASH160 c30afa58ae0673b00a45b5c17dff4633780f1400 OP_EQUALVERIFY OP_CHECKSIG",
|
||||
"input": "3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501 03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058",
|
||||
"witness": []
|
||||
},
|
||||
"input": "3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501 03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058 76a914c30afa58ae0673b00a45b5c17dff4633780f140088ac",
|
||||
"witness": []
|
||||
},
|
||||
{
|
||||
"description": "p2sh-p2wpkh",
|
||||
"address": "325CuTNSYmvurXaBmhNFer5zDkKnDXZggu",
|
||||
"hash": "0432515d8fe8de31be8207987fc6d67b29d5e7cc",
|
||||
"output": "OP_HASH160 0432515d8fe8de31be8207987fc6d67b29d5e7cc OP_EQUAL",
|
||||
"redeem": {
|
||||
"output": "OP_0 c30afa58ae0673b00a45b5c17dff4633780f1400",
|
||||
"input": "",
|
||||
"witness": [
|
||||
"3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501",
|
||||
"03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058"
|
||||
]
|
||||
},
|
||||
"input": "0014c30afa58ae0673b00a45b5c17dff4633780f1400",
|
||||
"witness": [
|
||||
"3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501",
|
||||
"03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
195
test/fixtures/p2wpkh.json
vendored
Normal file
195
test/fixtures/p2wpkh.json
vendored
Normal file
|
@ -0,0 +1,195 @@
|
|||
{
|
||||
"valid": [
|
||||
{
|
||||
"description": "output from address",
|
||||
"arguments": {
|
||||
"address": "bc1qafk4yhqvj4wep57m62dgrmutldusqde8adh20d"
|
||||
},
|
||||
"expected": {
|
||||
"hash": "ea6d525c0c955d90d3dbd29a81ef8bfb79003727",
|
||||
"output": "OP_0 ea6d525c0c955d90d3dbd29a81ef8bfb79003727",
|
||||
"signature": null,
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "output from hash",
|
||||
"arguments": {
|
||||
"hash": "ea6d525c0c955d90d3dbd29a81ef8bfb79003727"
|
||||
},
|
||||
"expected": {
|
||||
"address": "bc1qafk4yhqvj4wep57m62dgrmutldusqde8adh20d",
|
||||
"output": "OP_0 ea6d525c0c955d90d3dbd29a81ef8bfb79003727",
|
||||
"signature": null,
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "output from output",
|
||||
"arguments": {
|
||||
"output": "OP_0 ea6d525c0c955d90d3dbd29a81ef8bfb79003727"
|
||||
},
|
||||
"expected": {
|
||||
"address": "bc1qafk4yhqvj4wep57m62dgrmutldusqde8adh20d",
|
||||
"hash": "ea6d525c0c955d90d3dbd29a81ef8bfb79003727",
|
||||
"signature": null,
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "output from pubkey",
|
||||
"arguments": {
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001"
|
||||
},
|
||||
"expected": {
|
||||
"address": "bc1qz69ej270c3q9qvgt822t6pm3zdksk2x35j2jlm",
|
||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||
"output": "OP_0 168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||
"signature": null,
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "witness/output from pubkey/signature",
|
||||
"arguments": {
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"signature": "300602010002010001"
|
||||
},
|
||||
"expected": {
|
||||
"address": "bc1qz69ej270c3q9qvgt822t6pm3zdksk2x35j2jlm",
|
||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||
"output": "OP_0 168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||
"input": "",
|
||||
"witness": [
|
||||
"300602010002010001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000001"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "witness/output from witness",
|
||||
"arguments": {
|
||||
"witness": [
|
||||
"300602010002010001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000001"
|
||||
]
|
||||
},
|
||||
"expected": {
|
||||
"address": "bc1qz69ej270c3q9qvgt822t6pm3zdksk2x35j2jlm",
|
||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||
"output": "OP_0 168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"signature": "300602010002010001",
|
||||
"input": ""
|
||||
}
|
||||
}
|
||||
],
|
||||
"invalid": [
|
||||
{
|
||||
"exception": "Not enough data",
|
||||
"arguments": {}
|
||||
},
|
||||
{
|
||||
"exception": "Not enough data",
|
||||
"arguments": {
|
||||
"signature": "300602010002010001"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Output is invalid",
|
||||
"description": "Unexpected OP",
|
||||
"arguments": {
|
||||
"output": "OP_RESERVED ea6d525c0c955d90d3dbd29a81ef8bfb79003727"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Pubkey mismatch",
|
||||
"arguments": {
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"witness": [
|
||||
"300602010002010001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000002"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"hash": "ffffffffffffffffffffffffffffffffffffffff"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
"address": "bc1qafk4yhqvj4wep57m62dgrmutldusqde8adh20d",
|
||||
"hash": "ffffffffffffffffffffffffffffffffffffffff"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
"output": "OP_0 ea6d525c0c955d90d3dbd29a81ef8bfb79003727",
|
||||
"hash": "ffffffffffffffffffffffffffffffffffffffff"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
"hash": "ffffffffffffffffffffffffffffffffffffffff",
|
||||
"witness": [
|
||||
"300602010002010001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000001"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Input has invalid signature",
|
||||
"arguments": {
|
||||
"witness": [
|
||||
"ffffffffffffffffff",
|
||||
"030000000000000000000000000000000000000000000000000000000000000001"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Input has invalid pubkey",
|
||||
"arguments": {
|
||||
"witness": [
|
||||
"300602010002010001",
|
||||
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"dynamic": {
|
||||
"depends": {
|
||||
"address": [ "address", "output", "hash", "pubkey", "witness" ],
|
||||
"hash": [ "address", "output", "hash", "pubkey", "witness" ],
|
||||
"output": [ "address", "output", "hash", "pubkey", "witness" ],
|
||||
"pubkey": [ "witness" ],
|
||||
"signature": [ "witness" ],
|
||||
"input": [ "witness" ],
|
||||
"witness": [ [ "pubkey", "signature" ] ]
|
||||
},
|
||||
"details": [
|
||||
{
|
||||
"description": "p2wpkh",
|
||||
"address": "bc1qz69ej270c3q9qvgt822t6pm3zdksk2x35j2jlm",
|
||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||
"output": "OP_0 168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||
"signature": "300602010002010001",
|
||||
"input": "",
|
||||
"witness": [
|
||||
"300602010002010001",
|
||||
"030000000000000000000000000000000000000000000000000000000000000001"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
326
test/fixtures/p2wsh.json
vendored
Normal file
326
test/fixtures/p2wsh.json
vendored
Normal file
|
@ -0,0 +1,326 @@
|
|||
{
|
||||
"valid": [
|
||||
{
|
||||
"description": "p2wsh-*, out (from address)",
|
||||
"arguments": {
|
||||
"address": "bc1q6rgl33d3s9dugudw7n68yrryajkr3ha9q8q24j20zs62se4q9tsqdy0t2q"
|
||||
},
|
||||
"expected": {
|
||||
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
||||
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
||||
"redeem": null,
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "p2wsh-*, out (from hash)",
|
||||
"arguments": {
|
||||
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0"
|
||||
},
|
||||
"expected": {
|
||||
"address": "bc1q6rgl33d3s9dugudw7n68yrryajkr3ha9q8q24j20zs62se4q9tsqdy0t2q",
|
||||
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
||||
"redeem": null,
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "p2wsh-*, out (from output)",
|
||||
"arguments": {
|
||||
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0"
|
||||
},
|
||||
"expected": {
|
||||
"address": "bc1q6rgl33d3s9dugudw7n68yrryajkr3ha9q8q24j20zs62se4q9tsqdy0t2q",
|
||||
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
||||
"redeem": null,
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "p2wsh-p2pkh, out (from redeem)",
|
||||
"arguments": {
|
||||
"redeem": {
|
||||
"address": "this is P2PKH context, unknown and ignored by p2wsh",
|
||||
"output": "OP_DUP OP_HASH160 c30afa58ae0673b00a45b5c17dff4633780f1400 OP_EQUALVERIFY OP_CHECKSIG"
|
||||
}
|
||||
},
|
||||
"expected": {
|
||||
"address": "bc1qusxlgq9quu27ucxs7a2fg8nv0pycdzvxsjk9npyupupxw3y892ss2cq5ar",
|
||||
"hash": "e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
|
||||
"output": "OP_0 e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "p2wsh-p2wpkh, out (from redeem)",
|
||||
"arguments": {
|
||||
"redeem": {
|
||||
"hash": "this is P2WPKH context, unknown and ignored by p2wsh",
|
||||
"output": "OP_0 c30afa58ae0673b00a45b5c17dff4633780f1400"
|
||||
}
|
||||
},
|
||||
"expected": {
|
||||
"address": "bc1qpsl7el8wcx22f3fpdt3lm2wmzug7yyx2q3n8wzgtf37kps9tqy7skc7m3e",
|
||||
"hash": "0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
||||
"output": "OP_0 0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "p2wsh-p2pk, out (from redeem)",
|
||||
"arguments": {
|
||||
"redeem": {
|
||||
"output": "03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058 OP_CHECKSIG",
|
||||
"pubkey": "this is P2WPKH context, unknown and ignored by p2wsh"
|
||||
}
|
||||
},
|
||||
"expected": {
|
||||
"address": "bc1q6rgl33d3s9dugudw7n68yrryajkr3ha9q8q24j20zs62se4q9tsqdy0t2q",
|
||||
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
||||
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
||||
"input": null,
|
||||
"witness": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "p2wsh-p2pkh, in and out (from redeem, transformed to witness)",
|
||||
"arguments": {
|
||||
"redeem": {
|
||||
"output": "OP_DUP OP_HASH160 c30afa58ae0673b00a45b5c17dff4633780f1400 OP_EQUALVERIFY OP_CHECKSIG",
|
||||
"input": "3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501 03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058"
|
||||
}
|
||||
},
|
||||
"expected": {
|
||||
"address": "bc1qusxlgq9quu27ucxs7a2fg8nv0pycdzvxsjk9npyupupxw3y892ss2cq5ar",
|
||||
"hash": "e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
|
||||
"output": "OP_0 e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
|
||||
"redeem": {
|
||||
"input": ""
|
||||
},
|
||||
"input": "",
|
||||
"witness": [
|
||||
"3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501",
|
||||
"03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058",
|
||||
"76a914c30afa58ae0673b00a45b5c17dff4633780f140088ac"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "p2wsh-p2wpkh, in and out (from redeem w/ witness)",
|
||||
"arguments": {
|
||||
"redeem": {
|
||||
"output": "OP_0 c30afa58ae0673b00a45b5c17dff4633780f1400",
|
||||
"input": "",
|
||||
"witness": [
|
||||
"3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501",
|
||||
"03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058"
|
||||
]
|
||||
}
|
||||
},
|
||||
"expected": {
|
||||
"address": "bc1qpsl7el8wcx22f3fpdt3lm2wmzug7yyx2q3n8wzgtf37kps9tqy7skc7m3e",
|
||||
"hash": "0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
||||
"output": "OP_0 0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
||||
"input": "",
|
||||
"witness": [
|
||||
"3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501",
|
||||
"03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058",
|
||||
"0014c30afa58ae0673b00a45b5c17dff4633780f1400"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "p2wsh-p2pk, in and out (from witness)",
|
||||
"arguments": {
|
||||
"witness": [
|
||||
"3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501",
|
||||
"2103e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058ac"
|
||||
]
|
||||
},
|
||||
"expected": {
|
||||
"address": "bc1q6rgl33d3s9dugudw7n68yrryajkr3ha9q8q24j20zs62se4q9tsqdy0t2q",
|
||||
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
||||
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
||||
"redeem": {
|
||||
"output": "03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058 OP_CHECKSIG",
|
||||
"input": "",
|
||||
"witness": [
|
||||
"3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501"
|
||||
]
|
||||
},
|
||||
"input": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "p2wsh-p2wpkh, in and out (from witness)",
|
||||
"arguments": {
|
||||
"witness": [
|
||||
"3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501",
|
||||
"03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058",
|
||||
"0014c30afa58ae0673b00a45b5c17dff4633780f1400"
|
||||
]
|
||||
},
|
||||
"expected": {
|
||||
"address": "bc1qpsl7el8wcx22f3fpdt3lm2wmzug7yyx2q3n8wzgtf37kps9tqy7skc7m3e",
|
||||
"hash": "0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
||||
"output": "OP_0 0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
||||
"redeem": {
|
||||
"output": "OP_0 c30afa58ae0673b00a45b5c17dff4633780f1400",
|
||||
"input": "",
|
||||
"witness": [
|
||||
"3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501",
|
||||
"03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"invalid": [
|
||||
{
|
||||
"exception": "Not enough data",
|
||||
"arguments": {}
|
||||
},
|
||||
{
|
||||
"description": "address.hash != H",
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
"address": "bc1qpsl7el8wcx22f3fpdt3lm2wmzug7yyx2q3n8wzgtf37kps9tqy7skc7m3e",
|
||||
"hash": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "address.hash != output.hash",
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
"address": "bc1qpsl7el8wcx22f3fpdt3lm2wmzug7yyx2q3n8wzgtf37kps9tqy7skc7m3e",
|
||||
"output": "OP_0 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "output.hash != H",
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
"hash": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"description": "H(redeem.output) != H",
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
"hash": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
"redeem": {
|
||||
"output": "03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058 OP_CHECKSIG"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Output is invalid",
|
||||
"arguments": {
|
||||
"output": "OP_HASH256 ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff OP_EQUAL"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Redeem.output is invalid",
|
||||
"arguments": {
|
||||
"redeem": {
|
||||
"output": ""
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Non push-only scriptSig",
|
||||
"arguments": {
|
||||
"redeem": {
|
||||
"output": "OP_TRUE",
|
||||
"input": "OP_HASH256"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Witness and redeem.output mismatch",
|
||||
"arguments": {
|
||||
"redeem": {
|
||||
"output": "OP_TRUE",
|
||||
"input": "OP_0"
|
||||
},
|
||||
"witness": [
|
||||
"02ffff"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Witness and redeem.witness mismatch",
|
||||
"arguments": {
|
||||
"redeem": {
|
||||
"output": "OP_TRUE",
|
||||
"witness": [
|
||||
"01"
|
||||
]
|
||||
},
|
||||
"witness": [
|
||||
"00",
|
||||
"02ffff"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"dynamic": {
|
||||
"depends": {
|
||||
"address": [ "address", "output", "hash", "redeem.output", "witness" ],
|
||||
"hash": [ "address", "output", "hash", "redeem.output", "witness" ],
|
||||
"output": [ "address", "output", "hash", "redeem.output", "witness" ],
|
||||
"redeem.output": [ "witness" ],
|
||||
"redeem.input": [ [ "input", "witness" ], "witness" ],
|
||||
"input": [ "witness" ],
|
||||
"witness": [ "redeem" ]
|
||||
},
|
||||
"details": [
|
||||
{
|
||||
"description": "p2wsh-p2pkh",
|
||||
"disabled": [
|
||||
"redeem.input"
|
||||
],
|
||||
"address": "bc1qusxlgq9quu27ucxs7a2fg8nv0pycdzvxsjk9npyupupxw3y892ss2cq5ar",
|
||||
"hash": "e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
|
||||
"output": "OP_0 e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
|
||||
"redeem": {
|
||||
"output": "OP_DUP OP_HASH160 c30afa58ae0673b00a45b5c17dff4633780f1400 OP_EQUALVERIFY OP_CHECKSIG",
|
||||
"input": "3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501 03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058",
|
||||
"witness": null
|
||||
},
|
||||
"input": "",
|
||||
"witness": [
|
||||
"3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501",
|
||||
"03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058",
|
||||
"76a914c30afa58ae0673b00a45b5c17dff4633780f140088ac"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "p2wsh-p2wpkh",
|
||||
"address": "bc1qpsl7el8wcx22f3fpdt3lm2wmzug7yyx2q3n8wzgtf37kps9tqy7skc7m3e",
|
||||
"hash": "0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
||||
"output": "OP_0 0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
||||
"redeem": {
|
||||
"output": "OP_0 c30afa58ae0673b00a45b5c17dff4633780f1400",
|
||||
"input": "",
|
||||
"witness": [
|
||||
"3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501",
|
||||
"03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058"
|
||||
]
|
||||
},
|
||||
"input": "",
|
||||
"witness": [
|
||||
"3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501",
|
||||
"03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058",
|
||||
"0014c30afa58ae0673b00a45b5c17dff4633780f1400"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
65
test/payments.js
Normal file
65
test/payments.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
/* global describe, it */
|
||||
|
||||
const assert = require('assert')
|
||||
const u = require('./payments.utils')
|
||||
|
||||
;['p2ms', 'p2pk', 'p2pkh', 'p2sh', 'p2wpkh', 'p2wsh'].forEach(function (p) {
|
||||
describe(p, function () {
|
||||
const fn = require('../src/payments/' + p)
|
||||
const fixtures = require('./fixtures/' + p)
|
||||
|
||||
fixtures.valid.forEach(function (f, i) {
|
||||
const args = u.preform(f.arguments)
|
||||
|
||||
it(f.description + ' as expected', function () {
|
||||
const actual = fn(args, f.options)
|
||||
u.equate(actual, f.expected, f.arguments)
|
||||
})
|
||||
|
||||
it(f.description + ' as expected (no validation)', function () {
|
||||
const actual = fn(args, Object.assign({}, f.options, {
|
||||
validate: false
|
||||
}))
|
||||
|
||||
u.equate(actual, f.expected, f.arguments)
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.invalid.forEach(function (f) {
|
||||
it('throws ' + (f.description || f.exception), function () {
|
||||
const args = u.preform(f.arguments)
|
||||
|
||||
assert.throws(function () {
|
||||
fn(args, f.options)
|
||||
}, new RegExp(f.exception))
|
||||
})
|
||||
})
|
||||
|
||||
// cross-verify dynamically too
|
||||
if (!fixtures.dynamic) return
|
||||
const { depends, details } = fixtures.dynamic
|
||||
|
||||
details.forEach(function (f) {
|
||||
const detail = u.preform(f)
|
||||
const disabled = {}
|
||||
if (f.disabled) f.disabled.forEach(function (k) { disabled[k] = true })
|
||||
|
||||
for (let key in depends) {
|
||||
if (key in disabled) continue
|
||||
const dependencies = depends[key]
|
||||
|
||||
dependencies.forEach(function (dependency) {
|
||||
if (!Array.isArray(dependency)) dependency = [dependency]
|
||||
|
||||
const args = {}
|
||||
dependency.forEach(function (d) { u.from(d, detail, args) })
|
||||
const expected = u.from(key, detail)
|
||||
|
||||
it(f.description + ', ' + key + ' derives from ' + JSON.stringify(dependency), function () {
|
||||
u.equate(fn(args), expected)
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
128
test/payments.utils.js
Normal file
128
test/payments.utils.js
Normal file
|
@ -0,0 +1,128 @@
|
|||
let t = require('assert')
|
||||
let bscript = require('../src/script')
|
||||
let bnetworks = require('../src/networks')
|
||||
|
||||
function tryHex (x) {
|
||||
if (Buffer.isBuffer(x)) return x.toString('hex')
|
||||
if (Array.isArray(x)) return x.map(tryHex)
|
||||
return x
|
||||
}
|
||||
function tryASM (x) {
|
||||
if (Buffer.isBuffer(x)) return bscript.toASM(x)
|
||||
return x
|
||||
}
|
||||
function asmToBuffer (x) {
|
||||
if (x === '') return Buffer.alloc(0)
|
||||
return bscript.fromASM(x)
|
||||
}
|
||||
function carryOver (a, b) {
|
||||
for (let k in b) {
|
||||
if (k in a && k === 'redeem') {
|
||||
carryOver(a[k], b[k])
|
||||
continue
|
||||
}
|
||||
|
||||
// don't, the value was specified
|
||||
if (k in a) continue
|
||||
|
||||
// otherwise, expect match
|
||||
a[k] = b[k]
|
||||
}
|
||||
}
|
||||
|
||||
function equateBase (a, b, context) {
|
||||
if ('output' in b) t.strictEqual(tryASM(a.output), tryASM(b.output), `Inequal ${context}output`)
|
||||
if ('input' in b) t.strictEqual(tryASM(a.input), tryASM(b.input), `Inequal ${context}input`)
|
||||
if ('witness' in b) t.deepEqual(tryHex(a.witness), tryHex(b.witness), `Inequal ${context}witness`)
|
||||
}
|
||||
|
||||
function equate (a, b, args) {
|
||||
b = Object.assign({}, b)
|
||||
carryOver(b, args)
|
||||
|
||||
// by null, we mean 'undefined', but JSON
|
||||
if (b.input === null) b.input = undefined
|
||||
if (b.output === null) b.output = undefined
|
||||
if (b.witness === null) b.witness = undefined
|
||||
if (b.redeem) {
|
||||
if (b.redeem.input === null) b.redeem.input = undefined
|
||||
if (b.redeem.output === null) b.redeem.output = undefined
|
||||
if (b.redeem.witness === null) b.redeem.witness = undefined
|
||||
}
|
||||
|
||||
equateBase(a, b, '')
|
||||
if (b.redeem) equateBase(a.redeem, b.redeem, 'redeem.')
|
||||
if (b.network) t.deepEqual(a.network, b.network, 'Inequal *.network')
|
||||
|
||||
// contextual
|
||||
if (b.signature === null) b.signature = undefined
|
||||
if ('address' in b) t.strictEqual(a.address, b.address, 'Inequal *.address')
|
||||
if ('hash' in b) t.strictEqual(tryHex(a.hash), tryHex(b.hash), 'Inequal *.hash')
|
||||
if ('pubkey' in b) t.strictEqual(tryHex(a.pubkey), tryHex(b.pubkey), 'Inequal *.pubkey')
|
||||
if ('signature' in b) t.strictEqual(tryHex(a.signature), tryHex(b.signature), 'Inequal signature')
|
||||
if ('m' in b) t.strictEqual(a.m, b.m, 'Inequal *.m')
|
||||
if ('n' in b) t.strictEqual(a.n, b.n, 'Inequal *.n')
|
||||
if ('pubkeys' in b) t.deepEqual(tryHex(a.pubkeys), tryHex(b.pubkeys), 'Inequal *.pubkeys')
|
||||
if ('signatures' in b) t.deepEqual(tryHex(a.signatures), tryHex(b.signatures), 'Inequal *.signatures')
|
||||
}
|
||||
|
||||
function preform (x) {
|
||||
x = Object.assign({}, x)
|
||||
|
||||
if (x.network) x.network = bnetworks[x.network]
|
||||
if (typeof x.inputHex === 'string') {
|
||||
x.input = Buffer.from(x.inputHex, 'hex')
|
||||
delete x.inputHex
|
||||
}
|
||||
if (typeof x.outputHex === 'string') {
|
||||
x.output = Buffer.from(x.outputHex, 'hex')
|
||||
delete x.outputHex
|
||||
}
|
||||
if (typeof x.output === 'string') x.output = asmToBuffer(x.output)
|
||||
if (typeof x.input === 'string') x.input = asmToBuffer(x.input)
|
||||
if (Array.isArray(x.witness)) {
|
||||
x.witness = x.witness.map(function (y) {
|
||||
return Buffer.from(y, 'hex')
|
||||
})
|
||||
}
|
||||
|
||||
if (x.hash) x.hash = Buffer.from(x.hash, 'hex')
|
||||
if (x.pubkey) x.pubkey = Buffer.from(x.pubkey, 'hex')
|
||||
if (x.signature) x.signature = Buffer.from(x.signature, 'hex')
|
||||
if (x.pubkeys) x.pubkeys = x.pubkeys.map(function (y) { return Buffer.from(y, 'hex') })
|
||||
if (x.signatures) x.signatures = x.signatures.map(function (y) { return Number.isFinite(y) ? y : Buffer.from(y, 'hex') })
|
||||
if (x.redeem) {
|
||||
if (typeof x.redeem.input === 'string') x.redeem.input = asmToBuffer(x.redeem.input)
|
||||
if (typeof x.redeem.output === 'string') x.redeem.output = asmToBuffer(x.redeem.output)
|
||||
if (Array.isArray(x.redeem.witness)) x.redeem.witness = x.redeem.witness.map(function (y) { return Buffer.from(y, 'hex') })
|
||||
x.redeem.network = bnetworks[x.redeem.network] || x.network || bnetworks.bitcoin
|
||||
}
|
||||
|
||||
return x
|
||||
}
|
||||
|
||||
function from (path, object, result) {
|
||||
path = path.split('.')
|
||||
result = result || {}
|
||||
|
||||
let r = result
|
||||
path.forEach((k, i) => {
|
||||
if (i < path.length - 1) {
|
||||
r[k] = r[k] || {}
|
||||
|
||||
// recurse
|
||||
r = r[k]
|
||||
object = object[k]
|
||||
} else {
|
||||
r[k] = object[k]
|
||||
}
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
from,
|
||||
equate,
|
||||
preform
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue