tests/payments: add missing tests

This commit is contained in:
Daniel Cousens 2018-07-14 20:24:11 +10:00
parent 0d9619aeed
commit 7104bb412e
6 changed files with 84 additions and 14 deletions

View file

@ -87,9 +87,9 @@ function p2pkh (a, opts) {
if (opts.validate) { if (opts.validate) {
let hash let hash
if (a.address) { 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') if (_address().hash.length !== 20) throw new TypeError('Invalid address')
else hash = _address().hash hash = _address().hash
} }
if (a.hash) { if (a.hash) {

View file

@ -109,7 +109,7 @@ function p2sh (a, opts) {
if (opts.validate) { if (opts.validate) {
let hash let hash
if (a.address) { 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') if (_address().hash.length !== 20) throw new TypeError('Invalid address')
else hash = _address().hash else hash = _address().hash
} }

View file

@ -90,17 +90,11 @@ function p2wpkh (a, opts) {
if (opts.validate) { if (opts.validate) {
let hash let hash
if (a.address) { if (a.address) {
if (network && network.bech32 !== _address().prefix) throw new TypeError('Network mismatch') if (network && network.bech32 !== _address().prefix) throw new TypeError('Invalid prefix or Network mismatch')
if (_address().version !== 0x00) throw new TypeError('Invalid version') if (_address().version !== 0x00) throw new TypeError('Invalid address version')
if (_address().data.length !== 20) throw new TypeError('Invalid data') if (_address().data.length !== 20) throw new TypeError('Invalid address data')
if (hash && !hash.equals(_address().data)) throw new TypeError('Hash mismatch') // if (hash && !hash.equals(_address().data)) throw new TypeError('Hash mismatch')
else hash = _address().data 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 (a.hash) { if (a.hash) {
@ -117,6 +111,12 @@ function p2wpkh (a, opts) {
else hash = a.output.slice(2) 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) {
if (a.witness.length !== 2) throw new TypeError('Witness is invalid') if (a.witness.length !== 2) throw new TypeError('Witness is invalid')
if (!bscript.isCanonicalScriptSignature(a.witness[0])) throw new TypeError('Witness has invalid signature') if (!bscript.isCanonicalScriptSignature(a.witness[0])) throw new TypeError('Witness has invalid signature')

View file

@ -121,6 +121,24 @@
"outputHex": "76a94c14aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac" "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", "exception": "Pubkey mismatch",
"arguments": { "arguments": {

View file

@ -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", "exception": "Input too short",
"arguments": { "arguments": {
@ -280,6 +298,21 @@
"inputHex": "021000" "inputHex": "021000"
} }
}, },
{
"exception": "Witness and redeem.witness mismatch",
"arguments": {
"witness": [
"3045ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
"030000000000000000000000000000000000000000000000000000000000000001"
],
"redeem": {
"witness": [
"3045dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
"030000000000000000000000000000000000000000000000000000000000000001"
]
}
}
},
{ {
"exception": "Hash mismatch", "exception": "Hash mismatch",
"arguments": { "arguments": {

View file

@ -116,6 +116,18 @@
] ]
} }
}, },
{
"exception": "Invalid prefix or Network mismatch",
"arguments": {
"address": "tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7"
}
},
{
"exception": "Invalid address version",
"arguments": {
"address": "bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx"
}
},
{ {
"exception": "Hash mismatch", "exception": "Hash mismatch",
"arguments": { "arguments": {
@ -137,6 +149,13 @@
"hash": "ffffffffffffffffffffffffffffffffffffffff" "hash": "ffffffffffffffffffffffffffffffffffffffff"
} }
}, },
{
"exception": "Hash mismatch",
"arguments": {
"hash": "ffffffffffffffffffffffffffffffffffffffff",
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001"
}
},
{ {
"exception": "Hash mismatch", "exception": "Hash mismatch",
"arguments": { "arguments": {