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

37 lines
993 B
TypeScript
Raw 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) => Promise<void> | void
): Promise<void> {
for (const implementation of ["blst", "herumi"] as Implementation[]) {
const bls = getBls(implementation);
await callback(bls, implementation);
}
}
2020-11-19 13:22:41 +00:00
export function describeForAllImplementations(callback: (bls: IBls) => void): void {
runForAllImplementations((bls, implementation) => {
describe(implementation, () => {
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
callback(bls);
});
});
2020-11-19 13:22:41 +00:00
}