improve bls spec tests
This commit is contained in:
parent
359cc185e4
commit
98ec4bb402
|
@ -27,8 +27,9 @@
|
||||||
"lint-fix": "eslint --ext .ts src/ --fix",
|
"lint-fix": "eslint --ext .ts src/ --fix",
|
||||||
"pretest": "yarn check-types",
|
"pretest": "yarn check-types",
|
||||||
"prepublishOnly": "yarn build",
|
"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: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 -r ./.babel-register 'test/spec/**/*.test.ts'",
|
"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",
|
"test": "yarn test:unit && yarn test:spec",
|
||||||
"coverage": "codecov -F bls",
|
"coverage": "codecov -F bls",
|
||||||
"benchmark": "node -r ./.babel-register test/benchmarks"
|
"benchmark": "node -r ./.babel-register test/benchmarks"
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
import {join} from "path";
|
import {join} from "path";
|
||||||
import {describeSpecTest} from "@chainsafe/eth2.0-spec-test-util";
|
import {describeSpecTest} from "@chainsafe/eth2.0-spec-test-util";
|
||||||
import bls from "../../src";
|
import bls from "../../src";
|
||||||
import {BLSSignature} from "../../src/types";
|
import {BLSSignature} from "@chainsafe/eth2.0-types";
|
||||||
|
|
||||||
describeSpecTest(
|
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,
|
bls.aggregatePubkeys,
|
||||||
({input}) => {
|
({input}) => {
|
||||||
const sigs: BLSSignature[] = [];
|
const sigs: BLSSignature[] = [];
|
||||||
input.forEach((sig: string) => {
|
input.forEach((sig: string) => {
|
||||||
sigs.push(Buffer.from(sig.replace('0x', ''), 'hex'))
|
sigs.push(Buffer.from(sig.replace('0x', ''), 'hex'));
|
||||||
});
|
});
|
||||||
return [
|
return [
|
||||||
sigs
|
sigs
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
({output}) => output,
|
({output}) => output,
|
||||||
(result) => `0x${result.toString('hex')}`,
|
(result) => `0x${result.toString('hex')}`,
|
||||||
() => false,
|
() => false,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,22 +1,21 @@
|
||||||
import {join} from "path";
|
import {join} from "path";
|
||||||
import {describeSpecTest} from "@chainsafe/eth2.0-spec-test-util";
|
import {describeSpecTest} from "@chainsafe/eth2.0-spec-test-util";
|
||||||
import bls from "../../src";
|
import bls from "../../src";
|
||||||
import {G2point} from "../../src/helpers/g2point";
|
|
||||||
import {BLSPubkey} from "../../src/types";
|
import {BLSPubkey} from "../../src/types";
|
||||||
|
|
||||||
describeSpecTest(
|
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,
|
bls.aggregateSignatures,
|
||||||
({input}) => {
|
({input}) => {
|
||||||
const pubKeys: BLSPubkey[] = [];
|
const pubKeys: BLSPubkey[] = [];
|
||||||
input.forEach((pubKey: string) => {
|
input.forEach((pubKey: string) => {
|
||||||
pubKeys.push(Buffer.from(pubKey.replace('0x', ''), 'hex'))
|
pubKeys.push(Buffer.from(pubKey.replace('0x', ''), 'hex'));
|
||||||
});
|
});
|
||||||
return [
|
return [
|
||||||
pubKeys
|
pubKeys
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
({output}) => output,
|
({output}) => output,
|
||||||
(result) => `0x${result.toString('hex')}`,
|
(result) => `0x${result.toString('hex')}`,
|
||||||
() => false,
|
() => false,
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,20 +4,20 @@ import {padLeft} from "../../src/helpers/utils";
|
||||||
import {G2point} from "../../src/helpers/g2point";
|
import {G2point} from "../../src/helpers/g2point";
|
||||||
|
|
||||||
describeSpecTest(
|
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,
|
G2point.hashToG2,
|
||||||
({input}) => {
|
({input}) => {
|
||||||
const domain = padLeft(Buffer.from(input.domain.replace('0x', ''), 'hex'), 8);
|
const domain = padLeft(Buffer.from(input.domain.replace('0x', ''), 'hex'), 8);
|
||||||
return [
|
return [
|
||||||
Buffer.from(input.message.replace('0x', ''), 'hex'),
|
Buffer.from(input.message.replace('0x', ''), 'hex'),
|
||||||
domain
|
domain
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
({output}) => {
|
({output}) => {
|
||||||
const xReExpected = padLeft(Buffer.from(output[0].replace('0x', ''), 'hex'), 48);
|
const xReExpected = padLeft(Buffer.from(output[0].replace('0x', ''), 'hex'), 48);
|
||||||
const xImExpected = padLeft(Buffer.from(output[1].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,
|
() => false,
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,25 +4,25 @@ import {padLeft} from "../../src/helpers/utils";
|
||||||
import {G2point} from "../../src/helpers/g2point";
|
import {G2point} from "../../src/helpers/g2point";
|
||||||
|
|
||||||
describeSpecTest(
|
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,
|
G2point.hashToG2,
|
||||||
({input}) => {
|
({input}) => {
|
||||||
const domain = padLeft(Buffer.from(input.domain.replace('0x', ''), 'hex'), 8);
|
const domain = padLeft(Buffer.from(input.domain.replace('0x', ''), 'hex'), 8);
|
||||||
return [
|
return [
|
||||||
Buffer.from(input.message.replace('0x', ''), 'hex'),
|
Buffer.from(input.message.replace('0x', ''), 'hex'),
|
||||||
domain
|
domain
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
({output}) => {
|
({output}) => {
|
||||||
return '0x' + G2point.fromUncompressedInput(
|
return '0x' + G2point.fromUncompressedInput(
|
||||||
Buffer.from(output[0][0].replace('0x', ''), 'hex'),
|
Buffer.from(output[0][0].replace('0x', ''), 'hex'),
|
||||||
Buffer.from(output[0][1].replace('0x', ''), 'hex'),
|
Buffer.from(output[0][1].replace('0x', ''), 'hex'),
|
||||||
Buffer.from(output[1][0].replace('0x', ''), 'hex'),
|
Buffer.from(output[1][0].replace('0x', ''), 'hex'),
|
||||||
Buffer.from(output[1][1].replace('0x', ''), 'hex'),
|
Buffer.from(output[1][1].replace('0x', ''), 'hex'),
|
||||||
Buffer.from(output[2][0].replace('0x', ''), 'hex'),
|
Buffer.from(output[2][0].replace('0x', ''), 'hex'),
|
||||||
Buffer.from(output[2][1].replace('0x', ''), 'hex'),
|
Buffer.from(output[2][1].replace('0x', ''), 'hex'),
|
||||||
).toBytesCompressed().toString('hex');
|
).toBytesCompressed().toString('hex');
|
||||||
},
|
},
|
||||||
(result:G2point) => `0x${result.toBytesCompressed().toString('hex')}`,
|
(result: G2point) => `0x${result.toBytesCompressed().toString('hex')}`,
|
||||||
() => false,
|
() => false,
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,12 +3,12 @@ import {describeSpecTest} from "@chainsafe/eth2.0-spec-test-util";
|
||||||
import bls from "../../src";
|
import bls from "../../src";
|
||||||
|
|
||||||
describeSpecTest(
|
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,
|
bls.generatePublicKey,
|
||||||
({input}) => {
|
({input}) => {
|
||||||
return [Buffer.from(input.replace('0x', ''), 'hex')];
|
return [Buffer.from(input.replace('0x', ''), 'hex')];
|
||||||
},
|
},
|
||||||
({output}) => output,
|
({output}) => output,
|
||||||
(result) => `0x${result.toString('hex')}`,
|
(result) => `0x${result.toString('hex')}`,
|
||||||
() => false,
|
() => false,
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,17 +4,17 @@ import bls from "../../src";
|
||||||
import {padLeft} from "../../src/helpers/utils";
|
import {padLeft} from "../../src/helpers/utils";
|
||||||
|
|
||||||
describeSpecTest(
|
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,
|
bls.sign,
|
||||||
({input}) => {
|
({input}) => {
|
||||||
const domain = padLeft(Buffer.from(input.domain.replace('0x', ''), 'hex'), 8);
|
const domain = padLeft(Buffer.from(input.domain.replace('0x', ''), 'hex'), 8);
|
||||||
return [
|
return [
|
||||||
Buffer.from(input.privkey.replace('0x', ''), 'hex'),
|
Buffer.from(input.privkey.replace('0x', ''), 'hex'),
|
||||||
Buffer.from(input.message.replace('0x', ''), 'hex'),
|
Buffer.from(input.message.replace('0x', ''), 'hex'),
|
||||||
domain
|
domain
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
({output}) => output,
|
({output}) => output,
|
||||||
(result) => `0x${result.toString('hex')}`,
|
(result) => `0x${result.toString('hex')}`,
|
||||||
() => false,
|
() => false,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit 7567342c966c4e020f6ab3889f93cedb65ea9bfe
|
|
Reference in New Issue