Browse Source
Merge pull request #1129 from bitcoinjs/morecover
testing/p2wsh: add missing test case coverage
addLowRGrinding
Jonathan Underwood
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
51 additions and
6 deletions
-
src/payments/p2wsh.js
-
test/fixtures/p2wpkh.json
-
test/fixtures/p2wsh.json
-
test/payments.utils.js
|
|
@ -119,9 +119,9 @@ function p2wsh (a, opts) { |
|
|
|
if (opts.validate) { |
|
|
|
let hash |
|
|
|
if (a.address) { |
|
|
|
if (_address().prefix !== network.bech32) throw new TypeError('Network mismatch') |
|
|
|
if (_address().version !== 0x00) throw new TypeError('Invalid version') |
|
|
|
if (_address().data.length !== 32) throw new TypeError('Invalid data') |
|
|
|
if (_address().prefix !== network.bech32) throw new TypeError('Invalid prefix or Network mismatch') |
|
|
|
if (_address().version !== 0x00) throw new TypeError('Invalid address version') |
|
|
|
if (_address().data.length !== 32) throw new TypeError('Invalid address data') |
|
|
|
else hash = _address().data |
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -119,13 +119,19 @@ |
|
|
|
{ |
|
|
|
"exception": "Invalid prefix or Network mismatch", |
|
|
|
"arguments": { |
|
|
|
"address": "tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7" |
|
|
|
"address": "foo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqs30dvv" |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
"exception": "Invalid address version", |
|
|
|
"arguments": { |
|
|
|
"address": "bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx" |
|
|
|
"address": "bc1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq5us4ke" |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
"exception": "Invalid address data", |
|
|
|
"arguments": { |
|
|
|
"address": "bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8" |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
|
|
@ -268,6 +268,45 @@ |
|
|
|
"02ffff" |
|
|
|
] |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
"exception": "Ambiguous witness source", |
|
|
|
"arguments": { |
|
|
|
"redeem": { |
|
|
|
"output": "OP_TRUE", |
|
|
|
"input": "01", |
|
|
|
"witness": [ |
|
|
|
"01" |
|
|
|
] |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
"exception": "Network mismatch", |
|
|
|
"arguments": { |
|
|
|
"network": "bitcoin", |
|
|
|
"redeem": { |
|
|
|
"network": "testnet" |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
"exception": "Invalid prefix or Network mismatch", |
|
|
|
"arguments": { |
|
|
|
"address": "foo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqs30dvv" |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
"exception": "Invalid address version", |
|
|
|
"arguments": { |
|
|
|
"address": "bc1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq5us4ke" |
|
|
|
} |
|
|
|
}, |
|
|
|
{ |
|
|
|
"exception": "Invalid address data", |
|
|
|
"arguments": { |
|
|
|
"address": "bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8" |
|
|
|
} |
|
|
|
} |
|
|
|
], |
|
|
|
"dynamic": { |
|
|
|
|
|
@ -99,7 +99,7 @@ function preform (x) { |
|
|
|
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(fromHex) |
|
|
|
x.redeem.network = bnetworks[x.redeem.network] || x.network || bnetworks.bitcoin |
|
|
|
if (x.redeem.network) x.redeem.network = bnetworks[x.redeem.network] |
|
|
|
} |
|
|
|
|
|
|
|
return x |
|
|
|