From 20121c330b9bef0c2ffb692623a0f7cd6b84dfe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marin=20Petruni=C4=87?= Date: Thu, 21 May 2020 12:52:11 +0200 Subject: [PATCH] update tests --- src/index.ts | 2 +- test/spec/aggregate_sigs.test.ts | 15 +++++++++++---- test/spec/aggregate_sigs_verify.test.ts | 14 ++++++-------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/index.ts b/src/index.ts index 9ce9534..0e5f485 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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); diff --git a/test/spec/aggregate_sigs.test.ts b/test/spec/aggregate_sigs.test.ts index 3d9191e..139522f 100644 --- a/test/spec/aggregate_sigs.test.ts +++ b/test/spec/aggregate_sigs.test.ts @@ -20,10 +20,17 @@ describeDirectorySpecTest( "../../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: { diff --git a/test/spec/aggregate_sigs_verify.test.ts b/test/spec/aggregate_sigs_verify.test.ts index c6d2dd8..4f8c122 100644 --- a/test/spec/aggregate_sigs_verify.test.ts +++ b/test/spec/aggregate_sigs_verify.test.ts @@ -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( "../../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,