From 706f5d7a9cdd244adf4b2c85a0b2ccca11115b8f Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 18 Aug 2015 09:18:23 +1000 Subject: [PATCH] scripts: adds tests for *HashOutput --- src/types.js | 2 +- test/fixtures/scripts.json | 12 ++++++++++++ test/fixtures/transaction.json | 4 ++-- test/scripts.js | 20 ++++++++++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/types.js b/src/types.js index bd7c149..2944995 100644 --- a/src/types.js +++ b/src/types.js @@ -4,7 +4,7 @@ var typeforce = require('typeforce') function nBuffer (value, n) { if (!Buffer.isBuffer(value)) return false - if (value.length !== n) throw new Error('Expected ' + (n * 8) + '-bit Buffer, got ' + (value.length * 8) + '-bit') + if (value.length !== n) throw new Error('Expected ' + (n * 8) + '-bit Buffer, got ' + (value.length * 8) + '-bit Buffer') return true } diff --git a/test/fixtures/scripts.json b/test/fixtures/scripts.json index 2442d52..1a17622 100644 --- a/test/fixtures/scripts.json +++ b/test/fixtures/scripts.json @@ -265,6 +265,18 @@ "304402207515cf147d201f411092e6be5a64a6006f9308fad7b2a8fdaab22cd86ce764c202200974b8aca7bf51dbf54150d3884e1ae04f675637b926ec33bf75939446f6ca2801" ] } + ], + "pubKeyHashOutput": [ + { + "exception": "Expected 160-bit Buffer, got 16-bit Buffer", + "hash": "ffff" + } + ], + "scriptHashOutput": [ + { + "exception": "Expected 160-bit Buffer, got 24-bit Buffer", + "hash": "ffffff" + } ] } } diff --git a/test/fixtures/transaction.json b/test/fixtures/transaction.json index a47cf3a..8fb1a94 100644 --- a/test/fixtures/transaction.json +++ b/test/fixtures/transaction.json @@ -229,12 +229,12 @@ "invalid": { "addInput": [ { - "exception": "Expected 256-bit Buffer, got 240-bit", + "exception": "Expected 256-bit Buffer, got 240-bit Buffer", "hash": "0aed1366a73b6057ee7800d737bff1bdf8c448e98d86bc0998f2b009816d", "index": 0 }, { - "exception": "Expected 256-bit Buffer, got 272-bit", + "exception": "Expected 256-bit Buffer, got 272-bit Buffer", "hash": "0aed1366a73b6057ee7800d737bff1bdf8c448e98d86bc0998f2b009816da9b0ffff", "index": 0 } diff --git a/test/scripts.js b/test/scripts.js index daf2ff8..73b9f0d 100644 --- a/test/scripts.js +++ b/test/scripts.js @@ -245,6 +245,16 @@ describe('scripts', function () { assert.strictEqual(scripts.toASM(scriptPubKey), f.scriptPubKey) }) }) + + fixtures.invalid.pubKeyHashOutput.forEach(function (f) { + var hash = new Buffer(f.hash, 'hex') + + it('throws on ' + f.exception, function () { + assert.throws(function () { + scripts.pubKeyHashOutput(hash) + }, new RegExp(f.exception)) + }) + }) }) describe('multisigInput', function () { @@ -333,6 +343,16 @@ describe('scripts', function () { assert.strictEqual(scripts.toASM(scriptPubKey), f.scriptPubKey) }) }) + + fixtures.invalid.scriptHashOutput.forEach(function (f) { + var hash = new Buffer(f.hash, 'hex') + + it('throws on ' + f.exception, function () { + assert.throws(function () { + scripts.scriptHashOutput(hash) + }, new RegExp(f.exception)) + }) + }) }) describe('nullDataOutput', function () {