This repository has been archived on 2023-04-09. You can view files and clone it, but cannot push or open issues or pull requests.
chainsafe-bls/test/switch.ts

44 lines
1.1 KiB
TypeScript

import blst from "../src/blst-native/index.js";
import herumi from "../src/herumi/index.js";
import {IBls} from "../src/interface.js";
export type Implementation = "blst" | "herumi";
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export function getBls(implementation: Implementation): IBls {
switch (implementation) {
case "blst":
return blst;
case "herumi":
return herumi;
}
}
export async function runForAllImplementations(
callback: (bls: IBls, implementation: Implementation) => void
): Promise<void> {
for (const implementation of ["blst", "herumi"] as Implementation[]) {
const bls = getBls(implementation);
await bls.init();
callback(bls, implementation);
}
}
export function describeForAllImplementations(callback: (bls: IBls) => void): void {
runForAllImplementations((bls, implementation) => {
describe(implementation, function () {
before(async () => {
await bls.init();
});
try {
callback(bls);
} catch (e) {
it("Error generating test cases", function (done) {
done(e);
});
}
});
});
}