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/spec/aggregate.test.ts

35 lines
1.0 KiB
TypeScript

import path from "path";
import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util";
import {bytesToHex, hexToBytes} from "../../src/helpers";
import {SPEC_TESTS_DIR} from "../params";
import {describeForAllImplementations} from "../switch";
import {EmptyAggregateError} from "../../src/errors";
interface IAggregateSigsTestCase {
data: {
input: string[];
output: string;
};
}
describeForAllImplementations((bls) => {
describeDirectorySpecTest<IAggregateSigsTestCase, string | null>(
"bls/aggregate/small",
path.join(SPEC_TESTS_DIR, "tests/general/phase0/bls/aggregate/small"),
(testCase) => {
try {
const signatures = testCase.data.input;
const agg = bls.aggregateSignatures(signatures.map(hexToBytes));
return bytesToHex(agg);
} catch (e) {
if (e instanceof EmptyAggregateError) return null;
throw e;
}
},
{
inputTypes: {data: InputType.YAML},
getExpected: (testCase) => testCase.data.output,
}
);
});