mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-03-31 07:31:13 +00:00
BREAKING CHANGE: API refactored to use async/await feat: WIP use async await fix: passing tests chore: update travis node.js versions fix: skip ursa optional tests on windows fix: benchmarks docs: update docs fix: remove broken and intested private key decrypt chore: update deps
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
/* eslint-env mocha */
|
|
'use strict'
|
|
|
|
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
|
|
}
|
|
let 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 = (obj, fncs, num) => {
|
|
describe('returns error via cb instead of crashing', () => {
|
|
fncs.forEach(fnc => {
|
|
doTests(fnc, obj[fnc], num)
|
|
})
|
|
})
|
|
}
|
|
|
|
module.exports.doTests = doTests
|