Skip to content

Commit

Permalink
scripts: adds tests for *HashOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Aug 17, 2015
1 parent 4970ae0 commit 86f1cad
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

This comment has been minimized.

Copy link
@dcousens

dcousens Aug 17, 2015

Author Contributor

Small amendment to the changes made in noassert.

return true
}

Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/scripts.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
}
4 changes: 2 additions & 2 deletions test/fixtures/transaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
20 changes: 20 additions & 0 deletions test/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit 86f1cad

Please sign in to comment.