@@ -34,6 +34,11 @@ const encodeHex = string => {
34
34
35
35
const encodeText = string => textEncoder . encode ( string )
36
36
37
+ const they = ( description , test ) => {
38
+ it ( 'description (Buffer)' , ( ) => test ( Buffer . from ) )
39
+ it ( 'description (Uint8Array)' , ( ) => test ( encodeText ) )
40
+ }
41
+
37
42
describe ( 'multihash' , ( ) => {
38
43
describe ( 'toHexString' , ( ) => {
39
44
it ( 'valid' , ( ) => {
@@ -94,7 +99,7 @@ describe('multihash', () => {
94
99
} )
95
100
96
101
describe ( 'fromB58String' , ( ) => {
97
- it ( 'valid' , ( ) => {
102
+ they ( 'valid' , ( encode ) => {
98
103
const src = 'QmPfjpVaf593UQJ9a5ECvdh2x17XuJYG5Yanv5UFnH3jPE'
99
104
const expected = encodeHex ( '122013bf801597d74a660453412635edd8c34271e5998f801fac5d700c6ce8d8e461' )
100
105
@@ -105,7 +110,7 @@ describe('multihash', () => {
105
110
)
106
111
107
112
expect (
108
- mh . fromB58String ( encodeText ( src ) )
113
+ mh . fromB58String ( encode ( src ) )
109
114
) . to . be . eql (
110
115
expected
111
116
)
@@ -161,7 +166,7 @@ describe('multihash', () => {
161
166
} )
162
167
} )
163
168
164
- it ( 'invalid' , ( ) => {
169
+ they ( 'invalid' , ( encode ) => {
165
170
expect (
166
171
( ) => mh . encode ( )
167
172
) . to . throw (
@@ -175,7 +180,7 @@ describe('multihash', () => {
175
180
)
176
181
177
182
expect (
178
- ( ) => mh . encode ( encodeText ( 'hello' ) , 0x11 , 2 )
183
+ ( ) => mh . encode ( encode ( 'hello' ) , 0x11 , 2 )
179
184
) . to . throw (
180
185
/ l e n g t h s h o u l d b e e q u a l /
181
186
)
@@ -287,7 +292,7 @@ describe('multihash', () => {
287
292
} )
288
293
} )
289
294
290
- it ( 'invalid' , ( ) => {
295
+ they ( 'invalid' , ( encode ) => {
291
296
const invalidNames = [
292
297
'sha256' ,
293
298
'sha9' ,
@@ -303,7 +308,7 @@ describe('multihash', () => {
303
308
} )
304
309
305
310
expect (
306
- ( ) => mh . coerceCode ( encodeText ( 'hello' ) )
311
+ ( ) => mh . coerceCode ( encode ( 'hello' ) )
307
312
) . to . throw (
308
313
/ s h o u l d b e a n u m b e r /
309
314
)
@@ -316,14 +321,14 @@ describe('multihash', () => {
316
321
} )
317
322
} )
318
323
319
- it ( 'prefix' , ( ) => {
320
- const multihash = mh . encode ( encodeText ( 'hey' ) , 0x11 , 3 )
324
+ they ( 'prefix' , ( encode ) => {
325
+ const multihash = mh . encode ( encode ( 'hey' ) , 0x11 , 3 )
321
326
const prefix = mh . prefix ( multihash )
322
327
expect ( prefix . toString ( 'hex' ) ) . to . eql ( '1103' )
323
328
} )
324
329
325
- it ( 'prefix throws on invalid multihash' , ( ) => {
326
- const multihash = encodeText ( 'definitely not valid' )
330
+ they ( 'prefix throws on invalid multihash' , ( encode ) => {
331
+ const multihash = encode ( 'definitely not valid' )
327
332
328
333
expect ( ( ) => mh . prefix ( multihash ) ) . to . throw ( )
329
334
} )
0 commit comments