diff --git a/test/types.js b/test/types.js index 9556927..6423650 100644 --- a/test/types.js +++ b/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") + }) + }) })