Browse Source

add failing test case for hash160/256 typeforce check

hk-custom-address
Ruben de Vries 9 years ago
parent
commit
ce21c99b43
  1. 26
      test/types.js

26
test/types.js

@ -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…
Cancel
Save