bls uses spec tests cases from npm module
This commit is contained in:
parent
2725e3a518
commit
0a21bfb8cd
|
@ -27,7 +27,7 @@
|
||||||
"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 --colors -r ./.babel-register 'test/unit/**/*.test.ts' && nyc report",
|
"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": "mocha --colors -r ts-node/register 'test/spec/**/*.test.ts'",
|
||||||
"test:spec-min": "yarn run test:spec",
|
"test:spec-min": "yarn run test:spec",
|
||||||
"test": "yarn test:unit && yarn test:spec",
|
"test": "yarn test:unit && yarn test:spec",
|
||||||
|
|
|
@ -2,21 +2,24 @@ import bls from "../../src";
|
||||||
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
|
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
interface AggregatePubKeysTestCase {
|
interface IAggregatePubKeysTestCase {
|
||||||
data: {
|
data: {
|
||||||
input: string[];
|
input: string[];
|
||||||
output: string;
|
output: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
describeDirectorySpecTest<AggregatePubKeysTestCase, string>(
|
describeDirectorySpecTest<IAggregatePubKeysTestCase, string>(
|
||||||
"aggregate pubkeys",
|
"aggregate pubkeys",
|
||||||
path.join(__dirname, "../../../spec-test-cases/tests/general/phase0/bls/aggregate_pubkeys/small"),
|
path.join(
|
||||||
|
__dirname,
|
||||||
|
"../../../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/aggregate_pubkeys/small"
|
||||||
|
),
|
||||||
(testCase => {
|
(testCase => {
|
||||||
const result = bls.aggregatePubkeys(testCase.data.input.map(pubKey => {
|
const result = bls.aggregatePubkeys(testCase.data.input.map(pubKey => {
|
||||||
return Buffer.from(pubKey.replace("0x", ""), "hex");
|
return Buffer.from(pubKey.replace("0x", ""), "hex");
|
||||||
}));
|
}));
|
||||||
return `0x${result.toString('hex')}`;
|
return `0x${result.toString("hex")}`;
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
inputTypes: {
|
inputTypes: {
|
||||||
|
|
|
@ -11,12 +11,15 @@ interface AggregateSigsTestCase {
|
||||||
|
|
||||||
describeDirectorySpecTest<AggregateSigsTestCase, string>(
|
describeDirectorySpecTest<AggregateSigsTestCase, string>(
|
||||||
"aggregate sigs",
|
"aggregate sigs",
|
||||||
path.join(__dirname, "../../../spec-test-cases/tests/general/phase0/bls/aggregate_sigs/small"),
|
path.join(
|
||||||
|
__dirname,
|
||||||
|
"../../../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/aggregate_sigs/small"
|
||||||
|
),
|
||||||
(testCase => {
|
(testCase => {
|
||||||
const result = bls.aggregateSignatures(testCase.data.input.map(pubKey => {
|
const result = bls.aggregateSignatures(testCase.data.input.map(pubKey => {
|
||||||
return Buffer.from(pubKey.replace("0x", ""), "hex");
|
return Buffer.from(pubKey.replace("0x", ""), "hex");
|
||||||
}));
|
}));
|
||||||
return `0x${result.toString('hex')}`;
|
return `0x${result.toString("hex")}`;
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
inputTypes: {
|
inputTypes: {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import {padLeft} from "../../src/helpers/utils";
|
||||||
import {G2point} from "../../src/helpers/g2point";
|
import {G2point} from "../../src/helpers/g2point";
|
||||||
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
|
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
|
||||||
|
|
||||||
interface MsgHHashCOmpressed {
|
interface IMsgHHashCOmpressed {
|
||||||
data: {
|
data: {
|
||||||
input: {
|
input: {
|
||||||
message: string;
|
message: string;
|
||||||
|
@ -13,23 +13,26 @@ interface MsgHHashCOmpressed {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
describeDirectorySpecTest<MsgHHashCOmpressed, string>(
|
describeDirectorySpecTest<IMsgHHashCOmpressed, string>(
|
||||||
"msg_hash_compressed",
|
"msg_hash_compressed",
|
||||||
path.join(__dirname, "../../../spec-test-cases/tests/general/phase0/bls/msg_hash_compressed/small"),
|
path.join(
|
||||||
|
__dirname,
|
||||||
|
"../../../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/msg_hash_compressed/small"
|
||||||
|
),
|
||||||
(testCase => {
|
(testCase => {
|
||||||
const domain = padLeft(Buffer.from(testCase.data.input.domain.replace('0x', ''), 'hex'), 8);
|
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 input = Buffer.from(testCase.data.input.message.replace("0x", ""), "hex");
|
||||||
const result = G2point.hashToG2(input, domain);
|
const result = G2point.hashToG2(input, domain);
|
||||||
return `0x${result.toBytesCompressed().toString('hex')}`;
|
return `0x${result.toBytesCompressed().toString("hex")}`;
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
inputTypes: {
|
inputTypes: {
|
||||||
data: InputType.YAML,
|
data: InputType.YAML,
|
||||||
},
|
},
|
||||||
getExpected: (testCase => {
|
getExpected: (testCase => {
|
||||||
const xReExpected = padLeft(Buffer.from(testCase.data.output[0].replace('0x', ''), 'hex'), 48);
|
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);
|
const xImExpected = padLeft(Buffer.from(testCase.data.output[1].replace("0x", ""), "hex"), 48);
|
||||||
return '0x' + Buffer.concat([xReExpected, xImExpected]).toString('hex');
|
return "0x" + Buffer.concat([xReExpected, xImExpected]).toString("hex");
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
|
@ -3,7 +3,7 @@ import {padLeft} from "../../src/helpers/utils";
|
||||||
import {G2point} from "../../src/helpers/g2point";
|
import {G2point} from "../../src/helpers/g2point";
|
||||||
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
|
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
|
||||||
|
|
||||||
interface MsgHHashUnCompressed {
|
interface IMsgHHashUnCompressed {
|
||||||
data: {
|
data: {
|
||||||
input: {
|
input: {
|
||||||
message: string;
|
message: string;
|
||||||
|
@ -13,28 +13,31 @@ interface MsgHHashUnCompressed {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
describeDirectorySpecTest<MsgHHashUnCompressed, string>(
|
describeDirectorySpecTest<IMsgHHashUnCompressed, string>(
|
||||||
"msg_hash_uncompressed",
|
"msg_hash_uncompressed",
|
||||||
path.join(__dirname, "../../../spec-test-cases/tests/general/phase0/bls/msg_hash_uncompressed/small"),
|
path.join(
|
||||||
|
__dirname,
|
||||||
|
"../../../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/msg_hash_uncompressed/small"
|
||||||
|
),
|
||||||
(testCase => {
|
(testCase => {
|
||||||
const domain = padLeft(Buffer.from(testCase.data.input.domain.replace('0x', ''), 'hex'), 8);
|
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 input = Buffer.from(testCase.data.input.message.replace("0x", ""), "hex");
|
||||||
const result = G2point.hashToG2(input, domain);
|
const result = G2point.hashToG2(input, domain);
|
||||||
return `0x${result.toBytesCompressed().toString('hex')}`;
|
return `0x${result.toBytesCompressed().toString("hex")}`;
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
inputTypes: {
|
inputTypes: {
|
||||||
data: InputType.YAML,
|
data: InputType.YAML,
|
||||||
},
|
},
|
||||||
getExpected: (testCase => {
|
getExpected: (testCase => {
|
||||||
return '0x' + G2point.fromUncompressedInput(
|
return "0x" + G2point.fromUncompressedInput(
|
||||||
Buffer.from(testCase.data.output[0][0].replace('0x', ''), 'hex'),
|
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[0][1].replace("0x", ""), "hex"),
|
||||||
Buffer.from(testCase.data.output[1][0].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[1][1].replace("0x", ""), "hex"),
|
||||||
Buffer.from(testCase.data.output[2][0].replace('0x', ''), 'hex'),
|
Buffer.from(testCase.data.output[2][0].replace("0x", ""), "hex"),
|
||||||
Buffer.from(testCase.data.output[2][1].replace('0x', ''), 'hex'),
|
Buffer.from(testCase.data.output[2][1].replace("0x", ""), "hex"),
|
||||||
).toBytesCompressed().toString('hex');
|
).toBytesCompressed().toString("hex");
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
);
|
);
|
|
@ -2,19 +2,22 @@ import bls from "../../src";
|
||||||
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
|
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
interface PrivToPubTestCase {
|
interface IPrivToPubTestCase {
|
||||||
data: {
|
data: {
|
||||||
input: string;
|
input: string;
|
||||||
output: string;
|
output: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
describeDirectorySpecTest<PrivToPubTestCase, string>(
|
describeDirectorySpecTest<IPrivToPubTestCase, string>(
|
||||||
"priv_to_pub",
|
"priv_to_pub",
|
||||||
path.join(__dirname, "../../../spec-test-cases/tests/general/phase0/bls/priv_to_pub/small"),
|
path.join(
|
||||||
|
__dirname,
|
||||||
|
"../../../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/priv_to_pub/small"
|
||||||
|
),
|
||||||
(testCase => {
|
(testCase => {
|
||||||
const result = bls.generatePublicKey(Buffer.from(testCase.data.input.replace('0x', ''), 'hex'));
|
const result = bls.generatePublicKey(Buffer.from(testCase.data.input.replace("0x", ""), "hex"));
|
||||||
return `0x${result.toString('hex')}`;
|
return `0x${result.toString("hex")}`;
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
inputTypes: {
|
inputTypes: {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import bls from "../../src";
|
||||||
import {padLeft} from "../../src/helpers/utils";
|
import {padLeft} from "../../src/helpers/utils";
|
||||||
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
|
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
|
||||||
|
|
||||||
interface SignMessageTestCase {
|
interface ISignMessageTestCase {
|
||||||
data: {
|
data: {
|
||||||
input: {
|
input: {
|
||||||
privkey: string;
|
privkey: string;
|
||||||
|
@ -14,14 +14,17 @@ interface SignMessageTestCase {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
describeDirectorySpecTest<SignMessageTestCase, string>(
|
describeDirectorySpecTest<ISignMessageTestCase, string>(
|
||||||
"priv_to_pub",
|
"priv_to_pub",
|
||||||
path.join(__dirname, "../../../spec-test-cases/tests/general/phase0/bls/sign_msg/small"),
|
path.join(
|
||||||
|
__dirname,
|
||||||
|
"../../../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/sign_msg/small"
|
||||||
|
),
|
||||||
(testCase => {
|
(testCase => {
|
||||||
const signature = bls.sign(
|
const signature = bls.sign(
|
||||||
Buffer.from(testCase.data.input.privkey.replace("0x", ""), "hex"),
|
Buffer.from(testCase.data.input.privkey.replace("0x", ""), "hex"),
|
||||||
Buffer.from(testCase.data.input.message.replace("0x", ""), "hex"),
|
Buffer.from(testCase.data.input.message.replace("0x", ""), "hex"),
|
||||||
padLeft(Buffer.from(testCase.data.input.domain.replace('0x', ''), 'hex'), 8)
|
padLeft(Buffer.from(testCase.data.input.domain.replace("0x", ""), "hex"), 8)
|
||||||
);
|
);
|
||||||
return `0x${signature.toString("hex")}`;
|
return `0x${signature.toString("hex")}`;
|
||||||
}),
|
}),
|
||||||
|
|
Reference in New Issue