update tests

This commit is contained in:
Marin Petrunić 2020-05-21 12:52:11 +02:00
parent 114a344fb6
commit 20121c330b
No known key found for this signature in database
GPG Key ID: 834D07135E110DA5
3 changed files with 18 additions and 13 deletions

View File

@ -47,7 +47,7 @@ export function sign(secretKey: Uint8Array, messageHash: Uint8Array): Buffer {
* @param signatures
*/
export function aggregateSignatures(signatures: Uint8Array[]): Buffer {
assert(signatures, "signatures is null or undefined");
assert(signatures && signatures.length > 0, "signatures is null or undefined or empty array");
return Signature.aggregate(
signatures.map((signature): Signature => {
return Signature.fromCompressedBytes(signature);

View File

@ -20,10 +20,17 @@ describeDirectorySpecTest<IAggregateSigsTestCase, string>(
"../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/aggregate/small"
),
(testCase => {
const result = bls.aggregateSignatures(testCase.data.input.map(pubKey => {
return Buffer.from(pubKey.replace("0x", ""), "hex");
}));
return `0x${result.toString("hex")}`;
try {
const result = bls.aggregateSignatures(testCase.data.input.map(pubKey => {
return Buffer.from(pubKey.replace("0x", ""), "hex");
}));
return `0x${result.toString("hex")}`;
} catch (e) {
if(e.message === "signatures is null or undefined or empty array") {
return null;
}
throw e;
}
}),
{
inputTypes: {

View File

@ -5,10 +5,8 @@ import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-tes
interface AggregateSigsVerifyTestCase {
data: {
input: {
pairs: [{
pubkey: string;
message: string;
}];
pubkeys: string[];
messages: string[];
signature: string;
};
output: boolean;
@ -30,11 +28,11 @@ describeDirectorySpecTest<AggregateSigsVerifyTestCase, boolean>(
"../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/aggregate_verify/small"
),
(testCase => {
const pubkeys = testCase.data.input.pairs.map(pair => {
return Buffer.from(pair.pubkey.replace("0x", ""), "hex");
const pubkeys = testCase.data.input.pubkeys.map(pubkey => {
return Buffer.from(pubkey.replace("0x", ""), "hex");
});
const messages = testCase.data.input.pairs.map(pair => {
return Buffer.from(pair.message.replace("0x", ""), "hex");
const messages = testCase.data.input.messages.map(msg => {
return Buffer.from(msg.replace("0x", ""), "hex");
});
return bls.verifyMultiple(
pubkeys,