mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-03-31 07:31:13 +00:00
* fix: add buffer, cleanup, reduce size - add buffer related to https://github.com/ipfs/js-ipfs/issues/2924 - remove unnecessary eslint ignore - remove tweelnacl and use node-forge - remove browserify-aes and use node-forge - use multibase to encode b58 - require only sha256 from multihashing - reduce bundle size after all the deps here https://github.com/ipfs/js-ipfs/issues/2924 are merged libp2p-crypto will be able to be bundle with `node: false` 🎉 * fix: reduce bundle size * fix: use new secp * fix: bundle size * chore: update secp Co-Authored-By: Jacob Heun <jacobheun@gmail.com> Co-authored-by: Jacob Heun <jacobheun@gmail.com>
34 lines
977 B
JavaScript
34 lines
977 B
JavaScript
/* eslint-env mocha */
|
|
'use strict'
|
|
|
|
const { Buffer } = require('buffer')
|
|
const util = require('util')
|
|
const garbage = [Buffer.from('00010203040506070809', 'hex'), {}, null, false, undefined, true, 1, 0, Buffer.from(''), 'aGVsbG93b3JsZA==', 'helloworld', '']
|
|
|
|
function doTests (fncName, fnc, num, skipBuffersAndStrings) {
|
|
if (!num) {
|
|
num = 1
|
|
}
|
|
|
|
garbage.forEach((garbage) => {
|
|
if (skipBuffersAndStrings && (Buffer.isBuffer(garbage) || (typeof garbage) === 'string')) {
|
|
// skip this garbage because it's a buffer 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 }
|