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_sigs.test.ts

41 lines
1013 B
TypeScript
Raw Normal View History

2020-02-26 08:19:15 +00:00
import path from "path";
2020-11-05 20:55:25 +00:00
import bls, {initBLS} from "../../src";
import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util";
2020-02-26 08:19:15 +00:00
interface IAggregateSigsTestCase {
data: {
input: string[];
output: string;
};
}
before(async function f() {
await initBLS();
});
describeDirectorySpecTest<IAggregateSigsTestCase, string>(
"BLS - aggregate sigs",
2020-11-05 20:55:25 +00:00
path.join(__dirname, "../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/aggregate/small"),
2020-11-04 17:40:36 +00:00
(testCase) => {
2020-05-21 10:52:11 +00:00
try {
2020-11-04 17:40:36 +00:00
const result = bls.aggregateSignatures(
testCase.data.input.map((pubKey) => {
return Buffer.from(pubKey.replace("0x", ""), "hex");
})
);
2020-05-21 10:52:11 +00:00
return `0x${result.toString("hex")}`;
} catch (e) {
2020-11-04 17:40:36 +00:00
if (e.message === "signatures is null or undefined or empty array") {
2020-05-21 10:52:11 +00:00
return null;
}
throw e;
}
2020-11-04 17:40:36 +00:00
},
2020-02-26 08:19:15 +00:00
{
inputTypes: {
data: InputType.YAML,
},
2020-11-04 17:40:36 +00:00
getExpected: (testCase) => testCase.data.output,
2020-02-26 08:19:15 +00:00
}
);