Files
wasm/packages/wasm-crypto/test/all/index.cjs
T
Jaco be4f3ce82c 2022 (#263)
* 2022

* Update scripts/rust-version.sh
2022-01-01 09:30:22 +02:00

69 lines
1.2 KiB
JavaScript

// Copyright 2019-2022 @polkadot/wasm-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
const wasm = require('../../build/index.cjs');
const bip39 = require('./bip39.cjs');
const ed25519 = require('./ed25519.cjs');
const hashing = require('./hashing.cjs');
const secp256k1 = require('./secp256k1.cjs');
const sr25519 = require('./sr25519.cjs');
const vrf = require('./vrf.cjs');
const tests = {
...bip39,
...ed25519,
...hashing,
...secp256k1,
...sr25519,
...vrf
};
function beforeAll () {
return wasm.waitReady();
}
function runAll () {
const failed = [];
let count = 0;
Object.keys(tests).forEach((name) => {
count++;
try {
console.time(name);
console.log();
console.log(name);
tests[name](wasm);
console.timeEnd(name);
} catch (error) {
console.error(error);
failed.push(name);
}
});
if (failed.length) {
throw new Error(`Failed: ${failed.length} of ${count}: ${failed.concat(', ')}`);
}
}
function runUnassisted () {
beforeAll()
.then(() => runAll())
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(-1);
});
}
module.exports = {
beforeAll,
runAll,
runUnassisted,
tests,
wasm
};