2015-08-25 05:52:24 +02:00
|
|
|
/* global describe, it */
|
|
|
|
|
|
|
|
var assert = require('assert')
|
|
|
|
var types = require('../src/types')
|
2016-02-02 13:06:16 +01:00
|
|
|
var typeforce = require('typeforce')
|
2015-08-25 05:52:24 +02:00
|
|
|
|
|
|
|
describe('types', function () {
|
2015-09-05 07:42:25 +02:00
|
|
|
describe('BigInt/ECPoint', function () {
|
2015-08-25 05:52:24 +02:00
|
|
|
it('return true for duck types', function () {
|
2016-09-26 08:32:16 +02:00
|
|
|
assert(types.BigInt(new function BigInteger () {}()))
|
|
|
|
assert(types.ECPoint(new function Point () {}()))
|
2015-09-05 07:42:25 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('return false for bad types', function () {
|
2016-09-26 08:32:16 +02:00
|
|
|
assert(!types.BigInt(new function NotABigInteger () {}()))
|
|
|
|
assert(!types.ECPoint(new function NotAPoint () {}()))
|
2015-08-25 05:52:24 +02:00
|
|
|
})
|
|
|
|
})
|
2016-02-02 13:06:16 +01:00
|
|
|
|
|
|
|
describe('Buffer Hash160/Hash256', function () {
|
2016-07-11 11:42:05 +02:00
|
|
|
var buffer20byte = new Buffer(20)
|
|
|
|
var buffer32byte = new Buffer(32)
|
2016-02-02 13:06:16 +01:00
|
|
|
|
2016-02-05 04:15:23 +01:00
|
|
|
it('return true for valid size', function () {
|
2016-02-02 13:06:16 +01:00
|
|
|
assert(types.Hash160bit(buffer20byte))
|
|
|
|
assert(types.Hash256bit(buffer32byte))
|
|
|
|
})
|
|
|
|
|
2016-02-05 04:15:23 +01:00
|
|
|
it('return true for oneOf', function () {
|
|
|
|
assert(typeforce(types.oneOf(types.Hash160bit, types.Hash256bit), buffer32byte))
|
|
|
|
assert(typeforce(types.oneOf(types.Hash256bit, types.Hash160bit), buffer32byte))
|
|
|
|
})
|
|
|
|
|
|
|
|
it('throws for invalid size', function () {
|
2016-02-02 13:06:16 +01:00
|
|
|
assert.throws(function () {
|
|
|
|
types.Hash160bit(buffer32byte)
|
2016-02-02 14:04:37 +01:00
|
|
|
}, /Expected 160-bit Buffer, got 256-bit Buffer/)
|
2016-02-02 13:06:16 +01:00
|
|
|
|
|
|
|
assert.throws(function () {
|
|
|
|
types.Hash256bit(buffer20byte)
|
2016-02-02 14:04:37 +01:00
|
|
|
}, /Expected 256-bit Buffer, got 160-bit Buffer/)
|
2016-02-02 13:06:16 +01:00
|
|
|
})
|
|
|
|
})
|
2015-08-25 05:52:24 +02:00
|
|
|
})
|