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
Raw Permalink Normal View History

2020-11-19 13:22:41 +00:00
import blst from "../src/blst";
import herumi from "../src/herumi";
2020-11-20 19:03:17 +00:00
import {IBls} from "../src/interface";
2020-11-19 13:22:41 +00:00
export type Implementation = "blst" | "herumi";
2020-11-20 12:27:30 +00:00
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
2020-11-20 19:03:17 +00:00
export function getBls(implementation: Implementation): IBls {
2020-11-19 13:22:41 +00:00
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);
}
}
2020-11-19 13:22:41 +00:00
export function describeForAllImplementations(callback: (bls: IBls) => void): void {
runForAllImplementations((bls, implementation) => {
2020-12-14 09:13:56 +00:00
describe(implementation, function () {
2020-11-20 19:03:17 +00:00
before(async () => {
2020-11-25 16:09:44 +00:00
await bls.init();
2020-11-20 19:03:17 +00:00
});
2020-11-19 13:22:41 +00:00
2020-12-14 09:13:56 +00:00
try {
callback(bls);
} catch (e) {
it("Error generating test cases", function (done) {
done(e);
});
}
});
});
2020-11-19 13:22:41 +00:00
}