mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-03-15 11:11:01 +00:00
* fix: replace node buffers with uint8arrays All usage of node buffers have been replaced with uint8arrays. BREAKING CHANGES: - Where node Buffers were returned, now Uint8Arrays are * chore: remove commented code
34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
/* eslint-env mocha */
|
|
'use strict'
|
|
|
|
const uint8ArrayFromString = require('uint8arrays/from-string')
|
|
const util = require('util')
|
|
const garbage = [uint8ArrayFromString('00010203040506070809', 'base16'), {}, null, false, undefined, true, 1, 0, uint8ArrayFromString(''), 'aGVsbG93b3JsZA==', 'helloworld', '']
|
|
|
|
function doTests (fncName, fnc, num, skipBuffersAndStrings) {
|
|
if (!num) {
|
|
num = 1
|
|
}
|
|
|
|
garbage.forEach((garbage) => {
|
|
if (skipBuffersAndStrings && (garbage instanceof Uint8Array || (typeof garbage) === 'string')) {
|
|
// skip this garbage because it's a Uint8Array or a String and we were told do do that
|
|
return
|
|
}
|
|
const args = []
|
|
for (let i = 0; i < num; i++) {
|
|
args.push(garbage)
|
|
}
|
|
it(fncName + '(' + args.map(garbage => util.inspect(garbage)).join(', ') + ')', async () => {
|
|
try {
|
|
await fnc.apply(null, args)
|
|
} catch (err) {
|
|
return // expected
|
|
}
|
|
throw new Error('Expected error to be thrown')
|
|
})
|
|
})
|
|
}
|
|
|
|
module.exports = { doTests }
|