From 14d9636b6e6fe8131c3854c017ee14d2c3d73d8b Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 17 Jul 2018 15:22:03 +1000 Subject: [PATCH] testing/p2wsh: add missing test case coverage --- src/payments/p2wsh.js | 6 +++--- test/fixtures/p2wpkh.json | 10 ++++++++-- test/fixtures/p2wsh.json | 39 +++++++++++++++++++++++++++++++++++++++ test/payments.utils.js | 2 +- 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/payments/p2wsh.js b/src/payments/p2wsh.js index e1adcc5..c84d822 100644 --- a/src/payments/p2wsh.js +++ b/src/payments/p2wsh.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 } diff --git a/test/fixtures/p2wpkh.json b/test/fixtures/p2wpkh.json index b0aa4ff..7341907 100644 --- a/test/fixtures/p2wpkh.json +++ b/test/fixtures/p2wpkh.json @@ -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" } }, { diff --git a/test/fixtures/p2wsh.json b/test/fixtures/p2wsh.json index c123d64..9579f64 100644 --- a/test/fixtures/p2wsh.json +++ b/test/fixtures/p2wsh.json @@ -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": { diff --git a/test/payments.utils.js b/test/payments.utils.js index 2dbed3d..6a7af32 100644 --- a/test/payments.utils.js +++ b/test/payments.utils.js @@ -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