add failing test case for hash160/256 typeforce check
This commit is contained in:
parent
7ba58078b1
commit
ce21c99b43
1 changed files with 26 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
var assert = require('assert')
|
||||
var types = require('../src/types')
|
||||
var typeforce = require('typeforce')
|
||||
|
||||
describe('types', function () {
|
||||
describe('BigInt/ECPoint', function () {
|
||||
|
@ -15,4 +16,29 @@ describe('types', function () {
|
|||
assert(!types.ECPoint(new function NotAPoint () {}))
|
||||
})
|
||||
})
|
||||
|
||||
describe('Buffer Hash160/Hash256', function () {
|
||||
var buffer20byte = new Buffer((new Array(20 + 1)).join('00'), 'hex')
|
||||
var buffer32byte = new Buffer((new Array(32 + 1)).join('00'), 'hex')
|
||||
|
||||
it('return true for correct size', function () {
|
||||
assert(types.Hash160bit(buffer20byte))
|
||||
assert(types.Hash256bit(buffer32byte))
|
||||
})
|
||||
|
||||
it('return false for incorrect size', function () {
|
||||
assert.throws(function () {
|
||||
types.Hash160bit(buffer32byte)
|
||||
}, 'Expected 160-bit Buffer, got Number 256')
|
||||
|
||||
assert.throws(function () {
|
||||
types.Hash256bit(buffer20byte)
|
||||
}, 'Expected 256-bit Buffer, got Number 160')
|
||||
})
|
||||
|
||||
it('return true for oneOf', function () {
|
||||
assert(typeforce(types.oneOf(types.Hash256bit, types.Hash160bit), buffer32byte), "Hash256 first")
|
||||
assert(typeforce(types.oneOf(types.Hash160bit, types.Hash256bit), buffer32byte), "Hash160 first")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue