improve bls spec tests

This commit is contained in:
Marin Petrunić 2019-09-04 13:35:34 +02:00
parent 359cc185e4
commit 98ec4bb402
8 changed files with 90 additions and 91 deletions

View File

@ -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"

View File

@ -1,15 +1,15 @@
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"),
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'))
sigs.push(Buffer.from(sig.replace('0x', ''), 'hex'));
});
return [
sigs

View File

@ -1,16 +1,15 @@
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"),
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'))
pubKeys.push(Buffer.from(pubKey.replace('0x', ''), 'hex'));
});
return [
pubKeys

View File

@ -4,7 +4,7 @@ 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"),
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);
@ -16,8 +16,8 @@ describeSpecTest(
({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')
return '0x' + Buffer.concat([xReExpected, xImExpected]).toString('hex');
},
(result:G2point) => `0x${result.toBytesCompressed().toString('hex')}`,
(result: G2point) => `0x${result.toBytesCompressed().toString('hex')}`,
() => false,
);

View File

@ -4,7 +4,7 @@ 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"),
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);
@ -23,6 +23,6 @@ describeSpecTest(
Buffer.from(output[2][1].replace('0x', ''), 'hex'),
).toBytesCompressed().toString('hex');
},
(result:G2point) => `0x${result.toBytesCompressed().toString('hex')}`,
(result: G2point) => `0x${result.toBytesCompressed().toString('hex')}`,
() => false,
);

View File

@ -3,7 +3,7 @@ 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"),
join(__dirname, "../../../spec-test-cases/tests/bls/priv_to_pub/priv_to_pub.yaml"),
bls.generatePublicKey,
({input}) => {
return [Buffer.from(input.replace('0x', ''), 'hex')];

View File

@ -4,7 +4,7 @@ import bls from "../../src";
import {padLeft} from "../../src/helpers/utils";
describeSpecTest(
join(__dirname, "./spec-tests/tests/bls/sign_msg/sign_msg.yaml"),
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);

@ -1 +0,0 @@
Subproject commit 7567342c966c4e020f6ab3889f93cedb65ea9bfe