22
33var assert = require ( 'assert' )
44var types = require ( '../src/types' )
5+ var typeforce = require ( 'typeforce' )
56
67describe ( 'types' , function ( ) {
78 describe ( 'BigInt/ECPoint' , function ( ) {
@@ -15,4 +16,29 @@ describe('types', function () {
1516 assert ( ! types . ECPoint ( new function NotAPoint ( ) { } ) )
1617 } )
1718 } )
19+
20+ describe ( 'Buffer Hash160/Hash256' , function ( ) {
21+ var buffer20byte = new Buffer ( ( new Array ( 20 + 1 ) ) . join ( '00' ) , 'hex' )
22+ var buffer32byte = new Buffer ( ( new Array ( 32 + 1 ) ) . join ( '00' ) , 'hex' )
23+
24+ it ( 'return true for correct size' , function ( ) {
25+ assert ( types . Hash160bit ( buffer20byte ) )
26+ assert ( types . Hash256bit ( buffer32byte ) )
27+ } )
28+
29+ it ( 'return false for incorrect size' , function ( ) {
30+ assert . throws ( function ( ) {
31+ types . Hash160bit ( buffer32byte )
32+ } , 'Expected 160-bit Buffer, got Number 256' )
33+
34+ assert . throws ( function ( ) {
35+ types . Hash256bit ( buffer20byte )
36+ } , 'Expected 256-bit Buffer, got Number 160' )
37+ } )
38+
39+ it ( 'return true for oneOf' , function ( ) {
40+ assert ( typeforce ( types . oneOf ( types . Hash256bit , types . Hash160bit ) , buffer32byte ) , "Hash256 first" )
41+ assert ( typeforce ( types . oneOf ( types . Hash160bit , types . Hash256bit ) , buffer32byte ) , "Hash160 first" )
42+ } )
43+ } )
1844} )
0 commit comments