2020-02-26 08:19:15 +00:00
|
|
|
import path from "path";
|
2020-11-05 20:55:25 +00:00
|
|
|
import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util";
|
2020-11-28 19:52:32 +00:00
|
|
|
import {bytesToHex, hexToBytes} from "../../src/helpers";
|
2020-11-19 13:22:41 +00:00
|
|
|
import {SPEC_TESTS_DIR} from "../params";
|
2020-11-20 19:35:32 +00:00
|
|
|
import {describeForAllImplementations} from "../switch";
|
2020-11-30 02:43:57 +00:00
|
|
|
import {EmptyAggregateError} from "../../src/errors";
|
2020-02-26 08:19:15 +00:00
|
|
|
|
|
|
|
interface IAggregateSigsTestCase {
|
|
|
|
data: {
|
|
|
|
input: string[];
|
|
|
|
output: string;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-20 19:35:32 +00:00
|
|
|
describeForAllImplementations((bls) => {
|
2020-12-06 11:38:05 +00:00
|
|
|
describeDirectorySpecTest<IAggregateSigsTestCase, string | null>(
|
2020-11-19 14:41:45 +00:00
|
|
|
"bls/aggregate/small",
|
2020-12-01 08:17:25 +00:00
|
|
|
path.join(SPEC_TESTS_DIR, "tests/general/phase0/bls/aggregate/small"),
|
2020-11-19 13:22:41 +00:00
|
|
|
(testCase) => {
|
|
|
|
try {
|
|
|
|
const signatures = testCase.data.input;
|
|
|
|
const agg = bls.aggregateSignatures(signatures.map(hexToBytes));
|
|
|
|
return bytesToHex(agg);
|
|
|
|
} catch (e) {
|
2020-11-30 00:20:52 +00:00
|
|
|
if (e instanceof EmptyAggregateError) return null;
|
2020-11-19 13:22:41 +00:00
|
|
|
throw e;
|
2020-05-21 10:52:11 +00:00
|
|
|
}
|
2020-02-26 08:19:15 +00:00
|
|
|
},
|
2020-11-19 13:22:41 +00:00
|
|
|
{
|
|
|
|
inputTypes: {data: InputType.YAML},
|
|
|
|
getExpected: (testCase) => testCase.data.output,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|