use typeforce >= 1.6.2 which allows us to use typeforce.TfTypeError
with a custom error message.
This commit is contained in:
parent
ce21c99b43
commit
7c7537fc57
3 changed files with 6 additions and 5 deletions
|
@ -69,7 +69,7 @@
|
|||
"create-hmac": "^1.1.3",
|
||||
"ecurve": "^1.0.0",
|
||||
"randombytes": "^2.0.1",
|
||||
"typeforce": "^1.5.5",
|
||||
"typeforce": "^1.6.2",
|
||||
"wif": "^1.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -2,7 +2,8 @@ var typeforce = require('typeforce')
|
|||
|
||||
function nBuffer (value, n) {
|
||||
typeforce(types.Buffer, value)
|
||||
if (value.length !== n) throw new Error('Expected ' + (n * 8) + '-bit Buffer, got ' + (value.length * 8) + '-bit Buffer')
|
||||
if (value.length !== n) throw new typeforce.TfTypeError('Expected ' + (n * 8) + '-bit Buffer, got ' + (value.length * 8) + '-bit Buffer')
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -26,14 +26,14 @@ describe('types', function () {
|
|||
assert(types.Hash256bit(buffer32byte))
|
||||
})
|
||||
|
||||
it('return false for incorrect size', function () {
|
||||
it('throws for incorrect size', function () {
|
||||
assert.throws(function () {
|
||||
types.Hash160bit(buffer32byte)
|
||||
}, 'Expected 160-bit Buffer, got Number 256')
|
||||
}, /Expected 160-bit Buffer, got 256-bit Buffer/)
|
||||
|
||||
assert.throws(function () {
|
||||
types.Hash256bit(buffer20byte)
|
||||
}, 'Expected 256-bit Buffer, got Number 160')
|
||||
}, /Expected 256-bit Buffer, got 160-bit Buffer/)
|
||||
})
|
||||
|
||||
it('return true for oneOf', function () {
|
||||
|
|
Loading…
Reference in a new issue