diff --git a/package.json b/package.json index 3488a5f..80cc4b9 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,9 @@ "lint-fix": "eslint --ext .ts src/ --fix", "pretest": "yarn check-types", "prepublishOnly": "yarn build", - "test:unit": "nyc --cache-dir .nyc_output/.cache -r lcov -e .ts mocha -r ./.babel-register 'test/unit/**/*.test.ts' && nyc report", - "test:spec": "mocha -r ./.babel-register 'test/spec/**/*.test.ts'", + "test:unit": "nyc --cache-dir .nyc_output/.cache -r lcov -e .ts mocha --colors -r ./.babel-register 'test/unit/**/*.test.ts' && nyc report", + "test:spec": "mocha --colors -r ./.babel-register 'test/spec/**/*.test.ts'", + "test:spec-min": "yarn run test:spec", "test": "yarn test:unit && yarn test:spec", "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 index 775cb60..09a911f 100644 --- a/test/spec/aggregate_pubkeys.test.ts +++ b/test/spec/aggregate_pubkeys.test.ts @@ -1,21 +1,21 @@ import {join} from "path"; import {describeSpecTest} from "@chainsafe/eth2.0-spec-test-util"; import bls from "../../src"; -import {BLSSignature} from "../../src/types"; +import {BLSSignature} from "@chainsafe/eth2.0-types"; describeSpecTest( - join(__dirname, "./spec-tests/tests/bls/aggregate_pubkeys/aggregate_pubkeys.yaml"), - bls.aggregatePubkeys, - ({input}) => { - const sigs: BLSSignature[] = []; - input.forEach((sig: string) => { - sigs.push(Buffer.from(sig.replace('0x', ''), 'hex')) - }); - return [ - sigs - ]; - }, - ({output}) => output, - (result) => `0x${result.toString('hex')}`, - () => false, + join(__dirname, "../../../spec-test-cases/tests/bls/aggregate_pubkeys/aggregate_pubkeys.yaml"), + bls.aggregatePubkeys, + ({input}) => { + const sigs: BLSSignature[] = []; + input.forEach((sig: string) => { + sigs.push(Buffer.from(sig.replace('0x', ''), 'hex')); + }); + return [ + sigs + ]; + }, + ({output}) => output, + (result) => `0x${result.toString('hex')}`, + () => false, ); diff --git a/test/spec/aggregate_sigs.test.ts b/test/spec/aggregate_sigs.test.ts index 7abc949..4a494a2 100644 --- a/test/spec/aggregate_sigs.test.ts +++ b/test/spec/aggregate_sigs.test.ts @@ -1,22 +1,21 @@ import {join} from "path"; import {describeSpecTest} from "@chainsafe/eth2.0-spec-test-util"; import bls from "../../src"; -import {G2point} from "../../src/helpers/g2point"; import {BLSPubkey} from "../../src/types"; describeSpecTest( - join(__dirname, "./spec-tests/tests/bls/aggregate_sigs/aggregate_sigs.yaml"), - bls.aggregateSignatures, - ({input}) => { - const pubKeys: BLSPubkey[] = []; - input.forEach((pubKey: string) => { - pubKeys.push(Buffer.from(pubKey.replace('0x', ''), 'hex')) - }); - return [ - pubKeys - ]; - }, - ({output}) => output, - (result) => `0x${result.toString('hex')}`, - () => false, + join(__dirname, "../../../spec-test-cases/tests/bls/aggregate_sigs/aggregate_sigs.yaml"), + bls.aggregateSignatures, + ({input}) => { + const pubKeys: BLSPubkey[] = []; + input.forEach((pubKey: string) => { + pubKeys.push(Buffer.from(pubKey.replace('0x', ''), 'hex')); + }); + return [ + pubKeys + ]; + }, + ({output}) => output, + (result) => `0x${result.toString('hex')}`, + () => false, ); diff --git a/test/spec/g2_compressed.test.ts b/test/spec/g2_compressed.test.ts index 025d9ae..e0cf37f 100644 --- a/test/spec/g2_compressed.test.ts +++ b/test/spec/g2_compressed.test.ts @@ -4,20 +4,20 @@ import {padLeft} from "../../src/helpers/utils"; import {G2point} from "../../src/helpers/g2point"; describeSpecTest( - join(__dirname, "./spec-tests/tests/bls/msg_hash_g2_compressed/g2_compressed.yaml"), - G2point.hashToG2, - ({input}) => { - const domain = padLeft(Buffer.from(input.domain.replace('0x', ''), 'hex'), 8); - return [ - Buffer.from(input.message.replace('0x', ''), 'hex'), - domain - ]; - }, - ({output}) => { - const xReExpected = padLeft(Buffer.from(output[0].replace('0x', ''), 'hex'), 48); - const xImExpected = padLeft(Buffer.from(output[1].replace('0x', ''), 'hex'), 48); - return '0x' + Buffer.concat([xReExpected, xImExpected]).toString('hex') - }, - (result:G2point) => `0x${result.toBytesCompressed().toString('hex')}`, - () => false, + join(__dirname, "../../../spec-test-cases/tests/bls/msg_hash_g2_compressed/g2_compressed.yaml"), + G2point.hashToG2, + ({input}) => { + const domain = padLeft(Buffer.from(input.domain.replace('0x', ''), 'hex'), 8); + return [ + Buffer.from(input.message.replace('0x', ''), 'hex'), + domain + ]; + }, + ({output}) => { + const xReExpected = padLeft(Buffer.from(output[0].replace('0x', ''), 'hex'), 48); + const xImExpected = padLeft(Buffer.from(output[1].replace('0x', ''), 'hex'), 48); + return '0x' + Buffer.concat([xReExpected, xImExpected]).toString('hex'); + }, + (result: G2point) => `0x${result.toBytesCompressed().toString('hex')}`, + () => false, ); diff --git a/test/spec/g2_uncompressed.test.ts b/test/spec/g2_uncompressed.test.ts index 12896f9..ec9550b 100644 --- a/test/spec/g2_uncompressed.test.ts +++ b/test/spec/g2_uncompressed.test.ts @@ -4,25 +4,25 @@ import {padLeft} from "../../src/helpers/utils"; import {G2point} from "../../src/helpers/g2point"; describeSpecTest( - join(__dirname, "./spec-tests/tests/bls/msg_hash_g2_uncompressed/g2_uncompressed.yaml"), - G2point.hashToG2, - ({input}) => { - const domain = padLeft(Buffer.from(input.domain.replace('0x', ''), 'hex'), 8); - return [ - Buffer.from(input.message.replace('0x', ''), 'hex'), - domain - ]; - }, - ({output}) => { - return '0x' + G2point.fromUncompressedInput( - Buffer.from(output[0][0].replace('0x', ''), 'hex'), - Buffer.from(output[0][1].replace('0x', ''), 'hex'), - Buffer.from(output[1][0].replace('0x', ''), 'hex'), - Buffer.from(output[1][1].replace('0x', ''), 'hex'), - Buffer.from(output[2][0].replace('0x', ''), 'hex'), - Buffer.from(output[2][1].replace('0x', ''), 'hex'), - ).toBytesCompressed().toString('hex'); - }, - (result:G2point) => `0x${result.toBytesCompressed().toString('hex')}`, - () => false, + join(__dirname, "../../../spec-test-cases/tests/bls/msg_hash_g2_uncompressed/g2_uncompressed.yaml"), + G2point.hashToG2, + ({input}) => { + const domain = padLeft(Buffer.from(input.domain.replace('0x', ''), 'hex'), 8); + return [ + Buffer.from(input.message.replace('0x', ''), 'hex'), + domain + ]; + }, + ({output}) => { + return '0x' + G2point.fromUncompressedInput( + Buffer.from(output[0][0].replace('0x', ''), 'hex'), + Buffer.from(output[0][1].replace('0x', ''), 'hex'), + Buffer.from(output[1][0].replace('0x', ''), 'hex'), + Buffer.from(output[1][1].replace('0x', ''), 'hex'), + Buffer.from(output[2][0].replace('0x', ''), 'hex'), + Buffer.from(output[2][1].replace('0x', ''), 'hex'), + ).toBytesCompressed().toString('hex'); + }, + (result: G2point) => `0x${result.toBytesCompressed().toString('hex')}`, + () => false, ); diff --git a/test/spec/priv_to_public.test.ts b/test/spec/priv_to_public.test.ts index d193d0a..75b08f8 100644 --- a/test/spec/priv_to_public.test.ts +++ b/test/spec/priv_to_public.test.ts @@ -3,12 +3,12 @@ import {describeSpecTest} from "@chainsafe/eth2.0-spec-test-util"; import bls from "../../src"; describeSpecTest( - join(__dirname, "./spec-tests/tests/bls/priv_to_pub/priv_to_pub.yaml"), - bls.generatePublicKey, - ({input}) => { - return [Buffer.from(input.replace('0x', ''), 'hex')]; - }, - ({output}) => output, - (result) => `0x${result.toString('hex')}`, - () => false, + join(__dirname, "../../../spec-test-cases/tests/bls/priv_to_pub/priv_to_pub.yaml"), + bls.generatePublicKey, + ({input}) => { + return [Buffer.from(input.replace('0x', ''), 'hex')]; + }, + ({output}) => output, + (result) => `0x${result.toString('hex')}`, + () => false, ); diff --git a/test/spec/sign_message.test.ts b/test/spec/sign_message.test.ts index 446a6c4..1117838 100644 --- a/test/spec/sign_message.test.ts +++ b/test/spec/sign_message.test.ts @@ -4,17 +4,17 @@ import bls from "../../src"; import {padLeft} from "../../src/helpers/utils"; describeSpecTest( - join(__dirname, "./spec-tests/tests/bls/sign_msg/sign_msg.yaml"), - bls.sign, - ({input}) => { - const domain = padLeft(Buffer.from(input.domain.replace('0x', ''), 'hex'), 8); - return [ - Buffer.from(input.privkey.replace('0x', ''), 'hex'), - Buffer.from(input.message.replace('0x', ''), 'hex'), - domain - ]; - }, - ({output}) => output, - (result) => `0x${result.toString('hex')}`, - () => false, + join(__dirname, "../../../spec-test-cases/tests/bls/sign_msg/sign_msg.yaml"), + bls.sign, + ({input}) => { + const domain = padLeft(Buffer.from(input.domain.replace('0x', ''), 'hex'), 8); + return [ + Buffer.from(input.privkey.replace('0x', ''), 'hex'), + Buffer.from(input.message.replace('0x', ''), 'hex'), + domain + ]; + }, + ({output}) => output, + (result) => `0x${result.toString('hex')}`, + () => false, ); diff --git a/test/spec/spec-tests b/test/spec/spec-tests deleted file mode 160000 index 7567342..0000000 --- a/test/spec/spec-tests +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7567342c966c4e020f6ab3889f93cedb65ea9bfe