From e950c172f4e5b8878d3ec75f93f92cfb1079ef3b Mon Sep 17 00:00:00 2001 From: Cayman Date: Mon, 20 Jan 2020 16:10:21 -0600 Subject: [PATCH] Add test runner package --- package.json | 4 +-- test/spec/aggregate_pubkeys.test.ts | 34 ------------------- test/spec/aggregate_sigs.test.ts | 34 ------------------- test/spec/msg_hash_compressed.test.ts | 38 ---------------------- test/spec/msg_hash_uncompressed.test.ts | 43 ------------------------- test/spec/priv_to_public.test.ts | 32 ------------------ test/spec/sign_message.test.ts | 41 ----------------------- 7 files changed, 1 insertion(+), 225 deletions(-) delete mode 100644 test/spec/aggregate_pubkeys.test.ts delete mode 100644 test/spec/aggregate_sigs.test.ts delete mode 100644 test/spec/msg_hash_compressed.test.ts delete mode 100644 test/spec/msg_hash_uncompressed.test.ts delete mode 100644 test/spec/priv_to_public.test.ts delete mode 100644 test/spec/sign_message.test.ts diff --git a/package.json b/package.json index ecd33d6..08de1fc 100644 --- a/package.json +++ b/package.json @@ -31,9 +31,7 @@ "pretest": "yarn check-types", "prepublishOnly": "yarn build", "test:unit": "nyc --cache-dir .nyc_output/.cache -r lcov -e .ts mocha --colors -r ts-node/register 'test/unit/**/*.test.ts' && nyc report", - "test:spec": "mocha --colors -r ts-node/register 'test/spec/**/*.test.ts'", - "test:spec-min": "yarn run test:spec", - "test": "yarn test:unit && yarn test:spec", + "test": "yarn test:unit", "coverage": "codecov -F bls", "benchmark": "node -r ./.babel-register test/benchmarks" }, diff --git a/test/spec/aggregate_pubkeys.test.ts b/test/spec/aggregate_pubkeys.test.ts deleted file mode 100644 index 020402a..0000000 --- a/test/spec/aggregate_pubkeys.test.ts +++ /dev/null @@ -1,34 +0,0 @@ -import bls, {initBLS} from "../../src"; -import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single"; -import path from "path"; - -interface IAggregatePubKeysTestCase { - data: { - input: string[]; - output: string; - }; -} - -before(async function f() { - await initBLS(); -}); - -describeDirectorySpecTest( - "aggregate pubkeys", - path.join( - __dirname, - "../../../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/aggregate_pubkeys/small" - ), - (testCase => { - const result = bls.aggregatePubkeys(testCase.data.input.map(pubKey => { - return Buffer.from(pubKey.replace("0x", ""), "hex"); - })); - return `0x${result.toString("hex")}`; - }), - { - inputTypes: { - data: InputType.YAML, - }, - getExpected: (testCase => testCase.data.output) - } -); diff --git a/test/spec/aggregate_sigs.test.ts b/test/spec/aggregate_sigs.test.ts deleted file mode 100644 index e7b63ab..0000000 --- a/test/spec/aggregate_sigs.test.ts +++ /dev/null @@ -1,34 +0,0 @@ -import path from "path"; -import bls, {initBLS} from "../../src"; -import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single"; - -interface AggregateSigsTestCase { - data: { - input: string[]; - output: string; - }; -} - -before(async function f() { - await initBLS(); -}); - -describeDirectorySpecTest( - "aggregate sigs", - path.join( - __dirname, - "../../../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/aggregate_sigs/small" - ), - (testCase => { - const result = bls.aggregateSignatures(testCase.data.input.map(pubKey => { - return Buffer.from(pubKey.replace("0x", ""), "hex"); - })); - return `0x${result.toString("hex")}`; - }), - { - inputTypes: { - data: InputType.YAML, - }, - getExpected: (testCase => testCase.data.output) - } -); diff --git a/test/spec/msg_hash_compressed.test.ts b/test/spec/msg_hash_compressed.test.ts deleted file mode 100644 index 56a65dc..0000000 --- a/test/spec/msg_hash_compressed.test.ts +++ /dev/null @@ -1,38 +0,0 @@ -import path from "path"; -import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single"; -import {PrivateKey} from "../../src"; -import {padLeft} from "../../src/helpers/utils"; - -interface IMsgHHashCOmpressed { - data: { - input: { - message: string; - domain: string; - }; - output: string[]; - }; -} - -describeDirectorySpecTest( - "msg_hash_compressed", - path.join( - __dirname, - "../../../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/msg_hash_compressed/small" - ), - (testCase => { - const domain = Buffer.from(testCase.data.input.domain.replace("0x", ""), "hex"); - const input = Buffer.from(testCase.data.input.message.replace("0x", ""), "hex"); - const result = PrivateKey.fromInt(1).signMessage(input, domain).toBytesCompressed().toString("hex"); - return `0x${result}`; - }), - { - inputTypes: { - data: InputType.YAML, - }, - getExpected: (testCase => { - const xReExpected = padLeft(Buffer.from(testCase.data.output[0].replace("0x", ""), "hex"), 48); - const xImExpected = padLeft(Buffer.from(testCase.data.output[1].replace("0x", ""), "hex"), 48); - return "0x" + Buffer.concat([xReExpected, xImExpected]).toString("hex"); - }) - } -); \ No newline at end of file diff --git a/test/spec/msg_hash_uncompressed.test.ts b/test/spec/msg_hash_uncompressed.test.ts deleted file mode 100644 index 08de48f..0000000 --- a/test/spec/msg_hash_uncompressed.test.ts +++ /dev/null @@ -1,43 +0,0 @@ -// import path from "path"; -// import {padLeft} from "../../src/helpers/utils"; -// import {G2point} from "../../src/helpers/g2point"; -// import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single"; -// -// interface IMsgHHashUnCompressed { -// data: { -// input: { -// message: string; -// domain: string; -// }; -// output: string[][]; -// }; -// } -// -// describeDirectorySpecTest( -// "msg_hash_uncompressed", -// path.join( -// __dirname, -// "../../../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/msg_hash_uncompressed/small" -// ), -// (testCase => { -// const domain = padLeft(Buffer.from(testCase.data.input.domain.replace("0x", ""), "hex"), 8); -// const input = Buffer.from(testCase.data.input.message.replace("0x", ""), "hex"); -// const result = G2point.hashToG2(input, domain); -// return `0x${result.toBytesCompressed().toString("hex")}`; -// }), -// { -// inputTypes: { -// data: InputType.YAML, -// }, -// getExpected: (testCase => { -// return "0x" + G2point.fromUncompressedInput( -// Buffer.from(testCase.data.output[0][0].replace("0x", ""), "hex"), -// Buffer.from(testCase.data.output[0][1].replace("0x", ""), "hex"), -// Buffer.from(testCase.data.output[1][0].replace("0x", ""), "hex"), -// Buffer.from(testCase.data.output[1][1].replace("0x", ""), "hex"), -// Buffer.from(testCase.data.output[2][0].replace("0x", ""), "hex"), -// Buffer.from(testCase.data.output[2][1].replace("0x", ""), "hex"), -// ).toBytesCompressed().toString("hex"); -// }) -// } -// ); \ No newline at end of file diff --git a/test/spec/priv_to_public.test.ts b/test/spec/priv_to_public.test.ts deleted file mode 100644 index f21bc13..0000000 --- a/test/spec/priv_to_public.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import bls, {initBLS} from "../../src"; -import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single"; -import path from "path"; - -interface IPrivToPubTestCase { - data: { - input: string; - output: string; - }; -} - -before(async function f() { - await initBLS(); -}); - -describeDirectorySpecTest( - "priv_to_pub", - path.join( - __dirname, - "../../../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/priv_to_pub/small" - ), - (testCase => { - const result = bls.generatePublicKey(Buffer.from(testCase.data.input.replace("0x", ""), "hex")); - return `0x${result.toString("hex")}`; - }), - { - inputTypes: { - data: InputType.YAML, - }, - getExpected: (testCase => testCase.data.output) - } -); diff --git a/test/spec/sign_message.test.ts b/test/spec/sign_message.test.ts deleted file mode 100644 index b1a34a8..0000000 --- a/test/spec/sign_message.test.ts +++ /dev/null @@ -1,41 +0,0 @@ -import path from "path"; -import bls, {initBLS} from "../../src"; -import {padLeft} from "../../src/helpers/utils"; -import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single"; - -interface ISignMessageTestCase { - data: { - input: { - privkey: string; - message: string; - domain: string; - }; - output: string; - }; -} - -before(async function f() { - await initBLS(); -}); - -describeDirectorySpecTest( - "priv_to_pub", - path.join( - __dirname, - "../../../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/sign_msg/small" - ), - (testCase => { - const signature = bls.sign( - Buffer.from(testCase.data.input.privkey.replace("0x", ""), "hex"), - Buffer.from(testCase.data.input.message.replace("0x", ""), "hex"), - padLeft(Buffer.from(testCase.data.input.domain.replace("0x", ""), "hex"), 8) - ); - return `0x${signature.toString("hex")}`; - }), - { - inputTypes: { - data: InputType.YAML, - }, - getExpected: (testCase => testCase.data.output) - } -); \ No newline at end of file