11import { toHex , fromHex } from '@exodus/bytes/hex.js'
2+ import * as lib from '../hex.js'
23import * as js from '../fallback/hex.js'
34import { describe , test } from 'node:test'
45
@@ -63,18 +64,21 @@ describe('toHex', () => {
6364 test ( 'invalid input' , ( t ) => {
6465 for ( const input of [ null , undefined , [ ] , [ 1 , 2 ] , 'string' ] ) {
6566 t . assert . throws ( ( ) => toHex ( input ) )
67+ t . assert . throws ( ( ) => lib . toHex ( input ) )
6668 t . assert . throws ( ( ) => js . toHex ( input ) )
6769 }
6870 } )
6971
7072 test ( 'fixtures' , ( t ) => {
7173 for ( const [ hex , uint8 ] of VALID ) {
7274 t . assert . strictEqual ( toHex ( uint8 ) , hex . toLowerCase ( ) , 'uint8' )
75+ t . assert . strictEqual ( lib . toHex ( uint8 ) , hex . toLowerCase ( ) , 'uint8' )
7376 for ( const A of types ) {
7477 t . assert . ok ( Number . isSafeInteger ( A . BYTES_PER_ELEMENT ) && A . BYTES_PER_ELEMENT >= 1 )
7578 if ( uint8 . byteLength % A . BYTES_PER_ELEMENT !== 0 ) continue
7679 const x = new A ( uint8 . buffer , uint8 . byteOffset , uint8 . byteLength / A . BYTES_PER_ELEMENT )
7780 t . assert . strictEqual ( toHex ( x ) , hex . toLowerCase ( ) , A . name )
81+ t . assert . strictEqual ( lib . toHex ( x ) , hex . toLowerCase ( ) , A . name )
7882 t . assert . strictEqual ( js . toHex ( x ) , hex . toLowerCase ( ) , A . name )
7983 }
8084 }
@@ -84,6 +88,8 @@ describe('toHex', () => {
8488 for ( const { uint8, buffer, hex } of pool ) {
8589 t . assert . strictEqual ( toHex ( uint8 ) , hex )
8690 t . assert . strictEqual ( toHex ( buffer ) , hex )
91+ t . assert . strictEqual ( lib . toHex ( uint8 ) , hex )
92+ t . assert . strictEqual ( lib . toHex ( buffer ) , hex )
8793 t . assert . strictEqual ( js . toHex ( uint8 ) , hex )
8894 }
8995 } )
@@ -94,9 +100,11 @@ describe('fromHex', () => {
94100 for ( const input of INVALID ) {
95101 if ( Uint8Array . fromHex ) t . assert . throws ( ( ) => Uint8Array . fromHex ( input ) , 'coherence' )
96102 t . assert . throws ( ( ) => fromHex ( input ) )
103+ t . assert . throws ( ( ) => lib . fromHex ( input ) )
97104 t . assert . throws ( ( ) => js . fromHex ( input ) )
98105 for ( const form of [ 'uint8' , 'buffer' , 'hex' ] ) {
99106 t . assert . throws ( ( ) => fromHex ( input , form ) )
107+ t . assert . throws ( ( ) => lib . fromHex ( input , form ) )
100108 }
101109 }
102110 } )
@@ -106,6 +114,8 @@ describe('fromHex', () => {
106114 if ( Uint8Array . fromHex ) t . assert . deepEqual ( uint8 , Uint8Array . fromHex ( hex ) , 'coherence' )
107115 t . assert . deepStrictEqual ( fromHex ( hex ) , uint8 )
108116 t . assert . deepStrictEqual ( fromHex ( hex , 'uint8' ) , uint8 )
117+ t . assert . deepStrictEqual ( lib . fromHex ( hex ) , uint8 )
118+ t . assert . deepStrictEqual ( lib . fromHex ( hex , 'uint8' ) , uint8 )
109119 t . assert . deepStrictEqual ( js . fromHex ( hex ) , uint8 )
110120 }
111121 } )
@@ -114,6 +124,8 @@ describe('fromHex', () => {
114124 for ( const { hex, uint8 } of pool ) {
115125 t . assert . deepStrictEqual ( fromHex ( hex ) , uint8 )
116126 t . assert . deepStrictEqual ( fromHex ( hex , 'uint8' ) , uint8 )
127+ t . assert . deepStrictEqual ( lib . fromHex ( hex ) , uint8 )
128+ t . assert . deepStrictEqual ( lib . fromHex ( hex , 'uint8' ) , uint8 )
117129 t . assert . deepStrictEqual ( js . fromHex ( hex ) , uint8 )
118130 }
119131 } )
@@ -122,12 +134,14 @@ describe('fromHex', () => {
122134 for ( const [ hex , uint8 ] of VALID ) {
123135 t . assert . deepStrictEqual ( Buffer . from ( hex , 'hex' ) , Buffer . from ( uint8 ) , 'coherence' )
124136 t . assert . deepStrictEqual ( fromHex ( hex , 'buffer' ) , Buffer . from ( uint8 ) )
137+ t . assert . deepStrictEqual ( lib . fromHex ( hex , 'buffer' ) , Buffer . from ( uint8 ) )
125138 }
126139 } )
127140
128141 test ( 'buffer, random' , ( t ) => {
129142 for ( const { hex, buffer } of pool ) {
130143 t . assert . deepStrictEqual ( fromHex ( hex , 'buffer' ) , buffer )
144+ t . assert . deepStrictEqual ( lib . fromHex ( hex , 'buffer' ) , buffer )
131145 }
132146 } )
133147} )
0 commit comments