Add test runner package
This commit is contained in:
parent
042e2f3098
commit
e950c172f4
|
@ -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"
|
||||
},
|
||||
|
|
|
@ -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<IAggregatePubKeysTestCase, string>(
|
||||
"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)
|
||||
}
|
||||
);
|
|
@ -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<AggregateSigsTestCase, string>(
|
||||
"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)
|
||||
}
|
||||
);
|
|
@ -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<IMsgHHashCOmpressed, string>(
|
||||
"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");
|
||||
})
|
||||
}
|
||||
);
|
|
@ -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<IMsgHHashUnCompressed, string>(
|
||||
// "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");
|
||||
// })
|
||||
// }
|
||||
// );
|
|
@ -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<IPrivToPubTestCase, string>(
|
||||
"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)
|
||||
}
|
||||
);
|
|
@ -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<ISignMessageTestCase, string>(
|
||||
"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)
|
||||
}
|
||||
);
|
Reference in New Issue