tests/payments: add missing tests
This commit is contained in:
parent
0d9619aeed
commit
7104bb412e
6 changed files with 84 additions and 14 deletions
|
@ -87,9 +87,9 @@ function p2pkh (a, opts) {
|
|||
if (opts.validate) {
|
||||
let hash
|
||||
if (a.address) {
|
||||
if (_address().version !== network.pubKeyHash) throw new TypeError('Network mismatch')
|
||||
if (_address().version !== network.pubKeyHash) throw new TypeError('Invalid version or Network mismatch')
|
||||
if (_address().hash.length !== 20) throw new TypeError('Invalid address')
|
||||
else hash = _address().hash
|
||||
hash = _address().hash
|
||||
}
|
||||
|
||||
if (a.hash) {
|
||||
|
|
|
@ -109,7 +109,7 @@ function p2sh (a, opts) {
|
|||
if (opts.validate) {
|
||||
let hash
|
||||
if (a.address) {
|
||||
if (_address().version !== network.scriptHash) throw new TypeError('Network mismatch')
|
||||
if (_address().version !== network.scriptHash) throw new TypeError('Invalid version or Network mismatch')
|
||||
if (_address().hash.length !== 20) throw new TypeError('Invalid address')
|
||||
else hash = _address().hash
|
||||
}
|
||||
|
|
|
@ -90,17 +90,11 @@ function p2wpkh (a, opts) {
|
|||
if (opts.validate) {
|
||||
let hash
|
||||
if (a.address) {
|
||||
if (network && network.bech32 !== _address().prefix) throw new TypeError('Network mismatch')
|
||||
if (_address().version !== 0x00) throw new TypeError('Invalid version')
|
||||
if (_address().data.length !== 20) throw new TypeError('Invalid data')
|
||||
if (hash && !hash.equals(_address().data)) throw new TypeError('Hash mismatch')
|
||||
else hash = _address().data
|
||||
}
|
||||
|
||||
if (a.pubkey) {
|
||||
const pkh = bcrypto.hash160(a.pubkey)
|
||||
if (hash && !hash.equals(pkh)) throw new TypeError('Hash mismatch')
|
||||
else hash = pkh
|
||||
if (network && network.bech32 !== _address().prefix) throw new TypeError('Invalid prefix or Network mismatch')
|
||||
if (_address().version !== 0x00) throw new TypeError('Invalid address version')
|
||||
if (_address().data.length !== 20) throw new TypeError('Invalid address data')
|
||||
// if (hash && !hash.equals(_address().data)) throw new TypeError('Hash mismatch')
|
||||
hash = _address().data
|
||||
}
|
||||
|
||||
if (a.hash) {
|
||||
|
@ -117,6 +111,12 @@ function p2wpkh (a, opts) {
|
|||
else hash = a.output.slice(2)
|
||||
}
|
||||
|
||||
if (a.pubkey) {
|
||||
const pkh = bcrypto.hash160(a.pubkey)
|
||||
if (hash && !hash.equals(pkh)) throw new TypeError('Hash mismatch')
|
||||
else hash = pkh
|
||||
}
|
||||
|
||||
if (a.witness) {
|
||||
if (a.witness.length !== 2) throw new TypeError('Witness is invalid')
|
||||
if (!bscript.isCanonicalScriptSignature(a.witness[0])) throw new TypeError('Witness has invalid signature')
|
||||
|
|
18
test/fixtures/p2pkh.json
vendored
18
test/fixtures/p2pkh.json
vendored
|
@ -121,6 +121,24 @@
|
|||
"outputHex": "76a94c14aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Invalid version or Network mismatch",
|
||||
"arguments": {
|
||||
"address": "3LRW7jeCvQCRdPF8S3yUCfRAx4eqXFmdcr"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Invalid address",
|
||||
"arguments": {
|
||||
"address": "111111111111111111117K4nzc"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Invalid address",
|
||||
"arguments": {
|
||||
"address": "111111111111111111111111133izVn"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Pubkey mismatch",
|
||||
"arguments": {
|
||||
|
|
33
test/fixtures/p2sh.json
vendored
33
test/fixtures/p2sh.json
vendored
|
@ -227,6 +227,24 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Invalid version or Network mismatch",
|
||||
"arguments": {
|
||||
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Invalid address",
|
||||
"arguments": {
|
||||
"address": "TYPjCiGbKiwP6r12cdkmVjySbQr7mb3r"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Invalid address",
|
||||
"arguments": {
|
||||
"address": "EDaBpuERpLssFzbCV1kgy8tKJsHrcwmzY7HDMF2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Input too short",
|
||||
"arguments": {
|
||||
|
@ -280,6 +298,21 @@
|
|||
"inputHex": "021000"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Witness and redeem.witness mismatch",
|
||||
"arguments": {
|
||||
"witness": [
|
||||
"3045ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
||||
"030000000000000000000000000000000000000000000000000000000000000001"
|
||||
],
|
||||
"redeem": {
|
||||
"witness": [
|
||||
"3045dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
|
||||
"030000000000000000000000000000000000000000000000000000000000000001"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
|
|
19
test/fixtures/p2wpkh.json
vendored
19
test/fixtures/p2wpkh.json
vendored
|
@ -116,6 +116,18 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Invalid prefix or Network mismatch",
|
||||
"arguments": {
|
||||
"address": "tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Invalid address version",
|
||||
"arguments": {
|
||||
"address": "bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
|
@ -137,6 +149,13 @@
|
|||
"hash": "ffffffffffffffffffffffffffffffffffffffff"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
"hash": "ffffffffffffffffffffffffffffffffffffffff",
|
||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001"
|
||||
}
|
||||
},
|
||||
{
|
||||
"exception": "Hash mismatch",
|
||||
"arguments": {
|
||||
|
|
Loading…
Add table
Reference in a new issue